aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/bazaar
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-03-01 17:14:54 +0100
committerGitHub <noreply@github.com>2024-03-01 17:14:54 +0100
commit93af7607b3d5c1061bc845f097fe8be94c5e2043 (patch)
tree71a66fa6404cadd8b5f337fe1ac99f4b2b3e9485 /src/main/java/at/hannibal2/skyhanni/features/bazaar
parentc56b58e00d913e73a44106882bde8686ecdab341 (diff)
downloadskyhanni-93af7607b3d5c1061bc845f097fe8be94c5e2043.tar.gz
skyhanni-93af7607b3d5c1061bc845f097fe8be94c5e2043.tar.bz2
skyhanni-93af7607b3d5c1061bc845f097fe8be94c5e2043.zip
Internal Change: Bazaar Config -> Inventory Config (#1082)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt150
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt80
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt60
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt78
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt66
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt92
7 files changed, 0 insertions, 533 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
deleted file mode 100644
index 3ec2630a0..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
+++ /dev/null
@@ -1,150 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent
-import at.hannibal2.skyhanni.events.GuiContainerEvent
-import at.hannibal2.skyhanni.events.InventoryCloseEvent
-import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
-import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.events.LorenzTickEvent
-import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
-import at.hannibal2.skyhanni.utils.ItemUtils.getLore
-import at.hannibal2.skyhanni.utils.ItemUtils.name
-import at.hannibal2.skyhanni.utils.LorenzColor
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.NEUInternalName
-import at.hannibal2.skyhanni.utils.NEUItems
-import at.hannibal2.skyhanni.utils.OSUtils
-import at.hannibal2.skyhanni.utils.RenderUtils.highlight
-import at.hannibal2.skyhanni.utils.StringUtils.equalsIgnoreColor
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
-import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
-import net.minecraft.item.ItemStack
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class BazaarApi {
-
- private var loadedNpcPriceData = false
-
- companion object {
-
- val holder = BazaarDataHolder()
- var inBazaarInventory = false
- private var currentSearchedItem = ""
-
- var currentlyOpenedProduct: NEUInternalName? = null
-
- fun getBazaarDataByName(name: String): BazaarData? = NEUItems.getInternalNameOrNull(name)?.getBazaarData()
-
- fun NEUInternalName.getBazaarData() = if (isBazaarItem()) {
- holder.getData(this)
- } else null
-
- fun isBazaarItem(stack: ItemStack): Boolean = stack.getInternalName().isBazaarItem()
-
- fun NEUInternalName.isBazaarItem() = NEUItems.manager.auctionManager.getBazaarInfo(asString()) != null
-
- fun searchForBazaarItem(displayName: String, amount: Int = -1) {
- if (!LorenzUtils.inSkyBlock) return
- if (NEUItems.neuHasFocus()) return
- if (LorenzUtils.noTradeMode) return
- if (LorenzUtils.inDungeons || LorenzUtils.inKuudraFight) return
- ChatUtils.sendCommandToServer("bz ${displayName.removeColor()}")
- if (amount != -1) OSUtils.copyToClipboard(amount.toString())
- currentSearchedItem = displayName.removeColor()
- }
- }
-
- @SubscribeEvent
- fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
- inBazaarInventory = checkIfInBazaar(event)
- if (inBazaarInventory) {
- val itemName = getOpenedProduct(event.inventoryItems) ?: return
- val openedProduct = NEUItems.getInternalNameOrNull(itemName)
- currentlyOpenedProduct = openedProduct
- BazaarOpenedProductEvent(openedProduct, event).postAndCatch()
- }
- }
-
- private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): String? {
- val buyInstantly = inventoryItems[10] ?: return null
-
- if (buyInstantly.displayName != "§aBuy Instantly") return null
- val bazaarItem = inventoryItems[13] ?: return null
-
- return bazaarItem.displayName
- }
-
- @SubscribeEvent
- fun onTick(event: LorenzTickEvent) {
-
- if (!loadedNpcPriceData) {
- loadedNpcPriceData = true
- holder.start()
- }
- }
-
- @SubscribeEvent
- fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
- if (!LorenzUtils.inSkyBlock) return
- if (!inBazaarInventory) return
- if (!SkyHanniMod.feature.bazaar.purchaseHelper) return
- if (currentSearchedItem == "") return
-
- if (event.gui !is GuiChest) return
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
-
- for (slot in chest.inventorySlots) {
- if (slot == null) continue
- val stack = slot.stack ?: continue
-
- if (chest.inventorySlots.indexOf(slot) !in 9..44) {
- continue
- }
-
- if (stack.displayName.removeColor() == currentSearchedItem) {
- slot highlight LorenzColor.GREEN
- }
- }
- }
-
- @SubscribeEvent
- fun onChat(event: LorenzChatEvent) {
- if (!LorenzUtils.inSkyBlock) return
- if (!inBazaarInventory) return
- // TODO USE SH-REPO
- // TODO remove dynamic pattern
- "\\[Bazaar] (Buy Order Setup!|Bought).*$currentSearchedItem.*".toPattern()
- .matchMatcher(event.message.removeColor()) { currentSearchedItem = "" }
- }
-
- private fun checkIfInBazaar(event: InventoryFullyOpenedEvent): Boolean {
- val items = event.inventorySize.let { listOf(it - 5, it - 6) }.mapNotNull { event.inventoryItems[it] }
- if (items.any { it.name.equalsIgnoreColor("Go Back") && it.getLore().firstOrNull() == "§7To Bazaar" }) {
- return true
- }
-
- if (event.inventoryName.startsWith("Bazaar ➜ ")) return true
- return when (event.inventoryName) {
- "How many do you want?" -> true
- "How much do you want to pay?" -> true
- "Confirm Buy Order" -> true
- "Confirm Instant Buy" -> true
- "At what price are you selling?" -> true
- "Confirm Sell Offer" -> true
- "Order options" -> true
-
- else -> false
- }
- }
-
- @SubscribeEvent
- fun onInventoryClose(event: InventoryCloseEvent) {
- inBazaarInventory = false
- currentlyOpenedProduct = null
- }
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
deleted file mode 100644
index 3e409b0c6..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
+++ /dev/null
@@ -1,80 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent
-import at.hannibal2.skyhanni.events.InventoryCloseEvent
-import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData
-import at.hannibal2.skyhanni.utils.InventoryUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
-import at.hannibal2.skyhanni.utils.ItemUtils.itemName
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.NEUInternalName
-import at.hannibal2.skyhanni.utils.NumberUtil
-import at.hannibal2.skyhanni.utils.RenderUtils.renderString
-import io.github.moulberry.notenoughupdates.events.SlotClickEvent
-import net.minecraft.item.ItemStack
-import net.minecraftforge.client.event.GuiScreenEvent
-import net.minecraftforge.fml.common.eventhandler.EventPriority
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class BazaarBestSellMethod {
-
- private var display = ""
-
- // Working with the last clicked item manually because
- // the open inventory event happen while the recent clicked item in the inventory is not in the inventory or in the cursor slot
- private var lastClickedItem: ItemStack? = null
- private var nextCloseWillResetItem = false
-
- @SubscribeEvent
- fun onInventoryClose(event: InventoryCloseEvent) {
- display = ""
- if (lastClickedItem != null) {
- if (nextCloseWillResetItem) {
- lastClickedItem = null
- }
- nextCloseWillResetItem = !nextCloseWillResetItem
- }
- }
-
- @SubscribeEvent
- fun onBazaarOpenedProduct(event: BazaarOpenedProductEvent) {
- if (!isEnabled()) return
- display = updateDisplay(event.openedProduct)
- }
-
- private fun updateDisplay(internalName: NEUInternalName?): String {
- if (internalName == null) {
- return "§cUnknown Bazaar item!"
- }
- var having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName }
- lastClickedItem?.let {
- if (it.getInternalName() == internalName) {
- having += it.stackSize
- }
- }
- if (having <= 0) return ""
-
- val data = internalName.getBazaarData() ?: return ""
- val totalDiff = (data.buyPrice - data.sellPrice) * having
- val result = NumberUtil.format(totalDiff.toInt())
-
- val name = internalName.itemName
- return "$name§7 sell difference: §6$result coins"
- }
-
- @SubscribeEvent(priority = EventPriority.LOWEST)
- fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) {
- if (!isEnabled()) return
-
- SkyHanniMod.feature.bazaar.bestSellMethodPos.renderString(display, posLabel = "Bazaar Best Sell Method")
- }
-
- @SubscribeEvent(priority = EventPriority.HIGH)
- fun onStackClick(event: SlotClickEvent) {
- lastClickedItem = event.slot?.stack
- nextCloseWillResetItem = false
- }
-
- private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.bestSellMethod
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
deleted file mode 100644
index 3c5403309..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.events.LorenzToolTipEvent
-import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.getLore
-import at.hannibal2.skyhanni.utils.ItemUtils.name
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.OSUtils
-import at.hannibal2.skyhanni.utils.StringUtils.findMatcher
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
-import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class BazaarCancelledBuyOrderClipboard {
-
- private val patternGroup = RepoPattern.group("bazaar.cancelledorder")
- private val lastAmountPattern by patternGroup.pattern(
- "lastamount",
- "§a(?<amount>.*)§7x"
- )
- private val cancelledMessagePattern by patternGroup.pattern(
- "cancelledmessage",
- "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!"
- )
-
- private var latestAmount: String? = null
-
- @SubscribeEvent
- fun onTooltip(event: LorenzToolTipEvent) {
- if (!isEnabled()) return
-
- val stack = event.itemStack
- val name = stack.name ?: return
- if (!name.contains("Cancel Order")) return
-
- for (line in stack.getLore()) {
- lastAmountPattern.findMatcher(line) {
- latestAmount = group("amount")
- }
- }
- }
-
- @SubscribeEvent
- fun onChat(event: LorenzChatEvent) {
- if (!isEnabled()) return
-
- cancelledMessagePattern.matchMatcher(event.message) {
- event.blockedReason = "bazaar cancelled buy order clipboard"
- val coins = group("coins")
- ChatUtils.chat("Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)")
-
- latestAmount?.let { OSUtils.copyToClipboard(it.replace(",", "")) }
- latestAmount = null
- }
- }
-
- fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.cancelledBuyOrderClipboard
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
deleted file mode 100644
index daed03152..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-data class BazaarData(
- val displayName: String,
- val sellPrice: Double,
- val buyPrice: Double,
-) \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt
deleted file mode 100644
index 02e1f1446..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt
+++ /dev/null
@@ -1,78 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.config.ConfigManager
-import at.hannibal2.skyhanni.data.jsonobjects.other.SkyblockItemsDataJson
-import at.hannibal2.skyhanni.features.rift.RiftAPI
-import at.hannibal2.skyhanni.test.command.ErrorManager
-import at.hannibal2.skyhanni.utils.APIUtil
-import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.name
-import at.hannibal2.skyhanni.utils.NEUInternalName
-import at.hannibal2.skyhanni.utils.NEUItems
-import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getPrice
-import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import at.hannibal2.skyhanni.utils.fromJson
-import kotlinx.coroutines.launch
-import kotlin.concurrent.fixedRateTimer
-
-class BazaarDataHolder {
-
- companion object {
-
- private val bazaarData = mutableMapOf<NEUInternalName, BazaarData>()
- private var npcPrices = mapOf<NEUInternalName, Double>()
-
- fun getNpcPrice(internalName: NEUInternalName) = npcPrices[internalName]
- }
-
- private fun loadNpcPrices(): MutableMap<NEUInternalName, Double> {
- val list = mutableMapOf<NEUInternalName, Double>()
- val apiResponse = APIUtil.getJSONResponse("https://api.hypixel.net/v2/resources/skyblock/items")
- try {
- val itemsData = ConfigManager.gson.fromJson<SkyblockItemsDataJson>(apiResponse)
-
- val motesPrice = mutableMapOf<NEUInternalName, Double>()
- for (item in itemsData.items) {
- val neuItemId = NEUItems.transHypixelNameToInternalName(item.id ?: continue)
- item.npcPrice?.let { list[neuItemId] = it }
- item.motesPrice?.let { motesPrice[neuItemId] = it }
- }
- RiftAPI.motesPrice = motesPrice
- } catch (e: Throwable) {
- ErrorManager.logErrorWithData(
- e, "Error getting npc sell prices",
- "hypixelApiResponse" to apiResponse
- )
- }
- return list
- }
-
- fun start() {
- SkyHanniMod.coroutineScope.launch {
- npcPrices = loadNpcPrices()
- }
-
- fixedRateTimer(name = "skyhanni-bazaar-update", period = 10_000L) {
- bazaarData.clear()
- }
- }
-
- fun getData(internalName: NEUInternalName) = bazaarData[internalName] ?: createNewData(internalName)
-
- private fun createNewData(internalName: NEUInternalName): BazaarData? {
- val stack = internalName.getItemStackOrNull()
- if (stack == null) {
- ChatUtils.debug("Bazaar data is null: '$internalName'")
- return null
- }
- val displayName = stack.name!!.removeColor()
- val sellPrice = internalName.getPrice(true)
- val buyPrice = internalName.getPrice(false)
-
- val data = BazaarData(displayName, sellPrice, buyPrice)
- bazaarData[internalName] = data
- return data
- }
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt
deleted file mode 100644
index 0f03c9b0d..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOpenPriceWebsite.kt
+++ /dev/null
@@ -1,66 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.utils.NEUInternalName
-import at.hannibal2.skyhanni.utils.NEUItems
-import at.hannibal2.skyhanni.utils.OSUtils
-import at.hannibal2.skyhanni.utils.SimpleTimeMark
-import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent
-import io.github.moulberry.notenoughupdates.events.SlotClickEvent
-import io.github.moulberry.notenoughupdates.util.Utils
-import net.minecraft.entity.player.InventoryPlayer
-import net.minecraftforge.fml.common.eventhandler.EventPriority
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.time.Duration.Companion.seconds
-
-class BazaarOpenPriceWebsite {
-
- private val config get() = SkyHanniMod.feature.bazaar
- private var lastClick = SimpleTimeMark.farPast()
-
- private val item by lazy {
- val neuItem = NEUItems.getItemStack("PAPER")
- Utils.createItemStack(
- neuItem.item,
- "§bPrice History",
- "§7Click here to open",
- "§7the price history",
- "§7on §cskyblock.bz"
- )
- }
-
- @SubscribeEvent
- fun replaceItem(event: ReplaceItemEvent) {
- if (!isEnabled()) return
- BazaarApi.currentlyOpenedProduct ?: return
- if (event.inventory is InventoryPlayer) return
-
- if (event.slotNumber == 22) {
- event.replaceWith(item)
- }
- }
-
- @SubscribeEvent(priority = EventPriority.HIGH)
- fun onStackClick(event: SlotClickEvent) {
- if (!isEnabled()) return
- val lastItem = BazaarApi.currentlyOpenedProduct ?: return
-
- if (event.slotId == 22) {
- event.isCanceled = true
- if (lastClick.passedSince() > 0.3.seconds) {
- val name = getSkyBlockBzName(lastItem)
- OSUtils.openBrowser("https://www.skyblock.bz/product/$name")
- lastClick = SimpleTimeMark.now()
- }
- }
- }
-
- private fun getSkyBlockBzName(internalName: NEUInternalName): String {
- val name = internalName.asString()
- return if (name.contains(";")) {
- "ENCHANTMENT_" + name.replace(";", "_")
- } else name
- }
-
- fun isEnabled() = config.openPriceWebsite
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
deleted file mode 100644
index 6a42fe214..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ /dev/null
@@ -1,92 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.GuiContainerEvent
-import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
-import at.hannibal2.skyhanni.utils.ItemUtils.getLore
-import at.hannibal2.skyhanni.utils.ItemUtils.name
-import at.hannibal2.skyhanni.utils.LorenzColor
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.RenderUtils.highlight
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
-import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
-import net.minecraft.inventory.Slot
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class BazaarOrderHelper {
- private val patternGroup = RepoPattern.group("bazaar.orderhelper")
- private val bazaarItemNamePattern by patternGroup.pattern(
- "itemname",
- "§.§l(?<type>BUY|SELL) (?<name>.*)"
- )
- private val filledPattern by patternGroup.pattern(
- "filled",
- "§7Filled: §[a6].*§7/.* §a§l100%!"
- )
- private val pricePattern by patternGroup.pattern(
- "price",
- "§7Price per unit: §6(?<number>.*) coins"
- )
-
- companion object {
-
- 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
- if (!SkyHanniMod.feature.bazaar.orderHelper) return
- if (event.gui !is GuiChest) return
-
- val guiChest = event.gui
- val chest = guiChest.inventorySlots as ContainerChest
- val inventoryName = chest.getInventoryName()
- if (!isBazaarOrderInventory(inventoryName)) return
-
- for (slot in chest.inventorySlots) {
- if (slot == null) continue
- if (slot.slotNumber != slot.slotIndex) continue
- if (slot.stack == null) continue
-
- val itemName = slot.stack.name ?: continue
- bazaarItemNamePattern.matchMatcher(itemName) {
- val buyOrSell = group("type").let { (it == "BUY") to (it == "SELL") }
- if (buyOrSell.let { !it.first && !it.second }) return
-
- highlightItem(group("name"), slot, buyOrSell)
- }
- }
- }
-
- private fun highlightItem(itemName: String, slot: Slot, buyOrSell: Pair<Boolean, Boolean>) {
- val data = BazaarApi.getBazaarDataByName(itemName)
- if (data == null) {
- ChatUtils.debug("Bazaar data is null for bazaarItemName '$itemName'")
- return
- }
-
- val itemLore = slot.stack.getLore()
- for (line in itemLore) {
- filledPattern.matchMatcher(line) {
- slot highlight LorenzColor.GREEN
- return
- }
-
- pricePattern.matchMatcher(line) {
- val price = group("number").replace(",", "").toDouble()
- if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) {
- slot highlight LorenzColor.GOLD
- return
- }
- }
- }
- }
-}