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 /src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | |
parent | cc5ccde4c666589980eb717d2143e24ba0fde86d (diff) | |
download | skyhanni-07db6cd5fa6152c7252716c0fa128597955ed0d2.tar.gz skyhanni-07db6cd5fa6152c7252716c0fa128597955ed0d2.tar.bz2 skyhanni-07db6cd5fa6152c7252716c0fa128597955ed0d2.zip |
Using caches and jack o lantern fix.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 11 |
1 files changed, 9 insertions, 2 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 |