From 26ac6919de473490299142fee3e6fea98048d028 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 21 Feb 2023 00:46:47 +0100 Subject: Fixed bugs around item name renderer --- .../skyhanni/features/garden/GardenVisitorFeatures.kt | 19 ++++++------------- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index ade008853..5e3b0c3f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -25,7 +25,6 @@ import java.util.regex.Pattern class GardenVisitorFeatures { - private val pattern = Pattern.compile("(.*)§8x(.*)") private val visitors = mutableMapOf() private val display = mutableListOf() private var lastClickedNpc = 0 @@ -57,11 +56,8 @@ class GardenVisitorFeatures { if (line == "§7Items Required:") continue if (line.isEmpty()) break - val matcher = pattern.matcher(line) - if (!matcher.matches()) continue - - val itemName = matcher.group(1).trim() - val amount = matcher.group(2).toInt() + val (itemName, amount) = ItemUtils.readItemAmount(line) + if (itemName == null) continue visitor.items[itemName] = amount } @@ -108,18 +104,15 @@ class GardenVisitorFeatures { val line = l.substring(4) if (line == "") { if (amountDifferentItems > 1) { - val format = NumberUtil.format(totalPrice) - list[1] = list[1] + "$line §f(§6$format§f)" + val format = NumberUtil.format(totalPrice) + list[1] = list[1] + "$line §f(§6Total §6$format§f)" } break } if (i > 1) { - val matcher = pattern.matcher(line) - if (matcher.matches()) { - val itemName = matcher.group(1).trim() - val amount = matcher.group(2).toInt() - + val (itemName, amount) = ItemUtils.readItemAmount(line) + if (itemName != null) { val internalName = NEUItems.getInternalNameByName(itemName) val auctionManager = NotEnoughUpdates.INSTANCE.manager.auctionManager val lowestBin = auctionManager.getBazaarOrBin(internalName, false) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 87ae37da7..00ffdaefd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -9,6 +9,7 @@ import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.common.util.Constants import java.util.* +import java.util.regex.Pattern object ItemUtils { @@ -136,4 +137,18 @@ object ItemUtils { } fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName() == "SKYBLOCK_MENU" + + private val pattern = Pattern.compile("(?(?:[\\w-]+ ?)+)(?:§8x(?\\d+))?") + + fun readItemAmount(input: String): Pair { + var string = input.trim() + val color = string.substring(0, 2) + string = string.substring(2) + val matcher = pattern.matcher(string) + if (!matcher.matches()) return Pair(null, 0) + + val itemName = color + matcher.group("name").trim() + val amount = matcher.group("amount")?.replace(",", "")?.toInt() ?: 1 + return Pair(itemName, amount) + } } \ No newline at end of file -- cgit