diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt | 19 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 15 |
2 files changed, 21 insertions, 13 deletions
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<String, Visitor>() private val display = mutableListOf<String>() 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("(?<name>(?:[\\w-]+ ?)+)(?:§8x(?<amount>\\d+))?") + + fun readItemAmount(input: String): Pair<String?, Int> { + 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 |