diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-08-18 09:26:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-18 09:26:30 +0200 |
commit | b2bc0f3c44192af4a20a18917c4d8cef7835723b (patch) | |
tree | 2beaef33786a6c0a52b7e0ef8fa2f67e62e088a5 /src | |
parent | 962aa7e78aeececb91ef327de5b78d56c5633b62 (diff) | |
download | skyhanni-b2bc0f3c44192af4a20a18917c4d8cef7835723b.tar.gz skyhanni-b2bc0f3c44192af4a20a18917c4d8cef7835723b.tar.bz2 skyhanni-b2bc0f3c44192af4a20a18917c4d8cef7835723b.zip |
Fix: Bazaar + Item Trackers (#2366)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
4 files changed, 47 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt index 6a855a06b..947fa3bf1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt @@ -127,7 +127,7 @@ object OwnInventoryData { } } - private fun ignoreItem(duration: Duration, condition: (NEUInternalName) -> Boolean) { + fun ignoreItem(duration: Duration, condition: (NEUInternalName) -> Boolean) { ignoredItemsUntil.add(IgnoredItem(condition, SimpleTimeMark.now() + duration)) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt index 99e38fd77..afd5900f7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarApi.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.inventory.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.data.OwnInventoryData import at.hannibal2.skyhanni.data.bazaar.HypixelBazaarFetcher import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent import at.hannibal2.skyhanni.events.GuiContainerEvent @@ -13,8 +14,10 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.HypixelCommands +import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.InventoryUtils.getAllItems import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor @@ -32,6 +35,7 @@ import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds @SkyHanniModule object BazaarApi { @@ -43,13 +47,14 @@ object BazaarApi { private var currentSearchedItem = "" var currentlyOpenedProduct: NEUInternalName? = null + var orderOptionProduct: NEUInternalName? = null fun NEUInternalName.getBazaarData(): BazaarData? = HypixelBazaarFetcher.latestProductInformation[this] fun NEUInternalName.getBazaarDataOrError(): BazaarData = getBazaarData() ?: run { ErrorManager.skyHanniError( "Can not find bazaar data for $itemName", - "internal name" to this + "internal name" to this, ) } @@ -81,6 +86,25 @@ object BazaarApi { } } + @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + val item = event.item ?: return + val itemName = item.name + if (isBazaarOrderInventory(InventoryUtils.openInventoryName())) { + val internalName = item.getInternalNameOrNull() ?: return + if (itemName.contains("SELL")) { + orderOptionProduct = internalName + } else if (itemName.contains("BUY")) { + // pickup items from bazaar order + OwnInventoryData.ignoreItem(1.seconds, { it == internalName }) + } + } + if (InventoryUtils.openInventoryName() == "Order options" && itemName == "§cCancel Order") { + // pickup items from own bazaar order + OwnInventoryData.ignoreItem(1.seconds, { it == orderOptionProduct }) + } + } + private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): NEUInternalName? { val buyInstantly = inventoryItems[10] ?: return null @@ -161,4 +185,10 @@ object BazaarApi { inBazaarInventory = false currentlyOpenedProduct = null } + + fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) { + "Your Bazaar Orders" -> true + "Co-op Bazaar Orders" -> true + else -> false + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt index bd420de23..a177d3fe6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -34,15 +34,15 @@ object BazaarCancelledBuyOrderClipboard { */ private val lastAmountPattern by patternGroup.pattern( "lastamount", - "(?:§6coins §7from |§6§7from |§7)§a(?<amount>.*)§7x §7missing items\\." + "(?:§6coins §7from |§6§7from |§7)§a(?<amount>.*)§7x §7missing items\\.", ) private val cancelledMessagePattern by patternGroup.pattern( "cancelledmessage", - "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!" + "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!", ) private val inventoryTitlePattern by patternGroup.pattern( "inventorytitle", - "Order options" + "Order options", ) /** @@ -50,7 +50,7 @@ object BazaarCancelledBuyOrderClipboard { */ private val lastItemClickedPattern by patternGroup.pattern( "lastitemclicked", - "§a§lBUY (?<name>.*)" + "§a§lBUY (?<name>.*)", ) private var latestAmount: Int? = null @@ -83,7 +83,7 @@ object BazaarCancelledBuyOrderClipboard { @SubscribeEvent fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - if (!BazaarOrderHelper.isBazaarOrderInventory(InventoryUtils.openInventoryName())) return + if (!BazaarApi.isBazaarOrderInventory(InventoryUtils.openInventoryName())) return val item = event.slot?.stack ?: return val name = lastItemClickedPattern.matchMatcher(item.name) { @@ -105,9 +105,12 @@ object BazaarCancelledBuyOrderClipboard { val message = "Bazaar buy order cancelled. Click to reorder. " + "(§8${latestAmount.addSeparators()}x §r${lastClicked.itemName}§e)" - ChatUtils.clickableChat(message, onClick = { - BazaarApi.searchForBazaarItem(lastClicked, latestAmount) - }) + ChatUtils.clickableChat( + message, + onClick = { + BazaarApi.searchForBazaarItem(lastClicked, latestAmount) + }, + ) OSUtils.copyToClipboard(latestAmount.toString()) this.latestAmount = null } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt index 771de0001..ba643f7ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarOrderHelper.kt @@ -25,23 +25,17 @@ object BazaarOrderHelper { private val patternGroup = RepoPattern.group("bazaar.orderhelper") private val bazaarItemNamePattern by patternGroup.pattern( "itemname", - "§.§l(?<type>BUY|SELL) (?<name>.*)" + "§.§l(?<type>BUY|SELL) (?<name>.*)", ) private val filledPattern by patternGroup.pattern( "filled", - "§7Filled: §[a6].*§7/.* §a§l100%!" + "§7Filled: §[a6].*§7/.* §a§l100%!", ) private val pricePattern by patternGroup.pattern( "price", - "§7Price per unit: §6(?<number>.*) coins" + "§7Price per unit: §6(?<number>.*) coins", ) - fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) { - "Your Bazaar Orders" -> true - "Co-op Bazaar Orders" -> true - else -> false - } - @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { if (!LorenzUtils.inSkyBlock) return @@ -51,7 +45,7 @@ object BazaarOrderHelper { val guiChest = event.gui val chest = guiChest.inventorySlots as ContainerChest val inventoryName = chest.getInventoryName() - if (!isBazaarOrderInventory(inventoryName)) return + if (!BazaarApi.isBazaarOrderInventory(inventoryName)) return for ((slot, stack) in chest.getUpperItems()) { bazaarItemNamePattern.matchMatcher(stack.name) { |