diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-08-20 19:06:48 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-08-20 19:06:48 +0200 |
commit | 3aa270c43b368f003c0adf69d0ce161e2e710382 (patch) | |
tree | 9729ce8c07e411fda8cf410d34d55744138d93fb /src/main/java/at/hannibal2 | |
parent | defd6b8afec209935e4e19e0183a7c5498e83af3 (diff) | |
download | skyhanni-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')
5 files changed, 60 insertions, 47 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 } - } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index b9b11479f..aafed0994 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -191,4 +191,11 @@ object ItemUtils { return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties") .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value") } + + //extra method for shorter name and kotlin nullability logic + var ItemStack.name: String? + get() = this.displayName + set(value) { + setStackDisplayName(value) + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index c4bc912ee..04d7bb34a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -58,23 +58,6 @@ object LorenzUtils { fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - fun String.removeColor(): String { - val builder = StringBuilder() - var skipNext = false - for (c in this.toCharArray()) { - if (c == '§') { - skipNext = true - continue - } - if (skipNext) { - skipNext = false - continue - } - builder.append(c) - } - - return builder.toString() - } fun SimpleDateFormat.formatCurrentTime(): String = this.format(System.currentTimeMillis()) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt new file mode 100644 index 000000000..a28f6fd2e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -0,0 +1,20 @@ +package at.hannibal2.skyhanni.utils + +object StringUtils { + + fun String.firstLetterUppercase(): String { + if (isEmpty()) return this + + val lowercase = this.lowercase() + val first = lowercase[0].uppercase() + return first + lowercase.substring(1) + } + + fun String.removeColor(): String { + return replace("(?i)\\u00A7.", "") + } + +// fun cleanColour(`in`: String): String? { +// return `in`.replace("(?i)\\u00A7.".toRegex(), "") +// } +}
\ No newline at end of file |