diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
3 files changed, 14 insertions, 33 deletions
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 5d976a7dd..9df83ec81 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.bazaar.HypixelBazaarFetcher import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent @@ -14,6 +15,7 @@ import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.InventoryUtils.getAllItems import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils @@ -41,20 +43,18 @@ class BazaarApi { var currentlyOpenedProduct: NEUInternalName? = null - fun NEUInternalName.getBazaarData() = if (isBazaarItem()) { - holder.getData(this) - } else null + fun NEUInternalName.getBazaarData(): BazaarData? = HypixelBazaarFetcher.latestProductInformation[this] fun NEUInternalName.getBazaarDataOrError(): BazaarData = getBazaarData() ?: run { ErrorManager.skyHanniError( - "Can not find bazaar data for internal name", + "Can not find bazaar data for $itemName", "internal name" to this ) } fun isBazaarItem(stack: ItemStack): Boolean = stack.getInternalName().isBazaarItem() - fun NEUInternalName.isBazaarItem() = NEUItems.manager.auctionManager.getBazaarInfo(asString()) != null + fun NEUInternalName.isBazaarItem() = getBazaarData() != null fun searchForBazaarItem(displayName: String, amount: Int = -1) { if (!LorenzUtils.inSkyBlock) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarData.kt index ed49359bb..db97d5e6b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarData.kt @@ -1,7 +1,14 @@ package at.hannibal2.skyhanni.features.inventory.bazaar +import at.hannibal2.skyhanni.data.bazaar.BazaarProduct + data class BazaarData( val displayName: String, - val sellPrice: Double, - val buyPrice: Double, + val sellOfferPrice: Double, + val instantBuyPrice: Double, + val product: BazaarProduct, + @Deprecated("outdated", ReplaceWith("instantBuyPrice")) + val sellPrice: Double = instantBuyPrice, + @Deprecated("outdated", ReplaceWith("sellOfferPrice")) + val buyPrice: Double = sellOfferPrice, ) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt index 2cbc2474d..8911e1e2b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarDataHolder.kt @@ -6,22 +6,15 @@ 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] @@ -55,25 +48,6 @@ class BazaarDataHolder { } // TODO use SecondPassedEvent - 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 - } } |