diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
32 files changed, 284 insertions, 306 deletions
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(?<amount>.*)§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>.*) 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<String>() 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(?<name>.*)".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<String, IslandVisitStep>() private val itemRequired = mutableMapOf<String, NextStep>() private val islands = mutableMapOf<IslandType, IslandVisitStep>() - 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 (?<amount>[0-9]+(?:,\\d+)*) (?<name>.*) Collection\\.".toPattern() + private val crystalPattern = "Obtain a (?<name>\\w+) Crystal in the Crystal Hollows\\.".toPattern() + private val skillPattern = "Obtain level (?<level>.*) in the (?<skill>.*) Skill.".toPattern() companion object { private val finalSteps = mutableListOf<NextStep>() @@ -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 = "(?<name>.*) Minion (?<number>.*)".toPattern() private var tick = 0 private var display = listOf<String>() private var hasMinionInInventory = false @@ -75,11 +76,11 @@ class MinionCraftHelper { ): MutableList<String> { val newDisplay = mutableListOf<String>() 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<String, Long>() //§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§.(?<name>.+)§r§7 (?<reason>.+)".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\\((?<floor>.*)\\)".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 = " §.(?<playerName>.*)§f: §e(?<className>.*)§b \\(§e(?<level>.*)§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(?<nextLevelExp>.*)§6\\/(?:.*)".toPattern() private val overflowPattern = ".*§r §6(?<overflow>.*) XP".toPattern() - private val namePattern = "Garden Level (.*)".toPattern() + private val namePattern = "Garden Level (?<currentLevel>.*)".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(?<exp>.*) §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()< |
