From d376ff6ccac98716de41b5d8d77248254e002d11 Mon Sep 17 00:00:00 2001 From: Helfull Date: Sat, 14 Oct 2023 15:58:35 +0200 Subject: Internal Changes: add support for compacted numbers parsing (#555) add support for compacted numbers parsing #555 --- src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 06e7108d9..c81841268 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import com.google.gson.GsonBuilder import com.google.gson.JsonObject import net.minecraft.client.Minecraft @@ -18,6 +19,7 @@ import net.minecraft.nbt.NBTTagList import net.minecraft.nbt.NBTTagString import net.minecraftforge.common.util.Constants import java.util.LinkedList +import java.util.regex.Matcher import kotlin.time.Duration.Companion.seconds object ItemUtils { @@ -239,7 +241,7 @@ object ItemUtils { fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName_old() == "SKYBLOCK_MENU" - private val patternInFront = "(?: *§8(?[\\d,]+)x )?(?.*)".toPattern() + private val patternInFront = "(?: *§8(\\+§[\\d\\w])?(?[\\d\\.km,]+)(x )?)?(?.*)".toPattern() private val patternBehind = "(?(?:['\\w-]+ ?)+)(?:§8x(?[\\d,]+))?".toPattern() private val itemAmountCache = mutableMapOf>() @@ -258,10 +260,7 @@ object ItemUtils { if (matcher.matches()) { val itemName = matcher.group("name") if (!itemName.contains("§8x")) { - val amount = matcher.group("amount")?.replace(",", "")?.toInt() ?: 1 - val pair = Pair(itemName.trim(), amount) - itemAmountCache[input] = pair - return pair + return makePair(input, itemName.trim(), matcher) } } @@ -277,7 +276,12 @@ object ItemUtils { } val itemName = color + matcher.group("name").trim() - val amount = matcher.group("amount")?.replace(",", "")?.toInt() ?: 1 + return makePair(input, itemName, matcher) + } + + private fun makePair(input: String, itemName: String, matcher: Matcher): Pair { + val matcherAmount = matcher.group("amount") + val amount = matcherAmount?.formatNumber()?.toInt() ?: 1; val pair = Pair(itemName, amount) itemAmountCache[input] = pair return pair -- cgit