From 07db6cd5fa6152c7252716c0fa128597955ed0d2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 25 Feb 2023 15:52:25 +0100 Subject: Using caches and jack o lantern fix. --- src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt') 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("(?(?:[\\w-]+ ?)+)(?:§8x(?\\d+))?") + private val pattern = Pattern.compile("(?(?:['\\w-]+ ?)+)(?:§8x(?\\d+))?") + + private val itemAmountCache = mutableMapOf>() fun readItemAmount(input: String): Pair { + 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 -- cgit