diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-28 20:43:18 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-28 20:43:29 +0200 |
commit | bd6a0bb93ed6c0499cc3c5e044b7554481825bb5 (patch) | |
tree | be2eea214952108ae8acd658f4646403129a3e28 /src/main/java/at/hannibal2/skyhanni/features/bingo | |
parent | 9df04ac5aaa5e9897324af306dc73b8b1e67f600 (diff) | |
download | skyhanni-bd6a0bb93ed6c0499cc3c5e044b7554481825bb5.tar.gz skyhanni-bd6a0bb93ed6c0499cc3c5e044b7554481825bb5.tar.bz2 skyhanni-bd6a0bb93ed6c0499cc3c5e044b7554481825bb5.zip |
REGEX
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bingo')
3 files changed, 57 insertions, 52 deletions
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") |