diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-25 15:52:25 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-25 15:52:25 +0100 |
commit | 07db6cd5fa6152c7252716c0fa128597955ed0d2 (patch) | |
tree | a19171e702263da534d8baf0643c784f2c530136 | |
parent | cc5ccde4c666589980eb717d2143e24ba0fde86d (diff) | |
download | skyhanni-07db6cd5fa6152c7252716c0fa128597955ed0d2.tar.gz skyhanni-07db6cd5fa6152c7252716c0fa128597955ed0d2.tar.bz2 skyhanni-07db6cd5fa6152c7252716c0fa128597955ed0d2.zip |
Using caches and jack o lantern fix.
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 11 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 12 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index c22a72971..919b88969 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -137,9 +137,14 @@ object ItemUtils { fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName() == "SKYBLOCK_MENU" - private val pattern = Pattern.compile("(?<name>(?:[\\w-]+ ?)+)(?:§8x(?<amount>\\d+))?") + private val pattern = Pattern.compile("(?<name>(?:['\\w-]+ ?)+)(?:§8x(?<amount>\\d+))?") + + private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>() fun readItemAmount(input: String): Pair<String?, Int> { + if (itemAmountCache.containsKey(input)) { + return itemAmountCache[input]!! + } var string = input.trim() val color = string.substring(0, 2) string = string.substring(2) @@ -148,6 +153,8 @@ object ItemUtils { val itemName = color + matcher.group("name").trim() val amount = matcher.group("amount")?.replace(",", "")?.toInt() ?: 1 - return Pair(itemName, amount) + val pair = Pair(itemName, amount) + itemAmountCache[input] = pair + return pair } }
\ 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 0f7a15618..4e285e112 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -12,9 +12,19 @@ import net.minecraft.item.ItemStack object NEUItems { val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager private val itemCache = mutableMapOf<String, ItemStack>() + private val itemNameCache = mutableMapOf<String, String>() // item name -> internal name fun getInternalName(itemName: String): String { - return ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) + if (itemNameCache.containsKey(itemName)) { + return itemNameCache[itemName]!! + } + // We love hypixel naming moments + val name = if (itemName.contains("Jack o' Lantern")) { + itemName.replace("Jack o' Lantern", "Jack o'Lantern") + } else itemName + val internalName = ItemResolutionQuery.findInternalNameByDisplayName(name, false) + itemNameCache[itemName] = internalName + return internalName } fun getInternalName(itemStack: ItemStack): String { |