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 --- .../at/hannibal2/skyhanni/api/CollectionAPI.kt | 15 ++-- .../skyhanni/data/GardenCropMilestones.kt | 17 ++--- .../at/hannibal2/skyhanni/data/SkillExperience.kt | 28 ++++--- .../bazaar/BazaarCancelledBuyOrderClipboard.kt | 15 ++-- .../skyhanni/features/bazaar/BazaarOrderHelper.kt | 19 +++-- .../skyhanni/features/bingo/BingoCardDisplay.kt | 8 +- .../skyhanni/features/bingo/BingoNextStepHelper.kt | 86 +++++++++++----------- .../skyhanni/features/bingo/MinionCraftHelper.kt | 15 ++-- .../skyhanni/features/chat/PlayerDeathMessages.kt | 10 +-- .../skyhanni/features/dungeon/DungeonData.kt | 9 +-- .../skyhanni/features/dungeon/DungeonLevelColor.kt | 18 ++--- .../features/garden/GardenCropMilestoneFix.kt | 35 ++++----- .../skyhanni/features/garden/GardenLevelDisplay.kt | 49 ++++++------ .../features/garden/GardenNextJacobContest.kt | 29 ++++---- .../skyhanni/features/garden/GardenOptimalSpeed.kt | 8 +- .../garden/GardenTeleportPadCompactName.kt | 10 +-- .../features/garden/composter/ComposterDisplay.kt | 6 +- .../garden/composter/ComposterInventoryNumbers.kt | 59 +++++++-------- .../features/garden/composter/ComposterOverlay.kt | 8 +- .../garden/inventory/GardenInventoryNumbers.kt | 14 ++-- .../inventory/GardenTeleportPadInventoryNumber.kt | 14 ++-- .../garden/inventory/SkyMartCopperPrice.kt | 31 ++++---- .../garden/visitor/GardenVisitorFeatures.kt | 30 ++++---- .../features/garden/visitor/GardenVisitorTimer.kt | 14 ++-- .../inventory/ItemDisplayOverlayFeatures.kt | 20 +++-- .../skyhanni/features/inventory/StatsTuning.kt | 9 +-- .../skyhanni/features/minion/MinionFeatures.kt | 8 +- .../features/misc/CompactSplashPotionMessage.kt | 23 +++--- .../features/misc/NonGodPotEffectDisplay.kt | 8 +- .../features/misc/discordrpc/DiscordStatus.kt | 6 +- .../dailykuudra/DailyKuudraBossHelper.kt | 8 +- .../reputationhelper/dailyquest/QuestLoader.kt | 1 + .../miniboss/DailyMiniBossHelper.kt | 3 +- .../skyhanni/features/slayer/HideMobNames.kt | 10 +-- .../features/summonings/SummoningMobManager.kt | 7 +- .../skyhanni/mixins/hooks/GuiIngameHook.kt | 6 +- .../skyhanni/utils/MinecraftConsoleFilter.kt | 3 +- .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 12 ++- .../java/at/hannibal2/skyhanni/utils/TimeUtils.kt | 22 +++--- 39 files changed, 332 insertions(+), 361 deletions(-) (limited to 'src') 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 } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt index f4c2802f2..d07172609 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt @@ -5,12 +5,13 @@ import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class GardenCropMilestones { - private val cropPattern = "§7Harvest §f(.*) §7on .*".toPattern() - private val totalPattern = "§7Total: §a(.*)".toPattern() + private val cropPattern = "§7Harvest §f(?.*) §7on .*".toPattern() + private val totalPattern = "§7Total: §a(?.*)".toPattern() // Add when api support is there // @SubscribeEvent @@ -41,14 +42,12 @@ class GardenCropMilestones { for ((_, stack) in event.inventoryItems) { var crop: CropType? = null for (line in stack.getLore()) { - var matcher = cropPattern.matcher(line) - if (matcher.matches()) { - val name = matcher.group(1) - crop = CropType.getByNameOrNull(name) ?: continue + cropPattern.matchMatcher(line) { + val name = group("name") + crop = CropType.getByNameOrNull(name) } - matcher = totalPattern.matcher(line) - if (matcher.matches()) { - val amount = matcher.group(1).replace(",", "").toLong() + totalPattern.matchMatcher(line) { + val amount = group("name").replace(",", "").toLong() crop?.setCounter(amount) } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index c6d540ecb..11435ae96 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -9,13 +9,13 @@ 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.romanToDecimal +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SkillExperience { - - private val actionBarPattern = "(?:.*)§3\\+(?:.*) (.*) \\((.*)\\/(.*)\\)(?:.*)".toPattern() - private val inventoryPattern = "(?:.*) §e(.*)§6\\/(?:.*)".toPattern() + private val actionBarPattern = "(?:.*)§3\\+(?:.*) (?.*) \\((?.*)\\/(?.*)\\)(?:.*)".toPattern() + private val inventoryPattern = "(?:.*) §e(?.*)§6\\/(?:.*)".toPattern() @SubscribeEvent fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { @@ -38,15 +38,14 @@ class SkillExperience { fun onActionBar(event: LorenzActionBarEvent) { if (!LorenzUtils.inSkyBlock) return - val matcher = actionBarPattern.matcher(event.message) - if (!matcher.matches()) return - - val skill = matcher.group(1).lowercase() - val overflow = matcher.group(2).formatNumber() - val neededForNextLevel = matcher.group(3).formatNumber() - val nextLevel = getLevelForExpExactly(neededForNextLevel) - val baseExp = getExpForLevel(nextLevel - 1) - skillExp[skill] = baseExp + overflow + actionBarPattern.matchMatcher(event.message) { + val skill = group("skill").lowercase() + val overflow = group("overflow").formatNumber() + val neededForNextLevel = group("needed").formatNumber() + val nextLevel = getLevelForExpExactly(neededForNextLevel) + val baseExp = getExpForLevel(nextLevel - 1) + skillExp[skill] = baseExp + overflow + } } @SubscribeEvent @@ -70,9 +69,8 @@ class SkillExperience { val skillName = split[0].lowercase() val level = split[1].romanToDecimal() val baseExp = getExpForLevel(level) - val matcher = inventoryPattern.matcher(line) - if (matcher.matches()) { - val rawNumber = matcher.group(1) + inventoryPattern.matchMatcher(line) { + val rawNumber = group("number") val overflow = rawNumber.formatNumber() val experience = baseExp + overflow skillExp[skillName] = experience diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt index e3f50ad0b..3fce3b4d3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -6,15 +6,16 @@ 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.matchMatcher import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern class BazaarCancelledBuyOrderClipboard { - private val patternLastAmount = Pattern.compile("§a(.*)§7x") + private val patternLastAmount = Pattern.compile("§a(?.*)§7x") private val patternCancelledMessage = - "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(.*) coins §r§7from cancelling Buy Order!".toPattern() + "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?.*) coins §r§7from cancelling Buy Order!".toPattern() private var latestAmount: String? = null @@ -29,7 +30,7 @@ class BazaarCancelledBuyOrderClipboard { for (line in stack.getLore()) { val matcher = patternLastAmount.matcher(line) if (matcher.find()) { - latestAmount = matcher.group(1) + latestAmount = matcher.group("amount") } } } @@ -38,13 +39,9 @@ class BazaarCancelledBuyOrderClipboard { fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return - val message = event.message - - val matcher = patternCancelledMessage.matcher(message) - if (matcher.matches()) { + patternCancelledMessage.matchMatcher(event.message) { event.blockedReason = "bazaar cancelled buy order clipbaord" - val coins = matcher.group(1) - + val coins = group("coins") LorenzUtils.chat("§e[SkyHanni] Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)") latestAmount?.let { OSUtils.copyToClipboard(it.replace(",", "")) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt index 1e00d8c22..fa0dd8187 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name 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.matchMatcher import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraft.inventory.Slot @@ -43,13 +44,12 @@ class BazaarOrderHelper { if (slot.stack == null) continue val itemName = slot.stack.name ?: continue - val matcher = bazaarItemNamePattern.matcher(itemName) - if (!matcher.matches()) continue + bazaarItemNamePattern.matchMatcher(itemName) { + val buyOrSell = group("type").let { (it == "BUY") to (it == "SELL") } + if (buyOrSell.let { !it.first && !it.second }) return - val buyOrSell = matcher.group("type").let { (it == "BUY") to (it == "SELL") } - if (buyOrSell.let { !it.first && !it.second }) continue - - highlightItem(matcher.group("name"), slot, buyOrSell) + highlightItem(group("name"), slot, buyOrSell) + } } } @@ -62,14 +62,13 @@ class BazaarOrderHelper { val itemLore = slot.stack.getLore() for (line in itemLore) { - if (filledPattern.matcher(line).matches()) { + filledPattern.matchMatcher(line) { slot highlight LorenzColor.GREEN return } - val matcher = pricePattern.matcher(line) - if (matcher.matches()) { - val price = matcher.group("number").replace(",", "").toDouble() + pricePattern.matchMatcher(line) { + val price = group("number").replace(",", "").toDouble() if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) { slot highlight LorenzColor.GOLD return diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt index cc4faeaeb..229c3fc69 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt @@ -11,6 +11,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.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiChat @@ -27,7 +28,7 @@ class BingoCardDisplay { private var tick = 0 private var display = listOf() private val config get() = SkyHanniMod.feature.bingo - private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(.*)".toPattern() + private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?.*)".toPattern() init { update() @@ -179,9 +180,8 @@ class BingoCardDisplay { if (!LorenzUtils.isBingoProfile) return if (!config.cardDisplay) return - val matcher = goalCompletePattern.matcher(event.message) - if (matcher.matches()) { - val name = matcher.group(1) + goalCompletePattern.matchMatcher(event.message) { + val name = group("name") personalGoals.filter { it.displayName == name } .forEach { it.done = true diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt index 28faaf877..472fe1a81 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.bingo.nextstep.* import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -22,9 +23,9 @@ class BingoNextStepHelper { private val itemIslandRequired = mutableMapOf() private val itemRequired = mutableMapOf() private val islands = mutableMapOf() - private val collectionPattern = "Reach ([0-9]+(?:,\\d+)*) (.*) Collection\\.".toPattern() - private val crystalPattern = "Obtain a (\\w+) Crystal in the Crystal Hollows\\.".toPattern() - private val skillPattern = "Obtain level (.*) in the (.*) Skill.".toPattern() + private val collectionPattern = "Reach (?[0-9]+(?:,\\d+)*) (?.*) Collection\\.".toPattern() + private val crystalPattern = "Obtain a (?\\w+) Crystal in the Crystal Hollows\\.".toPattern() + private val skillPattern = "Obtain level (?.*) in the (?.*) Skill.".toPattern() companion object { private val finalSteps = mutableListOf() @@ -219,49 +220,52 @@ class BingoNextStepHelper { dirty = false for (goal in personalGoals) { - val description = goal.description.removeColor() + readDescription(goal.description.removeColor()) + } - val collectionMatcher = collectionPattern.matcher(description) - if (collectionMatcher.matches()) { - val amount = collectionMatcher.group(1).replace(",", "").toInt() - val name = collectionMatcher.group(2) + updateResult() + } - val collectionStep = CollectionStep(name, amount).apply { finalSteps.add(this) } - createItemIslandRequirement(name, collectionStep) - continue - } - if (description == "Craft an Emerald Ring.") { - CraftStep("Emerald Ring").apply { finalSteps.add(this) } requires ItemsStep( - "32x Enchanted Emerald", - "Emerald", - 160 * 32, - mapOf("Emerald" to 1, "Enchanted Emerald" to 160) - ).apply { this requires IslandType.DWARVEN_MINES.getStep() } - } - if (description == "Obtain a Mathematical Hoe Blueprint.") { - CraftStep("Mathematical Hoe Blueprint").apply { finalSteps.add(this) } requires ItemsStep( - "32x Jacob's Ticket", - "Jacob's Ticket", - 32, - mapOf("Jacob's Ticket" to 1) - ).apply { this requires IslandType.GARDEN.getStep() }.addItemRequirements() - } - val crystalMatcher = crystalPattern.matcher(description) - if (crystalMatcher.matches()) { - val crystal = crystalMatcher.group(1) - ChatMessageStep("Obtain a $crystal Crystal").apply { finalSteps.add(this) } requires IslandType.CRYSTAL_HOLLOWS.getStep() - } - val matcher = skillPattern.matcher(description) - if (matcher.matches()) { - val level = matcher.group(1).toInt() - val skillName = matcher.group(2) - SkillLevelStep(skillName, level).apply { finalSteps.add(this) } - } + private fun readDescription(description: String) { + collectionPattern.matchMatcher(description) { + val amount = group("amount").replace(",", "").toInt() + val name = group("name") + + val collectionStep = CollectionStep(name, amount).apply { finalSteps.add(this) } + createItemIslandRequirement(name, collectionStep) + return + } - println("No help for goal: '$description'") + if (description == "Craft an Emerald Ring.") { + CraftStep("Emerald Ring").apply { finalSteps.add(this) } requires ItemsStep( + "32x Enchanted Emerald", + "Emerald", + 160 * 32, + mapOf("Emerald" to 1, "Enchanted Emerald" to 160) + ).apply { this requires IslandType.DWARVEN_MINES.getStep() } } - updateResult() + if (description == "Obtain a Mathematical Hoe Blueprint.") { + CraftStep("Mathematical Hoe Blueprint").apply { finalSteps.add(this) } requires ItemsStep( + "32x Jacob's Ticket", + "Jacob's Ticket", + 32, + mapOf("Jacob's Ticket" to 1) + ).apply { this requires IslandType.GARDEN.getStep() }.addItemRequirements() + } + + crystalPattern.matchMatcher(description) { + val crystal = group("name") + ChatMessageStep("Obtain a $crystal Crystal").apply { finalSteps.add(this) } requires IslandType.CRYSTAL_HOLLOWS.getStep() + } + + skillPattern.matchMatcher(description) { + val level = group("level").toInt() + val skill = group("skill") + SkillLevelStep(skill, level).apply { finalSteps.add(this) } + } + + println("No help for goal: '$description'") } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt index 6fb885ff2..62077f08c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe @@ -21,7 +22,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent class MinionCraftHelper { - private var minionNamePattern = "(.*) Minion (.*)".toPattern() + private var minionNamePattern = "(?.*) Minion (?.*)".toPattern() private var tick = 0 private var display = listOf() private var hasMinionInInventory = false @@ -75,11 +76,11 @@ class MinionCraftHelper { ): MutableList { val newDisplay = mutableListOf() for ((minionName, minionId) in minions) { - val matcher = minionNamePattern.matcher(minionName) - if (!matcher.matches()) continue - val cleanName = matcher.group(1).removeColor() - val number = matcher.group(2).romanToDecimalIfNeeded() - addMinion(cleanName, number, minionId, otherItems, newDisplay) + minionNamePattern.matchMatcher(minionName) { + val cleanName = group("name").removeColor() + val number = group("number").romanToDecimalIfNeeded() + addMinion(cleanName, number, minionId, otherItems, newDisplay) + } } return newDisplay } @@ -273,7 +274,7 @@ class MinionCraftHelper { if (event.inventoryName != "Crafted Minions") return for ((_, b) in event.inventoryItems) { - val name = b.name?: continue + val name = b.name ?: continue if (!name.startsWith("§e")) continue val internalName = NEUItems.getInternalName("$name I") diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt index 1de8f09a2..2bfb0c9cf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.Minecraft @@ -18,7 +19,7 @@ class PlayerDeathMessages { private val lastTimePlayerSeen = mutableMapOf() //§c ☠ §r§7§r§bZeroHazel§r§7 was killed by §r§8§lAshfang§r§7§r§7. - private val pattern = "§c ☠ §r§7§r§.(.+)§r§7 (.+)".toPattern() + private val deathMessagePattern = "§c ☠ §r§7§r§.(?.+)§r§7 (?.+)".toPattern() @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { @@ -34,12 +35,11 @@ class PlayerDeathMessages { if (!LorenzUtils.inSkyBlock) return val message = event.message - val matcher = pattern.matcher(message) - if (matcher.matches()) { - val name = matcher.group(1) + deathMessagePattern.matchMatcher(message) { + val name = group("name") if (SkyHanniMod.feature.markedPlayers.highlightInChat && !LorenzUtils.inDungeons && !LorenzUtils.inKuudraFight) { if (MarkedPlayerManager.isMarkedPlayer(name)) { - val reason = matcher.group(2).removeColor() + val reason = group("reason").removeColor() LorenzUtils.chat(" §c☠ §e$name §7$reason") event.blockedReason = "marked_player_death" return diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt index 00db6d6b8..230e80dd2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt @@ -5,14 +5,14 @@ import at.hannibal2.skyhanni.events.DungeonBossRoomEnterEvent import at.hannibal2.skyhanni.events.DungeonEnterEvent import at.hannibal2.skyhanni.events.DungeonStartEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent class DungeonData { - - private val pattern = " §7⏣ §cThe Catacombs §7\\((.*)\\)".toPattern() + private val floorPattern = " §7⏣ §cThe Catacombs §7\\((?.*)\\)".toPattern() companion object { var dungeonFloor: String? = null @@ -66,9 +66,8 @@ class DungeonData { if (event.phase != TickEvent.Phase.START) return if (dungeonFloor == null) { for (line in ScoreboardData.sidebarLinesFormatted) { - val matcher = pattern.matcher(line) - if (matcher.matches()) { - val floor = matcher.group(1) + floorPattern.matchMatcher(line) { + val floor = group("floor") dungeonFloor = floor DungeonEnterEvent(floor).postAndCatch() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt index 91b347145..4f5ca684f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt @@ -4,12 +4,12 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class DungeonLevelColor { - - private val pattern = " §.(.*)§f: §e(.*)§b \\(§e(.*)§b\\)".toPattern() + private val pattern = " §.(?.*)§f: §e(?.*)§b \\(§e(?.*)§b\\)".toPattern() @SubscribeEvent fun onItemTooltip(event: ItemTooltipEvent) { @@ -24,14 +24,14 @@ class DungeonLevelColor { var index = 0 for (line in stack.getLore()) { index++ - val matcher = pattern.matcher(line) - if (!matcher.matches()) continue - val playerName = matcher.group(1) - val className = matcher.group(2) - val level = matcher.group(3).toInt() - val color = getColor(level) - event.toolTip[index] = " §b$playerName§f: §e$className $color$level" + pattern.matchMatcher(line) { + val playerName = group("playerName") + val className = group("className") + val level = group("level").toInt() + val color = getColor(level) + event.toolTip[index] = " §b$playerName§f: §e$className $color$level" + } } } 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 fb6453add..3539e40af 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern @@ -19,34 +20,28 @@ class GardenCropMilestoneFix { @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { - val matcher = levelUpPattern.matcher(event.message) - if (!matcher.matches()) return + levelUpPattern.matchMatcher(event.message) { + val cropName = group("crop") + val crop = CropType.getByNameOrNull(cropName) ?: return - val cropName = matcher.group("crop") - val crop = CropType.getByNameOrNull(cropName) - if (crop == null) { - LorenzUtils.debug("GardenCropMilestoneFix: crop is null: '$cropName'") - return - } + val tier = group("tier").romanToDecimalIfNeeded() - val tier = matcher.group("tier").romanToDecimalIfNeeded() - - val crops = GardenCropMilestones.getCropsForTier(tier) - changedValue(crop, crops, "level up chat message") + val crops = GardenCropMilestones.getCropsForTier(tier) + changedValue(crop, crops, "level up chat message") + } } @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { for (line in event.tabList) { - val matcher = tabListPattern.matcher(line) - if (!matcher.matches()) continue - - val tier = matcher.group("tier").toInt() - val percentage = matcher.group("percentage").toDouble() - val cropName = matcher.group("crop") + tabListPattern.matchMatcher(line) { + val tier = group("tier").toInt() + val percentage = group("percentage").toDouble() + val cropName = group("crop") - check(cropName, tier, percentage) - return + check(cropName, tier, percentage) + return + } } } 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 6c4abadb8..38b31b57e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -10,22 +10,23 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.roundToInt class GardenLevelDisplay { private val config get() = SkyHanniMod.feature.garden - private val expToNextLevelPattern = "(?:.*) §e(.*)§6\\/(?:.*)".toPattern() + private val expToNextLevelPattern = "(?:.*) §e(?.*)§6\\/(?:.*)".toPattern() private val overflowPattern = ".*§r §6(?.*) XP".toPattern() - private val namePattern = "Garden Level (.*)".toPattern() + private val namePattern = "Garden Level (?.*)".toPattern() private var gardenExp get() = SkyHanniMod.feature.hidden.gardenExp set(value) { SkyHanniMod.feature.hidden.gardenExp = value } private var display = "" - private var visitorRewardPattern = " {4}§r§8\\+§r§2(.*) §r§7Garden Experience".toPattern() + private var visitorRewardPattern = " {4}§r§8\\+§r§2(?.*) §r§7Garden Experience".toPattern() @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { @@ -36,10 +37,8 @@ class GardenLevelDisplay { fun onChatMessage(event: LorenzChatEvent) { if (!isEnabled()) return - val matcher = visitorRewardPattern.matcher(event.message) - if (matcher.matches()) { - val moreExp = matcher.group(1).toInt() - gardenExp += moreExp + visitorRewardPattern.matchMatcher(event.message) { + gardenExp += group("exp").toInt() update() } } @@ -50,28 +49,24 @@ class GardenLevelDisplay { if (event.inventoryName != "Desk") return val item = event.inventoryItems[4]!! - val name = item.name!!.removeColor() - val nameMatcher = namePattern.matcher(name) - if (!nameMatcher.matches()) return - val currentLevel = nameMatcher.group(1).romanToDecimalIfNeeded() - var nextLevelExp = 0 - for (line in item.getLore()) { - var matcher = expToNextLevelPattern.matcher(line) - if (matcher.matches()) { - nextLevelExp = matcher.group(1).replace(",", "").toDouble().roundToInt() - break - } - matcher = overflowPattern.matcher(line) - if (matcher.matches()) { - val overflow = matcher.group("overflow").replace(",", "").toDouble().roundToInt() - gardenExp = overflow - update() - return + namePattern.matchMatcher(item.name!!.removeColor()) { + val currentLevel = group("currentLevel").romanToDecimalIfNeeded() + var nextLevelExp = 0 + for (line in item.getLore()) { + expToNextLevelPattern.matchMatcher(line) { + nextLevelExp = group("nextLevelExp").replace(",", "").toDouble().roundToInt() + } + overflowPattern.matchMatcher(line) { + val overflow = group("overflow").replace(",", "").toDouble().roundToInt() + gardenExp = overflow + update() + return + } } + val expForLevel = getExpForLevel(currentLevel).toInt() + gardenExp = expForLevel + nextLevelExp + update() } - val expForLevel = getExpForLevel(currentLevel).toInt() - gardenExp = expForLevel + nextLevelExp - update() } private fun update() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index 7b9e52d14..c7ea644cb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -10,10 +10,12 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils import io.github.moulberry.notenoughupdates.util.SkyBlockTime import kotlinx.coroutines.launch +import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.opengl.Display @@ -31,9 +33,9 @@ class GardenNextJacobContest { private var tick = 0 private var contests = mutableMapOf() private var inCalendar = false - private val patternDay = "§aDay (.*)".toPattern() - private val patternMonth = "(.*), Year (.*)".toPattern() - private val patternCrop = "§e○ §7(.*)".toPattern() + private val patternDay = "§aDay (?.*)".toPattern() + private val patternMonth = "(?.*), Year (?.*)".toPattern() + private val patternCrop = "§e○ §7(?.*)".toPattern() private val maxContestsPerYear = 124 private val contestDuration = 1_000 * 60 * 20 @@ -92,17 +94,16 @@ class GardenNextJacobContest { if (lore[0] != "§7To Calendar and Events") return inCalendar = true - readCalendar(event) - } - private fun readCalendar(event: InventoryOpenEvent) { - val inventoryName = event.inventoryName + patternMonth.matchMatcher(event.inventoryName) { + val month = LorenzUtils.getSBMonthByName(group("month")) + val year = group("year").toInt() - val matcher = patternMonth.matcher(inventoryName) - if (!matcher.matches()) return - val month = LorenzUtils.getSBMonthByName(matcher.group(1)) - val year = matcher.group(2).toInt() + readCalendar(event.inventoryItems.values, year, month) + } + } + private fun readCalendar(items: MutableCollection, year: Int, month: Int) { if (contests.isNotEmpty()) { val contest = contests.values.first() val endTime = contest.endTime @@ -113,7 +114,7 @@ class GardenNextJacobContest { } } - for (item in event.inventoryItems.values) { + for (item in items) { val lore = item.getLore() if (!lore.any { it.contains("§6§eJacob's Farming Contest") }) continue @@ -121,13 +122,13 @@ class GardenNextJacobContest { val matcherDay = patternDay.matcher(name) if (!matcherDay.matches()) continue - val day = matcherDay.group(1).toInt() + val day = matcherDay.group("day").toInt() val startTime = SkyBlockTime(year, month, day).toMillis() val crops = mutableListOf() for (line in lore) { val matcherCrop = patternCrop.matcher(line) if (!matcherCrop.matches()) continue - crops.add(CropType.getByName(matcherCrop.group(1))) + crops.add(CropType.getByName(matcherCrop.group("crop"))) } val contest = FarmingContest(startTime + contestDuration, crops) contests[startTime] = contest diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt index d131aa91a..8653502d1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign @@ -22,7 +23,7 @@ class GardenOptimalSpeed { private val configCustomSpeed get() = config.optimalSpeedCustom private var currentSpeed = 100 private var optimalSpeed = -1 - private val currentSpeedPattern = " Speed: §r§f✦(.*)".toPattern() + private val currentSpeedPattern = " Speed: §r§f✦(?.*)".toPattern() private var lastWarnTime = 0L private var cropInHand: CropType? = null private var rancherOverlayList: List> = emptyList() @@ -30,9 +31,8 @@ class GardenOptimalSpeed { @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { for (line in event.tabList) { - val matcher = currentSpeedPattern.matcher(line) - if (matcher.matches()) { - currentSpeed = matcher.group(1).toInt() + currentSpeedPattern.matchMatcher(line) { + currentSpeed = group("speed").toInt() } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt index 4dcd73745..a23177f39 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.client.event.RenderLivingEvent @@ -8,7 +9,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class GardenTeleportPadCompactName { - private val patternName = "§.✦ §aWarp To (.*)".toPattern() + private val patternName = "§.✦ §aWarp To (?.*)".toPattern() private val patternNoName = "§.✦ §cNo Destination".toPattern() @SubscribeEvent(priority = EventPriority.HIGH) @@ -19,13 +20,12 @@ class GardenTeleportPadCompactName { val name = entity.name - if (patternNoName.matcher(name).matches()) { + patternNoName.matchMatcher(name) { event.isCanceled = true } - val matcher = patternName.matcher(name) - if (matcher.matches()) { - entity.customNameTag = matcher.group(1) + patternName.matchMatcher(name) { + entity.customNameTag = group("name") } } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt index ba9cbe9a1..763186a03 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration @@ -115,9 +116,8 @@ class ComposterDisplay { if (next) { if (line == "") break for (type in DataType.values()) { - val matcher = type.pattern.matcher(line) - if (matcher.matches()) { - newData[type] = matcher.group(1) + type.pattern.matchMatcher(line) { + newData[type] = group(1) } } } 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 aaccea8bd..b8a7a4fc3 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 @@ -6,12 +6,13 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI 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.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ComposterInventoryNumbers { - private val valuePattern = "(?:.*) §e(.*)§6\\/(.*)".toPattern() - private val compostsPattern = "§7§7Compost Available: §a(.*)".toPattern() + private val valuePattern = "(?:.*) §e(?.*)§6\\/(?.*)".toPattern() + private val compostsPattern = "§7§7Compost Available: §a(?.*)".toPattern() @SubscribeEvent fun onRenderItemTip(event: RenderInventoryItemTipEvent) { @@ -27,45 +28,41 @@ class ComposterInventoryNumbers { // Composts Available if (slotNumber == 22) { for (line in stack.getLore()) { - val matcher = compostsPattern.matcher(line) - if (!matcher.matches()) continue - - val total = matcher.group(1).replace(",", "").toInt() - if (total <= 64) continue - - event.offsetY = -2 - event.offsetX = -20 - event.stackTip = "§6${total.addSeparators()}" - return + compostsPattern.matchMatcher(line) { + val total = group("amount").replace(",", "").toInt() + 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()) { - val matcher = valuePattern.matcher(line) - if (!matcher.matches()) continue + valuePattern.matchMatcher(line) { + val having = group("having").removeColor().replace(",", "").toDouble().toInt() + val havingFormat = NumberUtil.format(having) + val total = group("total").removeColor() - val having = matcher.group(1).removeColor().replace(",", "").toDouble().toInt() - val havingFormat = NumberUtil.format(having) - val total = matcher.group(2).removeColor() + val color = if (slotNumber == 46) { + // Organic Matter + event.offsetY = -95 + event.offsetX = 5 + event.alignLeft = false + "§e" + } else { + // Fuel + event.offsetY = -76 + event.offsetX = -20 + "§a" + } - val color = if (slotNumber == 46) { - // Organic Matter - event.offsetY = -95 - event.offsetX = 5 - event.alignLeft = false - "§e" - } else { - // Fuel - event.offsetY = -76 - event.offsetX = -20 - "§a" + event.stackTip = "$color$havingFormat/$total" + return } - - event.stackTip = "$color$havingFormat/$total" - return } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 3e98858d8..3cdc0b699 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -120,10 +121,9 @@ class ComposterOverlay { for (upgrade in ComposterUpgrade.values()) { event.itemStack?.name?.let { if (it.contains(upgrade.displayName)) { - val matcher = ComposterUpgrade.regex.matcher(it) - matcher.matches() - val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0 - maxLevel = level == 25 + maxLevel = ComposterUpgrade.regex.matchMatcher(it) { + group("level")?.romanToDecimalIfNeeded() ?: 0 + } == 25 extraComposterUpgrade = upgrade update() return 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 0bf7be4da..c62b0c84d 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 @@ -8,13 +8,14 @@ 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.romanToDecimalIfNeeded +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class GardenInventoryNumbers { private val config get() = SkyHanniMod.feature.garden - private var patternTierProgress = "§7Progress to Tier (.*): §e(?:.*)".toPattern() - private var patternUpgradeTier = "§7Current Tier: §[ea](.*)§7/§a.*".toPattern() + private var patternTierProgress = "§7Progress to Tier (?.*): §e(?:.*)".toPattern() + private var patternUpgradeTier = "§7Current Tier: §[ea](?.*)§7/§a.*".toPattern() @SubscribeEvent fun onRenderItemTip(event: RenderItemTipEvent) { @@ -26,7 +27,7 @@ class GardenInventoryNumbers { event.stack.getLore() .map { patternTierProgress.matcher(it) } .filter { it.matches() } - .map { it.group(1).romanToDecimalIfNeeded() - 1 } + .map { it.group("tier").romanToDecimalIfNeeded() - 1 } .forEach { event.stackTip = "" + it } } @@ -36,7 +37,7 @@ class GardenInventoryNumbers { event.stack.getLore() .map { patternUpgradeTier.matcher(it) } .filter { it.matches() } - .map { it.group(1) } + .map { it.group("tier") } .forEach { event.stackTip = "" + it } } @@ -44,9 +45,8 @@ class GardenInventoryNumbers { if (!config.numberComposterUpgrades) return event.stack.name?.let { - val matcher = ComposterUpgrade.regex.matcher(it) - if (matcher.matches()) { - val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0 + ComposterUpgrade.regex.matchMatcher(it) { + val level = group("level")?.romanToDecimalIfNeeded() ?: 0 event.stackTip = "$level" } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt index dcb018404..5dc226327 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class GardenTeleportPadInventoryNumber { @@ -57,7 +58,7 @@ class GardenTeleportPadInventoryNumber { } private var inTeleportPad = false - private val pattern = "§.(.*) teleport pad".toPattern() + private val pattern = "§.(?.*) teleport pad".toPattern() @SubscribeEvent fun onInventoryOpen(event: InventoryOpenEvent) { @@ -71,13 +72,12 @@ class GardenTeleportPadInventoryNumber { if (!inTeleportPad) return val name = event.stack.name?.lowercase() ?: return - val matcher = pattern.matcher(name) - if (!matcher.matches()) return - val text = matcher.group(1) - numbers[text]?.let { - event.stackTip = "$it" - return + pattern.matchMatcher(name) { + val text = group("number") + numbers[text]?.let { + event.stackTip = "$it" + } } } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt index 3a83ff92b..f6138e079 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt @@ -13,10 +13,11 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SkyMartCopperPrice { - private val pattern = "§c(.*) Copper".toPattern() + private val pattern = "§c(?.*) Copper".toPattern() private var display = listOf>() private val config get() = SkyHanniMod.feature.garden @@ -33,25 +34,23 @@ class SkyMartCopperPrice { val table = mutableMapOf, Pair>() for (stack in event.inventoryItems.values) { for (line in stack.getLore()) { - val matcher = pattern.matcher(line) - if (!matcher.matches()) continue - val internalName = stack.getInternalName() val lowestBin = NEUItems.getPrice(internalName) if (lowestBin == -1.0) continue + pattern.matchMatcher(line) { + val amount = group("amount").replace(",", "").toInt() + val factor = lowestBin / amount + val perFormat = NumberUtil.format(factor) + val priceFormat = NumberUtil.format(lowestBin) + val amountFormat = NumberUtil.format(amount) - val amount = matcher.group(1).replace(",", "").toInt() - val factor = lowestBin / amount - val perFormat = NumberUtil.format(factor) - val priceFormat = NumberUtil.format(lowestBin) - val amountFormat = NumberUtil.format(amount) - - val name = stack.nameWithEnchantment!! - val advancedStats = if (config.skyMartCopperPriceAdvancedStats) { - " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)" - } else "" - val pair = Pair("$name§f:", "§6§l$perFormat$advancedStats") - table[pair] = Pair(factor, internalName) + val name = stack.nameWithEnchantment!! + val advancedStats = if (config.skyMartCopperPriceAdvancedStats) { + " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)" + } else "" + val pair = Pair("$name§f:", "§6§l$perFormat$advancedStats") + table[pair] = Pair(factor, internalName) + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 3823d80b8..6066608ec 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import io.github.moulberry.notenoughupdates.events.SlotClickEvent @@ -41,8 +42,8 @@ class GardenVisitorFeatures { private var lastClickedNpc = 0 private var tick = 0 private val newVisitorArrivedMessage = ".* §r§ehas arrived on your §r§bGarden§r§e!".toPattern() - private val copperPattern = " §8\\+§c(.*) Copper".toPattern() - private val gardenExperiencePattern = " §8\\+§2(.*) §7Garden Experience".toPattern() + private val copperPattern = " §8\\+§c(?.*) Copper".toPattern() + private val gardenExperiencePattern = " §8\\+§2(?.*) §7Garden Experience".toPattern() private val visitorChatMessagePattern = "§e\\[NPC] (§.)?(?.*)§f: §r§f.*".toPattern() private val config get() = SkyHanniMod.feature.garden private val logger = LorenzLogger("garden/visitors") @@ -335,17 +336,15 @@ class GardenVisitorFeatures { } if (config.visitorCopperPrice) { - val matcher = copperPattern.matcher(line) - if (matcher.matches()) { - val coppers = matcher.group(1).replace(",", "").toInt() + copperPattern.matchMatcher(line) { + val coppers = group("amount").replace(",", "").toInt() val pricePerCopper = NumberUtil.format((totalPrice / coppers).toInt()) list[i + itemsWithSpeedCounter] = "$line §7(price per §6$pricePerCopper§7)" } } if (config.visitorExperiencePrice) { - val matcher = gardenExperiencePattern.matcher(line) - if (matcher.matches()) { - val gardenExp = matcher.group(1).replace(",", "").toInt() + gardenExperiencePattern.matchMatcher(line) { + val gardenExp = group("amount").replace(",", "").toInt() val pricePerCopper = NumberUtil.format((totalPrice / gardenExp).toInt()) list[i + itemsWithSpeedCounter] = "$line §7(price per §6$pricePerCopper§7)" } @@ -480,16 +479,13 @@ class GardenVisitorFeatures { } } - private fun hideVisitorMessage(message: String): Boolean { - val matcher = visitorChatMessagePattern.matcher(message) - if (!matcher.matches()) return false + private fun hideVisitorMessage(message: String) = visitorChatMessagePattern.matchMatcher(message) { + val name = group("name") + if (name == "Spaceman") return false + if (name == "Beth") return false - val name = matcher.group("name") - if (name == "Spaceman") return false - if (name == "Beth") return false - - return visitors.keys.any { it.removeColor() == name } - } + return visitors.keys.any { it.removeColor() == name } + } ?: false private fun update() { checkVisitorsReady() 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 3e5ffa6bb..3535c31cd 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 @@ -8,14 +8,15 @@ import at.hannibal2.skyhanni.events.VisitorArrivalEvent import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.roundToLong class GardenVisitorTimer { - private val patternNextVisitor = " Next Visitor: §r§b(.*)".toPattern() - private val patternVisitors = "§b§lVisitors: §r§f\\((\\d)\\)".toPattern() + private val patternNextVisitor = " Next Visitor: §r§b(?