diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-28 20:43:18 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-28 20:43:29 +0200 |
commit | bd6a0bb93ed6c0499cc3c5e044b7554481825bb5 (patch) | |
tree | be2eea214952108ae8acd658f4646403129a3e28 /src/main/java/at/hannibal2/skyhanni/api | |
parent | 9df04ac5aaa5e9897324af306dc73b8b1e67f600 (diff) | |
download | skyhanni-bd6a0bb93ed6c0499cc3c5e044b7554481825bb5.tar.gz skyhanni-bd6a0bb93ed6c0499cc3c5e044b7554481825bb5.tar.bz2 skyhanni-bd6a0bb93ed6c0499cc3c5e044b7554481825bb5.zip |
REGEX
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/api')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt | 15 |
1 files changed, 7 insertions, 8 deletions
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(?<amount>.*)§6\\/(?:.*)".toPattern() + private val singleCounterPattern = "§7Total Collected: §e(?<amount>.*)".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 } } |