From acd1945179bc86f98ef8dae9ddf2cc55043608ea Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:09:15 +0200 Subject: [PATCH] Fix bazaar item movement counting in item trackers --- .../skyhanni/data/OwnInventoryData.kt | 2 +- .../features/inventory/bazaar/BazaarApi.kt | 32 ++++++++++++++++++- .../BazaarCancelledBuyOrderClipboard.kt | 19 ++++++----- .../inventory/bazaar/BazaarOrderHelper.kt | 14 +++----- 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 6a855a06bcf6..947fa3bf1bc0 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 99e38fd776fb..afd5900f7c34 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): 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 bd420de23db0..a177d3fe6287 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(?.*)§7x §7missing items\\." + "(?:§6coins §7from |§6§7from |§7)§a(?.*)§7x §7missing items\\.", ) private val cancelledMessagePattern by patternGroup.pattern( "cancelledmessage", - "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?.*) coins §r§7from cancelling Buy Order!" + "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?.*) 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 (?.*)" + "§a§lBUY (?.*)", ) 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 771de0001a31..ba643f7acf4d 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(?BUY|SELL) (?.*)" + "§.§l(?BUY|SELL) (?.*)", ) 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(?.*) coins" + "§7Price per unit: §6(?.*) 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) {