diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-02 16:01:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 16:01:39 +0200 |
commit | 6c8fc0df08331da7e49796985a1df5f14e6d7ac3 (patch) | |
tree | 3fb6f00ae187e3197d98de37d72168a860ee4d71 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 4353efaa3d18a61f49f79273bea63303afcab7e1 (diff) | |
download | skyhanni-6c8fc0df08331da7e49796985a1df5f14e6d7ac3.tar.gz skyhanni-6c8fc0df08331da7e49796985a1df5f14e6d7ac3.tar.bz2 skyhanni-6c8fc0df08331da7e49796985a1df5f14e6d7ac3.zip |
Backend: Bazaar Fetcher (#1597)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
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 - } } |