diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-09-07 12:58:34 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-09-07 12:58:34 +0200 |
commit | 9eac32ec67cd3a1ee5058322125f1350414c64ba (patch) | |
tree | 19bc6d30d870d76032d07c0d4725b6e40a249605 /src/main/java/at/hannibal2/skyhanni | |
parent | cfeac0b6a71c592b61c53fad192eb22bb24b0f54 (diff) | |
download | skyhanni-9eac32ec67cd3a1ee5058322125f1350414c64ba.tar.gz skyhanni-9eac32ec67cd3a1ee5058322125f1350414c64ba.tar.bz2 skyhanni-9eac32ec67cd3a1ee5058322125f1350414c64ba.zip |
fixed bazaar api checking too often
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt index 01f01015c..7318f1aa5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt @@ -13,9 +13,7 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa companion object { private val itemNames = mutableMapOf<String, String>() - private var lastData = "" var lastTime = 0L - var blockNoChange = false var currentlyUpdating = false } @@ -60,32 +58,21 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa } private fun checkIfUpdateNeeded() { - if (lastData != "") { - if (System.currentTimeMillis() - lastTime > 9_000) { - blockNoChange = true - } else { - if (blockNoChange) { - return - } - } + if (System.currentTimeMillis() > lastTime + 10_000) { + currentlyUpdating = true + lastTime = System.currentTimeMillis() + updateBazaarData() + currentlyUpdating = false } - - currentlyUpdating = true - updateBazaarData() - currentlyUpdating = false } private fun updateBazaarData() { val bazaarData = APIUtil.getJSONResponse("https://api.hypixel.net/skyblock/bazaar") - if (bazaarData.toString() != lastData) { - lastData = bazaarData.toString() - lastTime = System.currentTimeMillis() - } val products = bazaarData["products"].asJsonObject for (entry in products.entrySet()) { - val apiName = entry.key + var apiName = entry.key //TODO use repo if (apiName == "ENCHANTED_CARROT_ON_A_STICK") continue @@ -108,6 +95,16 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa LorenzUtils.warning("§c[SkyHanni] bazaar item '$apiName' not found! Try restarting your minecraft to fix this.") continue } + + //parse bazaar api format into internal name format + if (apiName.startsWith("ENCHANTMENT_")) { + val split = apiName.split("_") + val last = split.last() + val dropLast = split.drop(1).dropLast(1) + val text = dropLast.joinToString("_") + ";" + last + apiName = text + } + val data = BazaarData(apiName, itemName, sellPrice, buyPrice) bazaarMap[itemName] = data } |