From 9e3d64fe033ddce0f0ab168e3cb3b6a6bcf08bcb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 9 Aug 2023 12:54:18 +0200 Subject: Using NEUInternalName in EstimatedItemValue --- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 3 +++ .../at/hannibal2/skyhanni/utils/NEUInternalName.kt | 2 ++ .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 13 ++++++++----- .../skyhanni/utils/SkyBlockItemModifierUtils.kt | 22 +++++++++++----------- 4 files changed, 24 insertions(+), 16 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index abbe62057..06fdf7f11 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -224,4 +225,6 @@ object ItemUtils { itemAmountCache[input] = pair return pair } + + fun NEUInternalName.getItemName() = getItemStack().name ?: error("No item name found for $this") } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt index e57fc1768..c2269e186 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt @@ -5,6 +5,8 @@ class NEUInternalName private constructor(private val internalName: String) { companion object { private val map = mutableMapOf() + fun String.asInternalName() = from(this) + fun from(name: String): NEUInternalName { val internalName = name.uppercase() return map.getOrPut(internalName) { NEUInternalName(internalName) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 75f9d1562..e3674efd0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.test.command.CopyErrorCommand import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -138,14 +139,17 @@ object NEUItems { fun getInternalNameOrNull(nbt: NBTTagCompound) = ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName() - fun getPriceOrNull(internalName: String, useSellingPrice: Boolean = false): Double? { - val price = getPrice(internalName, useSellingPrice) + fun NEUInternalName.getPriceOrNull(useSellingPrice: Boolean = false): Double? { + val price = getPrice(useSellingPrice) if (price == -1.0) { return null } return price } + fun getPriceOrNull(internalName: String, useSellingPrice: Boolean = false) = + internalName.asInternalName().getPriceOrNull(useSellingPrice) + fun transHypixelNameToInternalName(hypixelId: String): NEUInternalName { val name = manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId) return NEUInternalName.from(name) @@ -318,15 +322,14 @@ object NEUItems { } // Taken and edited from NEU - private fun resolveEnchantmentByName(enchantmentName: String): String? { - return enchantmentNamePattern.matchMatcher(enchantmentName) { + private fun resolveEnchantmentByName(enchantmentName: String) = + enchantmentNamePattern.matchMatcher(enchantmentName) { val name = group("name").trim { it <= ' ' } val ultimate = group("format").lowercase().contains("§l") ((if (ultimate && name != "Ultimate Wise") "ULTIMATE_" else "") + turboCheck(name).replace(" ", "_").replace("-", "_").uppercase() + ";" + group("level").romanToDecimal()) } - } //Uses NEU fun saveNBTData(item: ItemStack, removeLore: Boolean = true): String { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index a7b129349..b63bdcef3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.mixins.hooks.ItemStackCachedData 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.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import com.google.gson.JsonObject import net.minecraft.item.ItemStack @@ -87,40 +88,39 @@ object SkyBlockItemModifierUtils { } fun ItemStack.getDrillUpgrades() = getExtraAttributes()?.let { - val list = mutableListOf() + val list = mutableListOf() for (attributes in it.keySet) { if (attributes in drillPartTypes) { val upgradeItem = it.getString(attributes) - list.add(upgradeItem.uppercase()) + list.add(upgradeItem.uppercase().asInternalName()) } } list } - fun ItemStack.getPowerScroll() = getAttributeString("power_ability_scroll") + fun ItemStack.getPowerScroll() = getAttributeString("power_ability_scroll")?.asInternalName() - fun ItemStack.getHelmetSkin() = getAttributeString("skin") + fun ItemStack.getHelmetSkin() = getAttributeString("skin")?.asInternalName() - fun ItemStack.getArmorDye() = getAttributeString("dye_item") + fun ItemStack.getArmorDye() = getAttributeString("dye_item")?.asInternalName() - fun ItemStack.getRune(): String? { + fun ItemStack.getRune(): NEUInternalName? { val runesMap = getExtraAttributes()?.getCompoundTag("runes") ?: return null val runesList = runesMap.keySet.associateWith { runesMap.getInteger(it) }.toList() if (runesList.isEmpty()) return null val (name, tier) = runesList.first() - return "${name.uppercase()}_RUNE;$tier" + return "${name.uppercase()}_RUNE;$tier".asInternalName() } fun ItemStack.getAbilityScrolls() = getExtraAttributes()?.let { - val list = mutableListOf() + val list = mutableListOf() for (attributes in it.keySet) { if (attributes == "ability_scroll") { val tagList = it.getTagList(attributes, 8) for (i in 0..3) { val text = tagList.get(i).toString() if (text == "END") break - val internalName = text.replace("\"", "") - list.add(internalName) + list.add(text.replace("\"", "").asInternalName()) } } } @@ -227,7 +227,7 @@ object SkyBlockItemModifierUtils { fun ItemStack.getExtraAttributes() = tagCompound?.getCompoundTag("ExtraAttributes") class GemstoneSlot(val type: GemstoneType, val quality: GemstoneQuality) { - fun getInternalName() = "${quality}_${type}_GEM" + fun getInternalName() = "${quality}_${type}_GEM".asInternalName() } enum class GemstoneQuality(val displayName: String) { -- cgit