aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/api
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-04-05 05:46:27 +1100
committerGitHub <noreply@github.com>2024-04-04 20:46:27 +0200
commit15db91ced38a8cc4c7c16565422fce5566c6057c (patch)
tree487804f98d4cad7316ea8b4f0f033fe530b2c4a5 /src/main/java/at/hannibal2/skyhanni/api
parent52afdbf62ef5c35403132696918b9cfcc8faffdb (diff)
downloadskyhanni-15db91ced38a8cc4c7c16565422fce5566c6057c.tar.gz
skyhanni-15db91ced38a8cc4c7c16565422fce5566c6057c.tar.bz2
skyhanni-15db91ced38a8cc4c7c16565422fce5566c6057c.zip
Backend: matchFirst function for lists of strings (#1353)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/api')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index 75941dcd6..c24e9b1cc 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -13,7 +13,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matchFirst
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
@@ -51,13 +51,11 @@ object CollectionAPI {
val inventoryName = event.inventoryName
if (inventoryName.endsWith(" Collection")) {
val stack = event.inventoryItems[4] ?: return
- loop@ for (line in stack.getLore()) {
- singleCounterPattern.matchMatcher(line) {
- val counter = group("amount").formatLong()
- val name = inventoryName.split(" ").dropLast(1).joinToString(" ")
- val internalName = incorrectCollectionNames[name] ?: NEUInternalName.fromItemName(name)
- collectionValue[internalName] = counter
- }
+ stack.getLore().matchFirst(singleCounterPattern) {
+ val counter = group("amount").formatLong()
+ val name = inventoryName.split(" ").dropLast(1).joinToString(" ")
+ val internalName = incorrectCollectionNames[name] ?: NEUInternalName.fromItemName(name)
+ collectionValue[internalName] = counter
}
CollectionUpdateEvent().postAndCatch()
}
@@ -77,11 +75,9 @@ object CollectionAPI {
}
val internalName = incorrectCollectionNames[name] ?: NEUInternalName.fromItemName(name)
- loop@ for (line in lore) {
- counterPattern.matchMatcher(line) {
- val counter = group("amount").formatLong()
- collectionValue[internalName] = counter
- }
+ lore.matchFirst(counterPattern) {
+ val counter = group("amount").formatLong()
+ collectionValue[internalName] = counter
}
}
CollectionUpdateEvent().postAndCatch()