From bd6a0bb93ed6c0499cc3c5e044b7554481825bb5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 28 Apr 2023 20:43:18 +0200 Subject: REGEX --- src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/api') diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index 074120d66..08010207a 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -9,12 +9,13 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CollectionAPI { - private val counterPattern = "(?:.*) §e(.*)§6\\/(?:.*)".toPattern() - private val singleCounterPattern = "§7Total Collected: §e(.*)".toPattern() + private val counterPattern = "(?:.*) §e(?.*)§6\\/(?:.*)".toPattern() + private val singleCounterPattern = "§7Total Collected: §e(?.*)".toPattern() // private val hypixelApiHasWrongItems = listOf( // "WOOL", @@ -60,9 +61,8 @@ class CollectionAPI { if (inventoryName.endsWith(" Collection")) { val stack = event.inventoryItems[4] ?: return for (line in stack.getLore()) { - val matcher = singleCounterPattern.matcher(line) - if (matcher.matches()) { - val counter = matcher.group(1).replace(",", "").toLong() + singleCounterPattern.matchMatcher(line) { + val counter = group("amount").replace(",", "").toLong() val name = inventoryName.split(" ").dropLast(1).joinToString(" ") collectionValue[name] = counter } @@ -85,9 +85,8 @@ class CollectionAPI { } for (line in lore) { - val matcher = counterPattern.matcher(line) - if (matcher.matches()) { - val counter = matcher.group(1).replace(",", "").toLong() + counterPattern.matchMatcher(line) { + val counter = group("amount").replace(",", "").toLong() collectionValue[name] = counter } } -- cgit