diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-04-05 05:46:27 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 20:46:27 +0200 |
commit | 15db91ced38a8cc4c7c16565422fce5566c6057c (patch) | |
tree | 487804f98d4cad7316ea8b4f0f033fe530b2c4a5 /src/main/java | |
parent | 52afdbf62ef5c35403132696918b9cfcc8faffdb (diff) | |
download | skyhanni-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')
28 files changed, 219 insertions, 274 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() diff --git a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt index 54131f4bf..72210ad63 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeResets @@ -162,15 +163,11 @@ object BitsAPI { return } - for (line in cookieStack.getLore()) { - bitsAvailableMenuPattern.matchMatcher(line) { - val amount = group("toClaim").formatInt() - if (bitsToClaim != amount) { - bitsToClaim = amount - sendEvent() - } - - return + cookieStack.getLore().matchFirst(bitsAvailableMenuPattern) { + val amount = group("toClaim").formatInt() + if (bitsToClaim != amount) { + bitsToClaim = amount + sendEvent() } } return diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt index 5f61f0330..0038f4448 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt @@ -7,8 +7,8 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -25,11 +25,9 @@ object GardenCropMilestones { ) fun getCropTypeByLore(itemStack: ItemStack): CropType? { - for (line in itemStack.getLore()) { - cropPattern.matchMatcher(line) { - val name = group("name") - return CropType.getByNameOrNull(name) - } + itemStack.getLore().matchFirst(cropPattern) { + val name = group("name") + return CropType.getByNameOrNull(name) } return null } @@ -40,11 +38,9 @@ object GardenCropMilestones { for ((_, stack) in event.inventoryItems) { val crop = getCropTypeByLore(stack) ?: continue - for (line in stack.getLore()) { - totalPattern.matchMatcher(line) { - val amount = group("name").formatNumber() - crop.setCounter(amount) - } + stack.getLore().matchFirst(totalPattern) { + val amount = group("name").formatLong() + crop.setCounter(amount) } } CropMilestoneUpdateEvent().postAndCatch() diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 7fc50447f..3ea3a9008 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -72,7 +73,7 @@ class HypixelData { ) private val scoreboardVisitingAmoutPattern by patternGroup.pattern( "scoreboard.visiting.amount", - "\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§.\\/(?<maxamount>\\d+)\\)" + "\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§./(?<maxamount>\\d+)\\)" ) private val guestPattern by patternGroup.pattern( "guesting.scoreboard", @@ -127,19 +128,15 @@ class HypixelData { if (LorenzUtils.lastWorldSwitch.passedSince() < 1.seconds) return if (!TabListData.fullyLoaded) return - ScoreboardData.sidebarLinesFormatted.forEach { - serverIdScoreboardPattern.matchMatcher(it) { - val serverType = if (group("servertype") == "M") "mega" else "mini" - serverId = "$serverType${group("serverid")}" - return - } + ScoreboardData.sidebarLinesFormatted.matchFirst(serverIdScoreboardPattern) { + val serverType = if (group("servertype") == "M") "mega" else "mini" + serverId = "$serverType${group("serverid")}" + return } - TabListData.getTabList().forEach { - serverIdTablistPattern.matchMatcher(it) { - serverId = group("serverid") - return - } + TabListData.getTabList().matchFirst(serverIdTablistPattern) { + serverId = group("serverid") + return } ErrorManager.logErrorWithData( @@ -172,10 +169,8 @@ class HypixelData { } fun getMaxPlayersForCurrentServer(): Int { - for (line in ScoreboardData.sidebarLinesFormatted) { - scoreboardVisitingAmoutPattern.matchMatcher(line) { - return group("maxamount").toInt() - } + ScoreboardData.sidebarLinesFormatted.matchFirst(scoreboardVisitingAmoutPattern) { + return group("maxamount").toInt() } return if (serverId?.startsWith("mega") == true) 80 else 26 } @@ -255,16 +250,14 @@ class HypixelData { @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { - for (line in event.tabList) { - UtilsPatterns.tabListProfilePattern.matchMatcher(line) { - var newProfile = group("profile").lowercase() - // Hypixel shows the profile name reversed while in the Rift - if (RiftAPI.inRift()) newProfile = newProfile.reversed() - if (profileName == newProfile) return - profileName = newProfile - ProfileJoinEvent(newProfile).postAndCatch() - return - } + event.tabList.matchFirst(UtilsPatterns.tabListProfilePattern) { + var newProfile = group("profile").lowercase() + + // Hypixel shows the profile name reversed while in the Rift + if (RiftAPI.inRift()) newProfile = newProfile.reversed() + if (profileName == newProfile) return + profileName = newProfile + ProfileJoinEvent(newProfile).postAndCatch() } } @@ -320,15 +313,13 @@ class HypixelData { skyBlock = inSkyBlock } - private fun checkProfileName(): Boolean { - if (profileName.isEmpty()) { - val text = TabListData.getTabList().firstOrNull { it.contains("Profile:") } ?: return true - UtilsPatterns.tabListProfilePattern.matchMatcher(text) { - profileName = group("profile").lowercase() - ProfileJoinEvent(profileName).postAndCatch() - } + private fun checkProfileName() { + if (profileName.isNotEmpty()) return + + TabListData.getTabList().matchFirst(UtilsPatterns.tabListProfilePattern) { + profileName = group("profile").lowercase() + ProfileJoinEvent(profileName).postAndCatch() } - return false } private fun checkHypixel() { @@ -364,24 +355,22 @@ class HypixelData { } private fun checkIsland() { - var newIsland = "" + var foundIsland = "" TabListData.fullyLoaded = false - for (line in TabListData.getTabList()) { - islandNamePattern.matchMatcher(line) { - newIsland = group("island").removeColor() - TabListData.fullyLoaded = true - } + TabListData.getTabList().matchFirst(islandNamePattern) { + foundIsland = group("island").removeColor() + TabListData.fullyLoaded = true } // Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST) val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor()) - val islandType = getIslandType(newIsland, guesting) + val islandType = getIslandType(foundIsland, guesting) if (skyBlockIsland != islandType) { IslandChangeEvent(islandType, skyBlockIsland).postAndCatch() if (islandType == IslandType.UNKNOWN) { - ChatUtils.debug("Unknown island detected: '$newIsland'") - loggerIslandChange.log("Unknown: '$newIsland'") + ChatUtils.debug("Unknown island detected: '$foundIsland'") + loggerIslandChange.log("Unknown: '$foundIsland'") } else { loggerIslandChange.log(islandType.name) } diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt index 622683066..2e42bb002 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt @@ -12,7 +12,7 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.UtilsPatterns import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -51,11 +51,9 @@ object ProfileStorageData { fun onTabListUpdate(event: TabListUpdateEvent) { if (!LorenzUtils.inSkyBlock) return - for (line in event.tabList) { - UtilsPatterns.tabListProfilePattern.matchMatcher(line) { - noTabListTime = SimpleTimeMark.farPast() - return - } + event.tabList.matchFirst(UtilsPatterns.tabListProfilePattern) { + noTabListTime = SimpleTimeMark.farPast() + return } noTabListTime = SimpleTimeMark.now() diff --git a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt index f4266f800..ff8f4b5e4 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt @@ -1,12 +1,12 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.PurseChangeCause import at.hannibal2.skyhanni.events.PurseChangeEvent +import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.NumberUtil.million -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -32,13 +32,11 @@ object PurseAPI { } @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - for (line in ScoreboardData.sidebarLinesFormatted) { - val newPurse = coinsPattern.matchMatcher(line) { - group("coins").formatDouble() - } ?: continue + fun onScoreboardChange(event: ScoreboardChangeEvent) { + event.newList.matchFirst(coinsPattern) { + val newPurse = group("coins").formatDouble() val diff = newPurse - currentPurse - if (diff == 0.0) continue + if (diff == 0.0) return currentPurse = newPurse PurseChangeEvent(diff, getCause(diff)).postAndCatch() diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt index f0eca0fd9..1543aaf01 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData @@ -88,11 +89,8 @@ object DungeonAPI { } fun getTime(): String { - loop@ for (line in ScoreboardData.sidebarLinesFormatted) { - timePattern.matchMatcher(line.removeColor()) { - if (!matches()) continue@loop - return "${group("minutes") ?: "00"}:${group("seconds")}" // 03:14 - } + ScoreboardData.sidebarLinesFormatted.matchFirst(timePattern) { + return "${group("minutes") ?: "00"}:${group("seconds")}" // 03:14 } return "" } @@ -121,12 +119,10 @@ object DungeonAPI { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (dungeonFloor == null) { - for (line in ScoreboardData.sidebarLinesFormatted) { - floorPattern.matchMatcher(line) { - val floor = group("floor") - dungeonFloor = floor - DungeonEnterEvent(floor).postAndCatch() - } + ScoreboardData.sidebarLinesFormatted.matchFirst(floorPattern) { + val floor = group("floor") + dungeonFloor = floor + DungeonEnterEvent(floor).postAndCatch() } } if (dungeonFloor != null && playerClass == null) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt index 107156f2e..90e401fc5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt @@ -9,9 +9,9 @@ import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -34,13 +34,10 @@ object UniqueGiftCounter { val storage = storage ?: return - for (line in item.getLore()) { - giftedAmountPattern.matchMatcher(line) { - val amount = group("amount").formatNumber().toInt() - storage.amountGifted = amount - update() - return - } + item.getLore().matchFirst(giftedAmountPattern) { + val amount = group("amount").formatInt() + storage.amountGifted = amount + update() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt index 0fd475647..c2bfd586e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt @@ -27,7 +27,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SimpleTimeMark -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.TimeUtils import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -123,15 +123,13 @@ class CityProjectFeatures { val lore = item.getLore() val completed = lore.lastOrNull()?.let { completedPattern.matches(it) } ?: false if (completed) continue - for (line in lore) { - contributeAgainPattern.matchMatcher(line) { - val rawTime = group("time") - if (rawTime.contains("Soon!")) return@matchMatcher - val duration = TimeUtils.getDuration(rawTime) - val endTime = now + duration - if (endTime < nextTime) { - nextTime = endTime - } + lore.matchFirst(contributeAgainPattern) { + val rawTime = group("time") + if (!rawTime.contains("Soon!")) return@matchFirst + val duration = TimeUtils.getDuration(rawTime) + val endTime = now + duration + if (endTime < nextTime) { + nextTime = endTime } } if (item.name != "§eContribute this component!") continue diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt index 21e4175f1..23e9b8a5e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt @@ -327,6 +327,9 @@ object FarmingFortuneDisplay { reforgeFortune = 0.0 itemBaseFortune = 0.0 greenThumbFortune = 0.0 + + //TODO code cleanup + for (line in tool?.getLore()!!) { tooltipFortunePattern.matchMatcher(line) { displayedFortune = group(1)!!.toDouble() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt index c4f85ae45..f233ab97f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -78,15 +79,12 @@ class GardenCropMilestoneFix { @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { - for (line in event.tabList) { - tabListPattern.matchMatcher(line) { - val tier = group("tier").toInt() - val percentage = group("percentage").toDouble() - val cropName = group("crop") - - check(cropName, tier, percentage) - return - } + event.tabList.matchFirst(tabListPattern) { + val tier = group("tier").toInt() + val percentage = group("percentage").toDouble() + val cropName = group("crop") + + check(cropName, tier, percentage) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt index 40df08a57..54db1d71d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -87,7 +88,7 @@ class GardenLevelDisplay { "SkyBlock Menu" -> event.inventoryItems[10] ?: return else -> return } - gardenItemNamePattern.matchMatcher(item.name.removeColor()) {} ?: return + if (!gardenItemNamePattern.matches(item.name.removeColor())) return var nextLevelExp = 0L var currentLevel = 0 for (line in item.getLore()) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt index 5747032cf..c740812a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -37,41 +37,36 @@ class ComposterInventoryNumbers { // Composts Available if (slotNumber == 13) { - for (line in stack.getLore()) { - amountPattern.matchMatcher(line) { - val total = group("amount").formatInt() - event.offsetY = -2 - event.offsetX = -20 - event.stackTip = "§6${total.addSeparators()}" - return - } + stack.getLore().matchFirst(amountPattern) { + val total = group("amount").formatInt() + event.offsetY = -2 + event.offsetX = -20 + event.stackTip = "§6${total.addSeparators()}" + return } } // Organic Matter or Fuel if (slotNumber == 46 || slotNumber == 52) { - for (line in stack.getLore()) { - valuePattern.matchMatcher(line) { - val having = group("having").removeColor().formatInt() - val havingFormat = NumberUtil.format(having) - val total = group("total").removeColor() - - val color = if (slotNumber == 46) { - // Organic Matter - event.offsetY = -95 - event.offsetX = 5 - event.alignLeft = false - "§e" - } else { - // Fuel - event.offsetY = -41 - event.offsetX = -20 - "§a" - } + stack.getLore().matchFirst(valuePattern) { + val having = group("having").removeColor().formatInt() + val havingFormat = NumberUtil.format(having) + val total = group("total").removeColor() - event.stackTip = "$color$havingFormat/$total" - return + val color = if (slotNumber == 46) { + // Organic Matter + event.offsetY = -95 + event.offsetX = 5 + event.alignLeft = false + "§e" + } else { + // Fuel + event.offsetY = -41 + event.offsetX = -20 + "§a" } + + event.stackTip = "$color$havingFormat/$total" } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index 1e133f8e5..36a2779a2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import io.github.moulberry.notenoughupdates.util.SkyBlockTime @@ -127,16 +128,15 @@ object FarmingContestAPI { private fun createContest(time: Long, item: ItemStack): FarmingContest { val lore = item.getLore() - val crop = lore.firstNotNullOfOrNull { - cropPattern.matchMatcher(it) { CropType.getByName(group("crop")) } + + val crop = lore.matchFirst(cropPattern) { + CropType.getByName(group("crop")) } ?: error("Crop not found in lore!") val brackets = buildMap { for (bracket in ContestBracket.entries) { - val amount = lore.firstNotNullOfOrNull { - bracket.bracketPattern.matchMatcher(it) { - group("amount").formatInt() - } + val amount = lore.matchFirst(bracket.bracketPattern) { + group("amount").formatInt() } ?: continue put(bracket, amount) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt index edf3cb8a2..4d3cc3ae1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData @@ -106,10 +107,9 @@ object CaptureFarmingGear { } } } - for (line in TabListData.getTabList()) { - strengthPattern.matchMatcher(line) { - GardenAPI.storage?.fortune?.farmingStrength = group("strength").toInt() - } + + TabListData.getTabList().matchFirst(strengthPattern) { + GardenAPI.storage?.fortune?.farmingStrength = group("strength").toInt() } } @@ -189,10 +189,9 @@ object CaptureFarmingGear { for ((_, item) in items) { if (item.displayName.contains("Extra Farming Fortune")) { level = 0 - for (line in item.getLore()) { - anitaMenuPattern.matchMatcher(line) { - level = group("level").toInt() / 4 - } + + item.getLore().matchFirst(anitaMenuPattern) { + level = group("level").toInt() / 4 } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt index 5d76e6c57..86495cb24 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -39,11 +40,9 @@ class GardenInventoryNumbers { if (InventoryUtils.openInventoryName() == "Crop Upgrades") { if (!config.cropUpgrades) return - event.stack.getLore() - .map { upgradeTierPattern.matcher(it) } - .filter { it.matches() } - .map { it.group("tier") } - .forEach { event.stackTip = "" + it } + event.stack.getLore().matchFirst(upgradeTierPattern) { + event.stackTip = group("tier") + } } if (InventoryUtils.openInventoryName() == "Composter Upgrades") { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt index 8c218845a..f4df7f94e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt @@ -21,6 +21,7 @@ import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -154,10 +155,8 @@ object PestAPI { plot.pests = 0 plot.isPestCountInaccurate = false val item = event.inventoryItems[plot.inventorySlot] ?: continue - for (line in item.getLore()) { - pestInventoryPattern.matchMatcher(line) { - plot.pests = group("amount").toInt() - } + item.getLore().matchFirst(pestInventoryPattern) { + plot.pests = group("amount").toInt() } } updatePests() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index c35cb9266..205085c53 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -14,7 +14,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.TimeUtils @@ -82,23 +82,21 @@ class GardenVisitorTimer { var visitorInterval = visitorInterval ?: return var millis = visitorInterval var queueFull = false - loop@ for (line in TabListData.getTabList()) { - timePattern.matchMatcher(line) { - val timeInfo = group("info").removeColor() - if (timeInfo == "Not Unlocked!") { - display = "§cVisitors not unlocked!" - return - } - if (timeInfo == "Queue Full!") { - queueFull = true - break@loop - } + + TabListData.getTabList().matchFirst(timePattern) { + val timeInfo = group("info").removeColor() + if (timeInfo == "Not Unlocked!") { + display = "§cVisitors not unlocked!" + return + } + if (timeInfo == "Queue Full!") { + queueFull = true + } else { if (lastTimerValue != timeInfo) { lastTimerUpdate = SimpleTimeMark.now() lastTimerValue = timeInfo } millis = TimeUtils.getDuration(timeInfo) - break@loop } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt index 0f454b54d..9acb9c500 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt @@ -12,7 +12,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.RenderUtils.highlight -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest @@ -53,13 +53,11 @@ object AuctionsHighlighter { continue } if (config.highlightAuctionsUnderbid) { - for (line in lore) { - buyItNowPattern.matchMatcher(line) { - val coins = group("coins").formatLong() - stack.getInternalNameOrNull()?.getPriceOrNull()?.let { - if (coins > it) { - slot highlight LorenzColor.GOLD - } + lore.matchFirst(buyItNowPattern) { + val coins = group("coins").formatLong() + stack.getInternalNameOrNull()?.getPriceOrNull()?.let { + if (coins > it) { + slot highlight LorenzColor.GOLD } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt index 01d47e308..854063a07 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack @@ -50,14 +51,12 @@ class DojoRankDisplay { testNamePattern.matchMatcher(name) { val testColor = group("color") val testName = group("name") - for (line in stack.getLore()) { - testRankPattern.matchMatcher(line) { - val rank = group("rank") - val score = group("score").toInt() - val color = if (score in 0..99) "§c" else "§a" - totalScore += score - add("$testColor$testName§f: $rank §7($color${score.addSeparators()}§7)") - } + stack.getLore().matchFirst(testRankPattern) { + val rank = group("rank") + val score = group("score").toInt() + val color = if (score in 0..99) "§c" else "§a" + totalScore += score + add("$testColor$testName§f: $rank §7($color${score.addSeparators()}§7)") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt index 70e458f33..2a899117d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt @@ -46,6 +46,7 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEdition import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPetLevel import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getRanchersSpeed +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -200,14 +201,12 @@ object ItemDisplayOverlayFeatures { } if (LARVA_HOOK.isSelected() && internalName == "LARVA_HOOK".asInternalName()) { - for (line in lore) { - harvestPattern.matchMatcher(line) { - val amount = group("amount").toInt() - return when { - amount > 4 -> "§a$amount" - amount > 2 -> "§e$amount" - else -> "§c$amount" - } + lore.matchFirst(harvestPattern) { + val amount = group("amount").toInt() + return when { + amount > 4 -> "§a$amount" + amount > 2 -> "§e$amount" + else -> "§c$amount" } } } @@ -224,18 +223,16 @@ object ItemDisplayOverlayFeatures { } if (VACUUM_GARDEN.isSelected() && internalName in PestAPI.vacuumVariants && isOwnVacuum(lore)) { - for (line in lore) { - gardenVacuumPatterm.matchMatcher(line) { - val pests = group("amount").formatLong() - return if (config.vacuumBagCap) { - if (pests > 39) "§640+" else "$pests" - } else { - when { - pests < 40 -> "$pests" - pests < 1_000 -> "§6$pests" - pests < 100_000 -> "§c${pests / 1000}k" - else -> "§c${pests / 100_000 / 10.0}m" - } + lore.matchFirst(gardenVacuumPatterm) { + val pests = group("amount").formatLong() + return if (config.vacuumBagCap) { + if (pests > 39) "§640+" else "$pests" + } else { + when { + pests < 40 -> "$pests" + pests < 1_000 -> "§6$pests" + pests < 100_000 -> "§c${pests / 1000}k" + else -> "§c${pests / 100_000 / 10.0}m" } } } @@ -255,11 +252,9 @@ object ItemDisplayOverlayFeatures { } if (BINGO_GOAL_RANK.isSelected() && chestName == "Bingo Card" && lore.lastOrNull() == "§aGOAL REACHED") { - for (line in lore) { - bingoGoalRankPattern.matchMatcher(line) { - val rank = group("rank").formatLong() - if (rank < 10000) return "§6${NumberUtil.format(rank)}" - } + lore.matchFirst(bingoGoalRankPattern) { + val rank = group("rank").formatLong() + if (rank < 10000) return "§6${NumberUtil.format(rank)}" } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt index fdeccd4ba..9b2a51f4b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft @@ -42,21 +43,17 @@ class MaxPurseItems { for (item in Minecraft.getMinecraft().thePlayer.openContainer.inventory) { val name = item?.displayName ?: continue createOrderPattern.matchMatcher(name) { - for (info in item.getLore()) { - orderPattern.matchMatcher(info) { - // +0.1 because I expect people to use the gold nugget option - buyOrderPrice = group("coins").formatDouble() + 0.1 - // If we get to this point, we have the instant price because instant is earlier in the list of items - // So we can return - return - } + item.getLore().matchFirst(orderPattern) { + // +0.1 because I expect people to use the gold nugget option + buyOrderPrice = group("coins").formatDouble() + 0.1 + // If we get to this point, we have the instant price because instant is earlier in the list of items + // So we can return + return } } createInstantPattern.matchMatcher(name) { - for (info in item.getLore()) { - instantPattern.matchMatcher(info) { - instantBuyPrice = group("coins").formatDouble() - } + item.getLore().matchFirst(instantPattern) { + instantBuyPrice = group("coins").formatDouble() } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt index 2e6484f68..db57eb5ff 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt @@ -12,7 +12,7 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.createCommaSeparatedList -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -88,11 +88,9 @@ class StatsTuning { } private fun points(stack: ItemStack, event: RenderInventoryItemTipEvent) { - for (line in stack.getLore()) { - statPointsPattern.matchMatcher(line) { - val points = group("amount") - event.stackTip = points - } + stack.getLore().matchFirst(statPointsPattern) { + val points = group("amount") + event.stackTip = points } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt index 9a02fb1df..ba0d4278b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -8,7 +8,7 @@ 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.OSUtils -import at.hannibal2.skyhanni.utils.StringUtils.findMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -34,10 +34,8 @@ class BazaarCancelledBuyOrderClipboard { val stack = event.itemStack if (!stack.name.contains("Cancel Order")) return - for (line in stack.getLore()) { - lastAmountPattern.findMatcher(line) { - latestAmount = group("amount") - } + stack.getLore().matchFirst(lastAmountPattern) { + latestAmount = group("amount") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt index 76261b5fb..2f0311294 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -66,11 +67,9 @@ class CurrentPetDisplay { if (!PetAPI.isPetMenu(event.inventoryName)) return val lore = event.inventoryItems[4]?.getLore() ?: return - for (line in lore) { - inventorySelectedPetPattern.matchMatcher(line) { - val newPet = group("pet") - PetAPI.currentPet = if (newPet != "§cNone") newPet else "" - } + lore.matchFirst(inventorySelectedPetPattern) { + val newPet = group("pet") + PetAPI.currentPet = if (newPet != "§cNone") newPet else "" } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt index 7f9c4c9eb..acab50046 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt @@ -51,6 +51,7 @@ class ServerRestartTitle { "restartPattern" to restartingPattern.pattern(), ) } + return } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt index aacec8be7..43ca734fc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/AuctionHouseCopyUnderbidPrice.kt @@ -15,7 +15,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.OSUtils -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.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -61,15 +61,11 @@ class AuctionHouseCopyUnderbidPrice { if (!LorenzUtils.inSkyBlock) return if (!allowedInventoriesPattern.matches(InventoryUtils.openInventoryName())) return val stack = event.guiContainer.slotUnderMouse?.stack ?: return - val lore = stack.getLore() - for (line in lore) { - auctionPricePattern.matchMatcher(line) { - val underbid = group("coins").formatLong() - 1 - OSUtils.copyToClipboard("$underbid") - ChatUtils.chat("Copied ${underbid.addSeparators()} to clipboard.") - return - } + stack.getLore().matchFirst(auctionPricePattern) { + val underbid = group("coins").formatLong() - 1 + OSUtils.copyToClipboard("$underbid") + ChatUtils.chat("Copied ${underbid.addSeparators()} to clipboard.") } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index bcb185f60..5079aa7fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -99,6 +99,13 @@ object StringUtils { inline fun <T> Pattern.findMatcher(text: String, consumer: Matcher.() -> T) = matcher(text).let { if (it.find()) consumer(it) else null } + inline fun <T> List<String>.matchFirst(pattern: Pattern, consumer: Matcher.() -> T): T? { + for (line in this) { + pattern.matcher(line).let { if (it.matches()) return consumer(it) } + } + return null + } + private fun String.internalCleanPlayerName(): String { val split = trim().split(" ") return if (split.size > 1) { |