aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-20 19:06:48 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-20 19:06:48 +0200
commit3aa270c43b368f003c0adf69d0ce161e2e710382 (patch)
tree9729ce8c07e411fda8cf410d34d55744138d93fb /src/main/java/at/hannibal2/skyhanni/features
parentdefd6b8afec209935e4e19e0183a7c5498e83af3 (diff)
downloadskyhanni-3aa270c43b368f003c0adf69d0ce161e2e710382.tar.gz
skyhanni-3aa270c43b368f003c0adf69d0ce161e2e710382.tar.bz2
skyhanni-3aa270c43b368f003c0adf69d0ce161e2e710382.zip
fixed BazaarOrderHelper and added essence to bazaar
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt32
2 files changed, 33 insertions, 30 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 925ab11fa..eea1138fa 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
import kotlin.concurrent.fixedRateTimer
internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, BazaarData>) {
@@ -84,19 +85,12 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
for (entry in products.entrySet()) {
val 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 itemName = itemNames.getOrDefault(apiName, null)
- if (itemName == null) {
- //TODO need to re enable this later again
-// LorenzUtils.error("Bazaar item name is null for '$apiName'! Restart to fix this problem!")
- continue
- }
-
- val sellPrice: Double = try {
+ val sellPrice = try {
itemData["sell_summary"].asJsonArray[0].asJsonObject["pricePerUnit"].asDouble.round(1)
} catch (e: Exception) {
0.0
@@ -107,8 +101,27 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
0.0
}
+ val itemName = getItemName(apiName) ?: continue
val data = BazaarData(apiName, itemName, sellPrice, buyPrice)
bazaarMap[itemName] = data
}
}
+
+ 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 {
+ //TODO need to re enable this later again
+ println("unknown bazaar item: '$apiName'")
+// LorenzUtils.error("Bazaar item name is null for '$apiName'! Restart to fix this problem!")
+ null
+ }
+ }
} \ 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 18822e7c2..ab398a5bf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
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.RenderUtils.highlight
import net.minecraft.client.gui.inventory.GuiChest
@@ -40,16 +41,15 @@ class BazaarOrderHelper {
if (slot.stack == null) continue
val stack = slot.stack
- val displayName = stack.displayName
- val isSelling = displayName.startsWith("§6§lSELL§7: ")
- val isBuying = displayName.startsWith("§a§lBUY§7: ")
+ val itemName = stack.name ?: continue
+
+ val isSelling = itemName.startsWith("§6§lSELL ")
+ val isBuying = itemName.startsWith("§a§lBUY ")
if (!isSelling && !isBuying) continue
- val text = displayName.split("§7: ")[1]
- val name = BazaarApi.getCleanBazaarName(text)
- val data = BazaarApi.getBazaarDataForName(name)
- val buyPrice = data.buyPrice
- val sellPrice = data.sellPrice
+ val rawName = itemName.split(if (isBuying) "BUY " else "SELL ")[1]
+ val bazaarName = BazaarApi.getCleanBazaarName(rawName)
+ val data = BazaarApi.getBazaarDataForName(bazaarName)
val itemLore = stack.getLore()
for (line in itemLore) {
@@ -59,25 +59,15 @@ class BazaarOrderHelper {
continue@out
}
}
- }
- for (line in itemLore) {
if (line.startsWith("§7Price per unit:")) {
var text = line.split(": §6")[1]
text = text.substring(0, text.length - 6)
text = text.replace(",", "")
val price = text.toDouble()
- if (isSelling) {
- if (buyPrice < price) {
- slot highlight LorenzColor.GOLD
- continue@out
- }
- } else {
- if (sellPrice > price) {
- slot highlight LorenzColor.GOLD
- continue@out
- }
+ if (isSelling && price > data.buyPrice || isBuying && price < data.sellPrice) {
+ slot highlight LorenzColor.GOLD
+ continue@out
}
-
}
}
}