aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-15 18:49:31 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-15 18:49:31 +0200
commit50de0411385ff51f2ff753630054aa2ea3d4d7ff (patch)
tree284285e0357d9ef4142235da290824ab81690c3f /src
parentc667d204866a442d17de9e61f123d3a72331ccc4 (diff)
downloadskyhanni-50de0411385ff51f2ff753630054aa2ea3d4d7ff.tar.gz
skyhanni-50de0411385ff51f2ff753630054aa2ea3d4d7ff.tar.bz2
skyhanni-50de0411385ff51f2ff753630054aa2ea3d4d7ff.zip
removed bazaar update timer
removed skyhanni bazaar logic and now fully using neu bazaar price logic
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt191
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt69
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt43
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt20
15 files changed, 100 insertions, 295 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 76eda7c64..100076625 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -7,7 +7,10 @@ import at.hannibal2.skyhanni.config.commands.Commands;
import at.hannibal2.skyhanni.data.*;
import at.hannibal2.skyhanni.data.repo.RepoManager;
import at.hannibal2.skyhanni.features.anvil.AnvilCombineHelper;
-import at.hannibal2.skyhanni.features.bazaar.*;
+import at.hannibal2.skyhanni.features.bazaar.BazaarApi;
+import at.hannibal2.skyhanni.features.bazaar.BazaarBestSellMethod;
+import at.hannibal2.skyhanni.features.bazaar.BazaarCancelledBuyOrderClipboard;
+import at.hannibal2.skyhanni.features.bazaar.BazaarOrderHelper;
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay;
import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper;
import at.hannibal2.skyhanni.features.bingo.CompactBingoChat;
@@ -223,7 +226,6 @@ public class SkyHanniMod {
loadModule(new CroesusUnopenedChestTracker());
loadModule(new CompactBingoChat());
loadModule(new BrewingStandOverlay());
- loadModule(new BazaarUpdateTimer());
loadModule(new BarnFishingTimer());
loadModule(new CrimsonIsleReputationHelper(this));
loadModule(new SharkFishCounter());
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index d9197c858..3c6caf271 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -32,7 +32,7 @@ class CollectionAPI {
val asJsonObject = jsonElement.asJsonObject ?: return
for ((rawName, rawCounter) in asJsonObject.entrySet()) {
val counter = rawCounter.asLong
- var itemName = BazaarApi.getBazaarDataForInternalName(rawName)?.itemName
+ var itemName = BazaarApi.getBazaarDataByInternalName(rawName)?.displayName
if (rawName == "MUSHROOM_COLLECTION") {
itemName = "Mushroom"
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index f09836a5b..5a0c8379c 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.config.commands.SimpleCommand.ProcessCommandRunnable
import at.hannibal2.skyhanni.data.ApiDataLoader
import at.hannibal2.skyhanni.data.GuiEditManager
-import at.hannibal2.skyhanni.features.bazaar.BazaarDataGrabber
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay
import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper
import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper
@@ -54,7 +53,6 @@ object Commands {
registerCommand("shprintbingohelper") { BingoNextStepHelper.command() }
registerCommand("shsetapikey") { ApiDataLoader.command(it) }
registerCommand("shtestgardenvisitors") { LorenzTest.testGardenVisitors() }
- registerCommand("shresetitemnames") { BazaarDataGrabber.resetItemNames() }
registerCommand("shtogglehypixelapierrors") { APIUtil.toggleApiErrorMessages() }
registerCommand("shcropspeedmeter") { CropSpeedMeter.toggle() }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java b/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java
index e988c7b67..f26b69997 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Bazaar.java
@@ -24,12 +24,4 @@ public class Bazaar {
@ConfigOption(name = "Cancelled Buy Order Clipboard", desc = "Saves missing items from cancelled buy orders to clipboard for faster re-entry.")
@ConfigEditorBoolean
public boolean cancelledBuyOrderClipboard = false;
-
- @Expose
- @ConfigOption(name = "Update Timer", desc = "A countdown timer for the next Bazaar data update.")
- @ConfigEditorBoolean
- public boolean updateTimer = false;
-
- @Expose
- public Position updateTimerPos = new Position(10, 10, false, true);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt
deleted file mode 100644
index 4d415d920..000000000
--- a/src/main/java/at/hannibal2/skyhanni/events/BazaarUpdateEvent.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package at.hannibal2.skyhanni.events
-
-import at.hannibal2.skyhanni.features.bazaar.BazaarData
-
-class BazaarUpdateEvent(val bazaarMap: MutableMap<String, BazaarData>): LorenzEvent() \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
index 0f6817dd1..4ed8f6255 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
@@ -5,7 +5,7 @@ import at.hannibal2.skyhanni.events.InventoryOpenEvent
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.LorenzUtils
+import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraft.item.ItemStack
@@ -14,7 +14,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class BazaarApi {
companion object {
- val bazaarMap = mutableMapOf<String, BazaarData>()
+ val holder = BazaarDataHolder()
var inBazaarInventory = false
fun getCleanBazaarName(name: String): String {
@@ -35,25 +35,19 @@ class BazaarApi {
return newName
}
- fun getBazaarDataForName(name: String): BazaarData? {
- if (bazaarMap.containsKey(name)) {
- val bazaarData = bazaarMap[name]
- if (bazaarData != null) {
- return bazaarData
- }
- LorenzUtils.error("Bazaar data not found! '$name'")
- }
- return null
- }
+ fun getBazaarDataByName(name: String): BazaarData? =
+ NEUItems.getInternalNameOrNull(name)?.let { getBazaarDataByInternalName(it) }
- fun getBazaarDataForInternalName(internalName: String) =
- bazaarMap.values.firstOrNull { it.apiName == internalName }
+ fun getBazaarDataByInternalName(internalName: String): BazaarData? {
+ return if (isBazaarItem(internalName)) {
+ holder.getData(internalName)
+ } else null
+ }
fun isBazaarItem(stack: ItemStack) = isBazaarItem(stack.getInternalName())
fun isBazaarItem(internalName: String): Boolean {
- val bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName)
- return bazaarInfo != null
+ return NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName) != null
}
}
@@ -95,6 +89,6 @@ class BazaarApi {
}
init {
- BazaarDataGrabber(bazaarMap).start()
+ holder.start()
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
index 55239442f..94ee30d6e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
@@ -38,7 +38,7 @@ class BazaarBestSellMethod {
val bazaarItem = inv.getStackInSlot(13) ?: return ""
var name = bazaarItem.displayName
name = BazaarApi.getCleanBazaarName(name)
- val data = BazaarApi.getBazaarDataForName(name) ?: return ""
+ val data = BazaarApi.getBazaarDataByName(name) ?: return ""
var having = 0
for (slot in chest.inventorySlots) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
index eb76ac18f..e9511d1b1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
@@ -2,10 +2,8 @@ package at.hannibal2.skyhanni.features.bazaar
data class BazaarData(
val apiName: String,
- val itemName: String,
+ val displayName: String,
val sellPrice: Double,
val buyPrice: Double,
val npcPrice: Double,
- val buyMovingWeek: Int,
- val sellMovingWeek: Int,
) \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
deleted file mode 100644
index 0bcaded93..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
+++ /dev/null
@@ -1,191 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.events.BazaarUpdateEvent
-import at.hannibal2.skyhanni.utils.APIUtil
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.LorenzUtils.round
-import at.hannibal2.skyhanni.utils.NumberUtil.isInt
-import at.hannibal2.skyhanni.utils.NumberUtil.toRoman
-import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
-import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import kotlin.concurrent.fixedRateTimer
-
-internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, BazaarData>) {
-
- companion object {
- private val itemNames = mutableMapOf<String, String>()
- private val npcPrices = mutableMapOf<String, Double>()
-
- var lastTime = 0L
- var currentlyUpdating = false
-
- fun resetItemNames() {
- LorenzUtils.chat("§e[SkyHanni] Reloading the hypixel item api..")
- itemNames.clear()
- }
- }
-
- private fun loadItemNames(): Boolean {
- currentlyUpdating = true
- try {
- val itemsData = APIUtil.getJSONResponse("https://api.hypixel.net/resources/skyblock/items")
- for (element in itemsData["items"].asJsonArray) {
- val jsonObject = element.asJsonObject
- val name = jsonObject["name"].asString
- val id = jsonObject["id"].asString
- itemNames[id] = name.removeColor()
-// if (id.lowercase().contains("redstone")) {
- if (jsonObject.has("npc_sell_price")) {
-// println(" ")
-// println("name: $name")
-// println("id: $id")
- val npcPrice = jsonObject["npc_sell_price"].asDouble
-// println("npcPrice: $npcPrice")
- npcPrices[id] = npcPrice
- }
-// println("jsonObject: $jsonObject")
-// }
- }
- currentlyUpdating = false
- return true
- } catch (e: Throwable) {
- e.printStackTrace()
- LorenzUtils.error("Error while trying to read bazaar item list from api: " + e.message)
- currentlyUpdating = false
- return false
- }
- }
-
- fun start() {
- fixedRateTimer(name = "skyhanni-bazaar-update", period = 1000L) {
- if (!LorenzUtils.inSkyBlock) {
- return@fixedRateTimer
- }
-
- if (currentlyUpdating) {
- LorenzUtils.error("Bazaar update took too long! Error?")
- return@fixedRateTimer
- }
-
- if (itemNames.isEmpty()) {
- if (!loadItemNames()) {
- return@fixedRateTimer
- }
- }
- checkIfUpdateNeeded()
- }
- }
-
- private fun checkIfUpdateNeeded() {
- if (System.currentTimeMillis() > lastTime + 10_000) {
- currentlyUpdating = true
- lastTime = System.currentTimeMillis()
- updateBazaarData()
- currentlyUpdating = false
- }
- }
-
- private fun updateBazaarData() {
- val bazaarData = APIUtil.getJSONResponse("https://api.hypixel.net/skyblock/bazaar")
-
- val products = bazaarData["products"].asJsonObject
-
- for (entry in products.entrySet()) {
- var apiName = entry.key
-
- //TODO use repo
- if (apiName == "ENCHANTED_CARROT_ON_A_STICK") continue
- if (apiName == "BAZAAR_COOKIE") continue
-
- val itemData = entry.value.asJsonObject
- val sellPrice = try {
- itemData["sell_summary"].asJsonArray[0].asJsonObject["pricePerUnit"].asDouble.round(1)
- } catch (e: Exception) {
- 0.0
- }
- val buyPrice: Double = try {
- itemData["buy_summary"].asJsonArray[0].asJsonObject["pricePerUnit"].asDouble.round(1)
- } catch (e: Exception) {
- 0.0
- }
-
- val itemName = getItemName(apiName)
- if (itemName == null) {
- LorenzUtils.warning("§c[SkyHanni] bazaar item '$apiName' not found!")
- resetItemNames()
- continue
- }
-
- val sellMovingWeek = itemData["quick_status"].asJsonObject["sellMovingWeek"].asInt
- val buyMovingWeek = itemData["quick_status"].asJsonObject["buyMovingWeek"].asInt
- //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 npcPrice = npcPrices[apiName] ?: -1.0
-// if (npcPrice == -1.0) {
-// if (apiName.lowercase().contains("carrot")) {
-// println(" ")
-// println("BazaarData")
-// println("itemName: '$itemName'")
-// println("apiName: '$apiName'")
-// println("npc price: $npcPrice")
-// }
-// }
-
- val data = BazaarData(apiName, itemName, sellPrice, buyPrice, npcPrice, buyMovingWeek, sellMovingWeek)
- bazaarMap[itemName] = data
- }
- BazaarUpdateEvent(bazaarMap).postAndCatch()
- }
-
- private fun getItemName(apiName: String): String? {
- var itemName = itemNames.getOrDefault(apiName, null)
-
- //Crimson Essence
- //ESSENCE_CRIMSON
- return itemName ?: if (apiName.startsWith("ESSENCE_")) {
- val type = apiName.split("_")[1].firstLetterUppercase()
- itemName = "$type Essence"
- itemNames[apiName] = itemName
- itemName
- } else {
- if (apiName.startsWith("ENCHANTMENT_ULTIMATE_") && !apiName.contains("JERRY") && !apiName.contains("WISE")) {
- val enchantmentName = getEnchantmentRealName(apiName.split("ENCHANTMENT_ULTIMATE_")[1])
- itemNames[apiName] = enchantmentName
- enchantmentName
- } else if (apiName.startsWith("ENCHANTMENT_")) {
- val enchantmentName = getEnchantmentRealName(apiName.split("ENCHANTMENT_")[1])
- itemNames[apiName] = enchantmentName
- enchantmentName
- } else {
- null
- }
- }
- }
-
- private fun getEnchantmentRealName(rawName: String): String {
- val builder = StringBuilder()
- for (word in rawName.lowercase().split("_")) {
- if (word.isInt()) {
- val number = word.toInt()
- if (number < 1) continue
- builder.append(number.toRoman())
- } else {
- if (word in listOf("of", "the")) {
- builder.append(word)
- } else {
- builder.append(word.firstLetterUppercase())
- }
- }
- builder.append(" ")
- }
- val string = builder.toString()
- return string.substring(0, string.length - 1)
- }
-} \ 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
new file mode 100644
index 000000000..121aa7dfb
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt
@@ -0,0 +1,69 @@
+package at.hannibal2.skyhanni.features.bazaar
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.APIUtil
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates
+import kotlinx.coroutines.launch
+import kotlin.concurrent.fixedRateTimer
+
+class BazaarDataHolder {
+
+ companion object {
+ private val bazaarData = mutableMapOf<String, BazaarData>()
+ private var npcPrices = mapOf<String, Double>()
+ }
+
+ private fun loadNpcPrices(): MutableMap<String, Double> {
+ println("loadNpcPrices")
+ val list = mutableMapOf<String, Double>()
+ try {
+ val itemsData = APIUtil.getJSONResponse("https://api.hypixel.net/resources/skyblock/items")
+ for (element in itemsData["items"].asJsonArray) {
+ val jsonObject = element.asJsonObject
+ if (jsonObject.has("npc_sell_price")) {
+ val hypixelId = jsonObject["id"].asString
+ val npcPrice = jsonObject["npc_sell_price"].asDouble
+ val auctionManager = NotEnoughUpdates.INSTANCE.manager.auctionManager
+ val neuItemId = auctionManager.transformHypixelBazaarToNEUItemId(hypixelId)
+ list[neuItemId] = npcPrice
+ }
+ }
+ } catch (e: Throwable) {
+ e.printStackTrace()
+ LorenzUtils.error("Error while trying to read bazaar item list from api: " + e.message)
+ }
+ return list
+ }
+
+ fun start() {
+ SkyHanniMod.coroutineScope.launch {
+ npcPrices = loadNpcPrices()
+ }
+
+ fixedRateTimer(name = "skyhanni-bazaar-update", period = 10_000L) {
+ bazaarData.clear()
+ }
+ }
+
+ fun getData(internalName: String) = bazaarData[internalName] ?: createNewData(internalName)
+
+ private fun createNewData(internalName: String): BazaarData {
+ val displayName = NEUItems.getItemStack(internalName).name!!.removeColor()
+ val sellPrice = NEUItems.getPrice(internalName, true)
+ val buyPrice = NEUItems.getPrice(internalName, false)
+ val npcPrice = npcPrices[internalName].let {
+ if (it == null) {
+ LorenzUtils.debug("NPC price not found for item '$internalName'")
+ 0.0
+ } else it
+ }
+
+ val data = BazaarData(internalName, displayName, sellPrice, buyPrice, npcPrice)
+ bazaarData[internalName] = data
+ return data
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
index 8fbb9b0c3..2d5284790 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -47,7 +47,7 @@ class BazaarOrderHelper {
val rawName = itemName.split(if (isBuying) "BUY " else "SELL ")[1]
val bazaarName = BazaarApi.getCleanBazaarName(rawName)
- val data = BazaarApi.getBazaarDataForName(bazaarName)
+ val data = BazaarApi.getBazaarDataByName(bazaarName)
if (data == null) {
LorenzUtils.debug("Bazaar data is null!")
println("Bazaar data is null for '$rawName'/'$bazaarName'")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt
deleted file mode 100644
index 72c306a17..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package at.hannibal2.skyhanni.features.bazaar
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.BazaarUpdateEvent
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.TimeUnit
-import at.hannibal2.skyhanni.utils.TimeUtils
-import net.minecraftforge.client.event.GuiScreenEvent
-import net.minecraftforge.fml.common.eventhandler.EventPriority
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-class BazaarUpdateTimer {
- private var lastBazaarUpdateTime = 0L
-
- @SubscribeEvent
- fun onBazaarUpdate(event: BazaarUpdateEvent) {
- if (!isEnabled()) return
- lastBazaarUpdateTime = System.currentTimeMillis()
- }
-
- @SubscribeEvent(priority = EventPriority.LOWEST)
- fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) {
- if (!isEnabled()) return
- if (!BazaarApi.inBazaarInventory) return
-
- val duration = 10_000 - (System.currentTimeMillis() - lastBazaarUpdateTime)
- val format = if (duration < 0) {
- "Updating"
- } else {
- TimeUtils.formatDuration(duration, TimeUnit.SECOND, showMilliSeconds = true)
- }
-
- val list = mutableListOf<String>()
- list.add("Next update in:")
- list.add(format)
- SkyHanniMod.feature.bazaar.updateTimerPos.renderStrings(list, posLabel = "Bazaar Update Timer")
- }
-
- private fun isEnabled(): Boolean {
- return LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.updateTimer
- }
-} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
index a9d25ecb3..26ddd50c0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
@@ -203,7 +203,7 @@ class CropMoneyDisplay {
val speedPerHour = speed * 60 * 60
val cropsPerHour = speedPerHour / amount.toDouble()
- val bazaarData = BazaarApi.getBazaarDataForInternalName(internalName) ?: continue
+ val bazaarData = BazaarApi.getBazaarDataByInternalName(internalName) ?: continue
var npcPrice = bazaarData.npcPrice * cropsPerHour
var sellOffer = bazaarData.buyPrice * cropsPerHour
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
index 93e507826..05c549a70 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
@@ -45,7 +45,11 @@ object APIUtil {
try {
return parser.parse(retSrc) as JsonObject
} catch (e: JsonSyntaxException) {
- if (retSrc.contains("<center><h1>502 Bad Gateway</h1></center>")) {
+ if (e.message?.contains("Use JsonReader.setLenient(true)") == true) {
+ println("MalformedJsonException: Use JsonReader.setLenient(true)")
+ println(" - getJSONResponse: '$urlString'")
+ LorenzUtils.debug("MalformedJsonException: Use JsonReader.setLenient(true)")
+ } else if (retSrc.contains("<center><h1>502 Bad Gateway</h1></center>")) {
if (showApiErrors) {
LorenzUtils.clickableChat(
"[SkyHanni] Problems with detecting the Hypixel API. §eClick here to hide this message for now.",
@@ -58,11 +62,6 @@ object APIUtil {
LorenzUtils.error("[SkyHanni] JsonSyntaxException at getJSONResponse!")
println("result: '$retSrc'")
}
- if (e.message?.contains("Use JsonReader.setLenient(true)") == true) {
- println("MalformedJsonException: Use JsonReader.setLenient(true)")
- println(" - getJSONResponse: '$urlString'")
- LorenzUtils.debug("MalformedJsonException: Use JsonReader.setLenient(true)")
- }
e.printStackTrace()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 2549c215b..76a2f7d2a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -1,6 +1,5 @@
package at.hannibal2.skyhanni.utils
-import at.hannibal2.skyhanni.features.bazaar.BazaarApi
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import io.github.moulberry.notenoughupdates.NEUManager
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
@@ -60,28 +59,21 @@ object NEUItems {
return price
}
- fun getPrice(internalName: String, useSellingPrice: Boolean = false): Double {
- val bazaarData = BazaarApi.getBazaarDataForInternalName(internalName)
- bazaarData?.let {
- val buyPrice = it.buyPrice
- if (buyPrice > 0) return buyPrice
-
- val sellPrice = it.sellPrice
- if (sellPrice > 0) return sellPrice
-
- return it.npcPrice
- }
+ fun getPrice(internalName: String): Double {
+ return getPrice(internalName, false)
+ }
+ fun getPrice(internalName: String, useSellingPrice: Boolean): Double {
val result = manager.auctionManager.getBazaarOrBin(internalName, useSellingPrice)
- // TODO remove workaround
if (result == -1.0) {
if (internalName == "JACK_O_LANTERN") {
- return getPrice("PUMPKIN") + 1
+ return getPrice("PUMPKIN", useSellingPrice) + 1
}
if (internalName == "GOLDEN_CARROT") {
// 6.8 for some players
return 7.0 // NPC price
}
+ LorenzUtils.debug("Item price is null for '$internalName'")
}
return result
}