From 0662bb696bb5f003a8c0edc14e8d54dac19f78dc Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 29 Jul 2023 20:20:41 +0200 Subject: Created NEUInternalName, fixed collection counter --- .../at/hannibal2/skyhanni/api/CollectionAPI.kt | 44 ++++----- .../skyhanni/features/bazaar/BazaarApi.kt | 20 ++-- .../skyhanni/features/bazaar/BazaarData.kt | 1 - .../skyhanni/features/bazaar/BazaarDataHolder.kt | 21 +++-- .../skyhanni/features/misc/CollectionCounter.kt | 50 +++++++--- .../features/misc/tabcomplete/PlayerTabComplete.kt | 2 +- .../features/misc/tabcomplete/TabComplete.kt | 9 +- .../skyhanni/features/rift/everywhere/RiftAPI.kt | 7 +- .../skyhanni/test/HighlightMissingRepoItems.kt | 6 +- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 6 +- .../at/hannibal2/skyhanni/utils/NEUInternalName.kt | 28 ++++++ .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 102 +++++++++++++-------- 12 files changed, 189 insertions(+), 107 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index 80ff8659f..7b3fbc7d5 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -4,10 +4,12 @@ import at.hannibal2.skyhanni.events.CollectionUpdateEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent -import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_new 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.LorenzUtils.addOrPut +import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -24,12 +26,12 @@ class CollectionAPI { val asJsonObject = jsonElement.asJsonObject ?: return for ((hypixelId, rawCounter) in asJsonObject.entrySet()) { val counter = rawCounter.asLong - val neuItemId = NEUItems.transHypixelNameToInternalName(hypixelId) + val internalName = NEUItems.transHypixelNameToInternalName(hypixelId) - // MUSHROOM_COLLECTION, GEMSTONE_COLLECTION - BazaarApi.getBazaarDataByInternalName(neuItemId)?.displayName ?: continue + // MUSHROOM_COLLECTION, + NEUItems.getItemStackOrNull(internalName)?.displayName ?: continue - collectionValue[neuItemId] = counter + collectionValue[internalName] = counter } CollectionUpdateEvent().postAndCatch() @@ -49,7 +51,8 @@ class CollectionAPI { singleCounterPattern.matchMatcher(line) { val counter = group("amount").replace(",", "").toLong() val name = inventoryName.split(" ").dropLast(1).joinToString(" ") - collectionValue[name] = counter + val internalName = NEUItems.getInternalNameOrNull_new(name) ?: continue + collectionValue[internalName] = counter } } CollectionUpdateEvent().postAndCatch() @@ -72,7 +75,8 @@ class CollectionAPI { for (line in lore) { counterPattern.matchMatcher(line) { val counter = group("amount").replace(",", "").toLong() - collectionValue[name] = counter + val internalName = NEUItems.getInternalNameOrNull_new(name) ?: continue + collectionValue[internalName] = counter } } } @@ -81,33 +85,25 @@ class CollectionAPI { } companion object { - private val collectionValue = mutableMapOf() + val collectionValue = mutableMapOf() private val collectionTier0Pattern = "§7Progress to .* I: .*".toPattern() fun isCollectionTier0(lore: List) = lore.map { collectionTier0Pattern.matcher(it) }.any { it.matches() } - fun getCollectionCounter(searchName: String): Long? { - for ((collectionName, counter) in collectionValue) { - if (collectionName.equals(searchName, true)) { - return counter - } - } - return null - } + fun getCollectionCounter(itemName: String) = getCollectionCounter(NEUItems.getInternalName_new(itemName)) + + fun getCollectionCounter(internalName: NEUInternalName) = collectionValue[internalName] // TODO add support for replenish (higher collection than actual items in inv) - fun addFromInventory(internalName: String, amount: Int) { - val stack = NEUItems.getItemStackOrNull(internalName) + fun addFromInventory(internalNameRaw: String, amount: Int) { + val stack = NEUItems.getItemStackOrNull(internalNameRaw) if (stack == null) { - LorenzUtils.debug("CollectionAPI.addFromInventory: internalName is null for '$internalName'") + LorenzUtils.debug("CollectionAPI.addFromInventory: internalName is null for '$internalNameRaw'") return } + val internalName = stack.getInternalName_new() - val name = stack.name!!.removeColor() - val oldValue = collectionValue[name] ?: return - - val newValue = oldValue + amount - collectionValue[name] = newValue + collectionValue.addOrPut(internalName, amount.toLong()) } } } \ 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 52227e4f7..1d9c20dea 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -2,13 +2,10 @@ package at.hannibal2.skyhanni.features.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.utils.* 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.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.gui.inventory.GuiChest @@ -27,14 +24,19 @@ class BazaarApi { fun getBazaarDataByName(name: String): BazaarData? = NEUItems.getInternalNameOrNull(name)?.let { getBazaarDataByInternalName(it) } - fun getBazaarDataByInternalName(internalName: String): BazaarData? { - return if (isBazaarItem(internalName)) { + fun getBazaarDataByInternalName(internalName: String) = + getBazaarDataByInternalName_new(NEUInternalName.from(internalName)) + + fun getBazaarDataByInternalName_new(internalName: NEUInternalName) = if (isBazaarItem(internalName)) { holder.getData(internalName) } else null - } fun isBazaarItem(stack: ItemStack) = isBazaarItem(stack.getInternalName()) + fun isBazaarItem(internalName: NEUInternalName): Boolean { + return NEUItems.manager.auctionManager.getBazaarInfo(internalName.asString()) != null + } + fun isBazaarItem(internalName: String): Boolean { return NEUItems.manager.auctionManager.getBazaarInfo(internalName) != null } @@ -91,7 +93,9 @@ class BazaarApi { @SubscribeEvent fun onChat(event: LorenzChatEvent) { - if ("\\[Bazaar] (Buy Order Setup!|Bought).*$currentSearchedItem.*".toRegex().matches(event.message.removeColor())) { + if ("\\[Bazaar] (Buy Order Setup!|Bought).*$currentSearchedItem.*".toRegex() + .matches(event.message.removeColor()) + ) { currentSearchedItem = "" } } 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 e9511d1b1..3562be68a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.features.bazaar data class BazaarData( - val apiName: String, val displayName: String, val sellPrice: Double, val buyPrice: Double, diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt index 53ae2935e..c6d31cede 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.features.rift.everywhere.RiftAPI import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.StringUtils.removeColor import kotlinx.coroutines.launch @@ -13,15 +14,15 @@ import kotlin.concurrent.fixedRateTimer class BazaarDataHolder { companion object { - private val bazaarData = mutableMapOf() - private var npcPrices = mapOf() + private val bazaarData = mutableMapOf() + private var npcPrices = mapOf() } - private fun loadNpcPrices(): MutableMap { - val list = mutableMapOf() + private fun loadNpcPrices(): MutableMap { + val list = mutableMapOf() try { val itemsData = APIUtil.getJSONResponse("https://api.hypixel.net/resources/skyblock/items") - val motesPrice = mutableMapOf() + val motesPrice = mutableMapOf() for (element in itemsData["items"].asJsonArray) { val jsonObject = element.asJsonObject val hypixelId = jsonObject["id"].asString @@ -52,10 +53,10 @@ class BazaarDataHolder { } } - fun getData(internalName: String) = bazaarData[internalName] ?: createNewData(internalName) + fun getData(internalName: NEUInternalName) = bazaarData[internalName] ?: createNewData(internalName) - private fun createNewData(internalName: String): BazaarData? { - val stack = NEUItems.getItemStackOrNull(internalName) + private fun createNewData(internalName: NEUInternalName): BazaarData? { + val stack = NEUItems.getItemStackOrNull(internalName.asString()) if (stack == null) { LorenzUtils.debug("Bazaar data is null: '$internalName'") return null @@ -65,14 +66,14 @@ class BazaarDataHolder { val buyPrice = NEUItems.getPrice(internalName, false) val npcPrice = npcPrices[internalName].let { if (it == null) { - if (!ignoreNoNpcPrice(internalName)) { + if (!ignoreNoNpcPrice(internalName.asString())) { LorenzUtils.debug("NPC price not found for item '$internalName'") } 0.0 } else it } - val data = BazaarData(internalName, displayName, sellPrice, buyPrice, npcPrice) + val data = BazaarData(displayName, sellPrice, buyPrice, npcPrice) bazaarData[internalName] = data return data } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt index ef23583e3..ff860b3b5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt @@ -5,14 +5,16 @@ import at.hannibal2.skyhanni.api.CollectionAPI import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_new import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.* class CollectionCounter { @@ -20,10 +22,10 @@ class CollectionCounter { companion object { - private var display = "" + private var display = emptyList>() private var itemName = "" - private var internalName = "" + private var internalName: NEUInternalName? = null private var itemAmount = -1L private var lastAmountInInventory = -1 @@ -33,7 +35,7 @@ class CollectionCounter { fun command(args: Array) { if (args.isEmpty()) { - if (internalName == "") { + if (internalName == null) { LorenzUtils.chat("§c/shtrackcollection ") return } @@ -42,7 +44,7 @@ class CollectionCounter { return } - val rawName = fixTypo(args.joinToString(" ").lowercase()) + val rawName = fixTypo(args.joinToString(" ").lowercase().replace("_", " ")) if (rawName == "gemstone") { LorenzUtils.chat("§c[SkyHanni] Gemstone collection is not supported!") // setNewCollection("GEMSTONE_COLLECTION", "Gemstone") @@ -53,7 +55,13 @@ class CollectionCounter { return } - val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) ?: rawName.replace(" ", "_") +// val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) ?: rawName.replace(" ", "_") + val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) + if (foundInternalName == null) { + LorenzUtils.chat("§c[SkyHanni] Item '$rawName' does not exist!") + return + } + val stack = NEUItems.getItemStackOrNull(foundInternalName) if (stack == null) { LorenzUtils.chat("§c[SkyHanni] Item '$rawName' does not exist!") @@ -63,7 +71,7 @@ class CollectionCounter { } private fun fixTypo(rawName: String) = when (rawName) { - "carrot" -> "carrots" + "carrots" -> "carrot" "melons" -> "melon" "seed" -> "seeds" "iron" -> "iron ingot" @@ -78,11 +86,13 @@ class CollectionCounter { "stone" -> "cobblestone" "red mushroom", "brown mushroom", "mushrooms" -> "mushroom" "gemstones" -> "gemstone" + "caducous" -> "caducous stem" + "agaricus" -> "agaricus cap" else -> rawName } - private fun setNewCollection(internalName: String, name: String) { + private fun setNewCollection(internalName: NEUInternalName, name: String) { val foundAmount = CollectionAPI.getCollectionCounter(internalName) if (foundAmount == null) { LorenzUtils.chat("§c[SkyHanni] Item $name is not in the collection data! (Maybe the API is disabled or try to open the collection inventory)") @@ -99,10 +109,10 @@ class CollectionCounter { private fun resetData() { itemAmount = -1 - internalName = "" + internalName = null lastAmountInInventory = -1 - display = "" + display = emptyList() recentGain = 0 } @@ -115,11 +125,23 @@ class CollectionCounter { gainText = "§a+" + LorenzUtils.formatInteger(recentGain) } - display = "$itemName collection: §e$format $gainText" + display = Collections.singletonList(buildList { + internalName?.let { + add(NEUItems.getItemStack(it)) + } + add("$itemName collection: §e$format $gainText") + }) } private fun countCurrentlyInInventory() = - InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName } + InventoryUtils.countItemsInLowerInventory { it.getInternalName_new() == internalName } + + fun handleTabComplete(command: String): List? { + if (command != "shtrackcollection") return null + + return CollectionAPI.collectionValue.keys.mapNotNull { NEUItems.getItemStackOrNull(it) } + .map { it.displayName.removeColor().replace(" ", "_") } + } } @SubscribeEvent @@ -171,6 +193,6 @@ class CollectionCounter { fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { if (!LorenzUtils.inSkyBlock) return - SkyHanniMod.feature.misc.collectionCounterPos.renderString(display, posLabel = "Collection Counter") + SkyHanniMod.feature.misc.collectionCounterPos.renderStringsAndItems(display, posLabel = "Collection Counter") } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt index 66029a4ee..5bf74e44c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt @@ -25,7 +25,7 @@ object PlayerTabComplete { ISLAND_PLAYERS, } - fun handleTabComplete(command: String, originalArray: Array): List? { + fun handleTabComplete(command: String): List? { val commands = mapOf( "p" to listOf(PlayerCategory.PARTY), "party" to listOf(PlayerCategory.PARTY), diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt index 388b89034..08ec84c52 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt @@ -1,5 +1,7 @@ package at.hannibal2.skyhanni.features.misc.tabcomplete +import at.hannibal2.skyhanni.features.misc.CollectionCounter + object TabComplete { @JvmStatic @@ -9,7 +11,7 @@ object TabComplete { var command = splits.first().lowercase() if (command.startsWith("/")) { command = command.substring(1) - customTabComplete(command, originalArray)?.let { + customTabComplete(command)?.let { return buildResponse(splits, it).toSet().toTypedArray() } } @@ -17,9 +19,10 @@ object TabComplete { return null } - private fun customTabComplete(command: String, originalArray: Array): List? { + private fun customTabComplete(command: String): List? { WarpTabComplete.handleTabComplete(command)?.let { return it } - PlayerTabComplete.handleTabComplete(command, originalArray)?.let { return it } + PlayerTabComplete.handleTabComplete(command)?.let { return it } + CollectionCounter.handleTabComplete(command)?.let { return it } return null } diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt index 20e64dc8f..4e500d21f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt @@ -3,8 +3,9 @@ package at.hannibal2.skyhanni.features.rift.everywhere import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.features.RiftConfig import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_new import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName import net.minecraft.item.ItemStack object RiftAPI { @@ -13,10 +14,10 @@ object RiftAPI { val config: RiftConfig get() = SkyHanniMod.feature.rift // internal name -> motes - var motesPrice = emptyMap() + var motesPrice = emptyMap() fun ItemStack.motesNpcPrice(): Double? { - val baseMotes = motesPrice[getInternalName()] ?: return null + val baseMotes = motesPrice[getInternalName_new()] ?: return null val burgerStacks = config.motes.burgerStacks val pricePer = baseMotes + (burgerStacks * 5) * baseMotes / 100 return pricePer * stackSize diff --git a/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt b/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt index ea814420c..cb48c803e 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull_new import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.MultiFilter @@ -37,9 +37,9 @@ class HighlightMissingRepoItems { private fun highlightItems(slots: Iterable) { if (NEUItems.allInternalNames.isEmpty()) return for (slot in slots) { - val internalName = slot.stack?.getInternalNameOrNull() ?: continue + val internalName = slot.stack?.getInternalNameOrNull_new() ?: continue if (NEUItems.allInternalNames.contains(internalName)) continue - if (ignoreItems.match(internalName)) continue + if (ignoreItems.match(internalName.asString())) continue slot highlight LorenzColor.RED } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 9b06dfb8d..1683f90e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -117,7 +117,11 @@ object ItemUtils { fun ItemStack.getInternalNameOrNull() = getInternalName().takeIf { it != "" } - fun ItemStack.getInternalName(): String { + fun ItemStack.getInternalNameOrNull_new() = getInternalName_new().takeIf { it.asString() != "" } + + fun ItemStack.getInternalName_new() = NEUInternalName.from(getInternalName()) + + fun ItemStack.getInternalName(): String { if (name == "§fWisp's Ice-Flavored Water I Splash Potion") { return "WISP_POTION" } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt new file mode 100644 index 000000000..8e9b8efc2 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt @@ -0,0 +1,28 @@ +package at.hannibal2.skyhanni.utils + +class NEUInternalName private constructor(private val internalName: String) { + + companion object { + private val map = mutableMapOf() + + fun from(name: String): NEUInternalName { + val internalName = name.uppercase() + return map.getOrPut(internalName) { NEUInternalName(internalName) } + } + } + + fun asString() = internalName + + override fun equals(other: Any?): Boolean { + if (other is NEUInternalName) { + return internalName == other.internalName + } + return super.equals(other) + } + + override fun toString(): String { + return "internalName:$internalName" + } + +// fun equals(other: String) = internalName == other +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 077993544..f22f26112 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -29,12 +29,12 @@ import java.util.regex.Pattern object NEUItems { val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager - private val itemNameCache = mutableMapOf() // item name -> internal name + private val itemNameCache = mutableMapOf() // item name -> internal name private val multiplierCache = mutableMapOf>() private val recipesCache = mutableMapOf>() private val enchantmentNamePattern = Pattern.compile("^(?(?:§.)+)(?[^§]+) (?[IVXL]+)$") - var allItemsCache = mapOf() // item name -> internal name - var allInternalNames = mutableListOf() + var allItemsCache = mapOf() // item name -> internal name + var allInternalNames = mutableListOf() private val fallbackItem by lazy { Utils.createItemStack( @@ -45,10 +45,14 @@ object NEUItems { } fun getInternalName(itemName: String): String { - return getInternalNameOrNull(itemName) ?: throw Error("getInternalName is null for '$itemName'") + return getInternalNameOrNull_new(itemName)?.asString() ?: throw Error("getInternalName is null for '$itemName'") } - fun getInternalNameOrNullIgnoreCase(itemName: String): String? { + fun getInternalName_new(itemName: String): NEUInternalName { + return getInternalNameOrNull_new(itemName) ?: throw Error("getInternalName is null for '$itemName'") + } + + fun getInternalNameOrNullIgnoreCase(itemName: String): NEUInternalName? { val lowercase = itemName.removeColor().lowercase() if (itemNameCache.containsKey(lowercase)) { return itemNameCache[lowercase]!! @@ -65,26 +69,30 @@ object NEUItems { return null } - fun readAllNeuItems(): Map { + fun readAllNeuItems(): Map { allInternalNames.clear() - val map = mutableMapOf() - for (internalName in manager.itemInformation.keys) { - val name = manager.createItem(internalName).displayName.removeColor().lowercase() + val map = mutableMapOf() + for (internalNameRaw in manager.itemInformation.keys) { + val name = manager.createItem(internalNameRaw).displayName.removeColor().lowercase() + val internalName = NEUInternalName.from(internalNameRaw) map[name] = internalName allInternalNames.add(internalName) } return map } - fun getInternalNameOrNull(itemName: String): String? { + fun getInternalNameOrNull(itemName: String) = getInternalNameOrNull_new(itemName)?.asString() + + fun getInternalNameOrNull_new(itemName: String): NEUInternalName? { val lowercase = itemName.lowercase() if (itemNameCache.containsKey(lowercase)) { return itemNameCache[lowercase]!! } if (itemName == "§cmissing repo item") { - itemNameCache[lowercase] = "MISSING_ITEM" - return "MISSING_ITEM" + val name = NEUInternalName.from("MISSING_ITEM") + itemNameCache[lowercase] = name + return name } resolveEnchantmentByName(itemName)?.let { @@ -92,26 +100,28 @@ object NEUItems { itemNameCache[itemName] = enchantmentName return enchantmentName } - var internalName = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null + var internalNameRaw = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null // This fixes a NEU bug with §9Hay Bale (cosmetic item) // TODO remove workaround when this is fixed in neu - if (internalName == "HAY_BALE") { - internalName = "HAY_BLOCK" + val internalName = if (internalNameRaw == "HAY_BALE") { + NEUInternalName.from("HAY_BLOCK") + } else { + NEUInternalName.from(internalNameRaw) } itemNameCache[lowercase] = internalName return internalName } - private fun fixEnchantmentName(originalName: String): String { + private fun fixEnchantmentName(originalName: String): NEUInternalName { // Workaround for duplex "ULTIMATE_DUPLEX;(?.*)".toPattern().matchMatcher(originalName) { val tier = group("tier") - return "ULTIMATE_REITERATE;$tier" + return NEUInternalName.from("ULTIMATE_REITERATE;$tier") } - return originalName + return NEUInternalName.from(originalName) } private fun turboCheck(text: String): String { @@ -136,23 +146,27 @@ object NEUItems { return price } - fun getPrice(internalName: String): Double { - if (internalName == "WISP_POTION") { + fun getPrice(internalName: NEUInternalName): Double { + if (internalName.asString() == "WISP_POTION") { return 20_000.0 } return getPrice(internalName, false) } - fun transHypixelNameToInternalName(hypixelId: String): String = - manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId) + fun getPrice(internalName: String) = getPrice(NEUInternalName.from(internalName)) - fun getPrice(internalName: String, useSellingPrice: Boolean): Double { - val result = manager.auctionManager.getBazaarOrBin(internalName, useSellingPrice) + fun transHypixelNameToInternalName(hypixelId: String): NEUInternalName { + val name = manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId) + return NEUInternalName.from(name) + } + + fun getPrice(internalName: NEUInternalName, useSellingPrice: Boolean): Double { + val result = manager.auctionManager.getBazaarOrBin(internalName.asString(), useSellingPrice) if (result == -1.0) { - if (internalName == "JACK_O_LANTERN") { + if (internalName.asString() == "JACK_O_LANTERN") { return getPrice("PUMPKIN", useSellingPrice) + 1 } - if (internalName == "GOLDEN_CARROT") { + if (internalName.asString() == "GOLDEN_CARROT") { // 6.8 for some players return 7.0 // NPC price } @@ -160,22 +174,32 @@ object NEUItems { return result } - fun getItemStackOrNull(internalName: String) = ItemResolutionQuery(manager) - .withKnownInternalName(internalName) + fun getPrice(internalName: String, useSellingPrice: Boolean): Double { + return getPrice(NEUInternalName.from(internalName), useSellingPrice) + } + + fun getItemStackOrNull(internalName: NEUInternalName) = ItemResolutionQuery(manager) + .withKnownInternalName(internalName.asString()) .resolveToItemStack()?.copy() - fun getItemStack(internalName: String, definite: Boolean = false): ItemStack = getItemStackOrNull(internalName) ?: run { - if (definite) { - Utils.showOutdatedRepoNotification() + fun getItemStackOrNull(internalName: String) = getItemStackOrNull(NEUInternalName.from(internalName)) + + fun getItemStack(internalName: String, definite: Boolean = false): ItemStack = + getItemStack(NEUInternalName.from(internalName), definite) + + fun getItemStack(internalName: NEUInternalName, definite: Boolean = false): ItemStack = + getItemStackOrNull(internalName) ?: run { + if (definite) { + Utils.showOutdatedRepoNotification() + } + CopyErrorCommand.logError( + IllegalStateException("Something went wrong!"), + "Encountered an error getting the item for §7$internalName§c. " + + "This may be because your NEU repo is outdated. Please ask in the SkyHanni " + + "Discord if this is the case" + ) + fallbackItem } - CopyErrorCommand.logError( - IllegalStateException("Something went wrong!"), - "Encountered an error getting the item for §7$internalName§c. " + - "This may be because your NEU repo is outdated. Please ask in the SkyHanni " + - "Discord if this is the case" - ) - fallbackItem - } fun isVanillaItem(item: ItemStack) = manager.auctionManager.isVanillaItem(item.getInternalName()) -- cgit