diff options
author | Walker Selby <git@walkerselby.com> | 2023-11-22 12:31:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 13:31:37 +0100 |
commit | a66f85649faacb89d2b3afaa7b19bd508779af0d (patch) | |
tree | 1a2e6d84d5c2bc734dd49ba03c4db435a1b5630c /src/main/java/at/hannibal2 | |
parent | a6de55740355b3bc4d7c869626d22da5b3854416 (diff) | |
download | skyhanni-a66f85649faacb89d2b3afaa7b19bd508779af0d.tar.gz skyhanni-a66f85649faacb89d2b3afaa7b19bd508779af0d.tar.bz2 skyhanni-a66f85649faacb89d2b3afaa7b19bd508779af0d.zip |
Change logic to use Pattern instead of Regex and cleanup (#644)
DungeonCopilot cleanup #644
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCopilot.kt | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCopilot.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCopilot.kt index 8119535fd..f776eb155 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCopilot.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCopilot.kt @@ -11,12 +11,23 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class DungeonCopilot { + private val config get() = SkyHanniMod.feature.dungeon.dungeonCopilot + + private val countdownPattern = + "(.*) has started the dungeon countdown. The dungeon will begin in 1 minute.".toPattern() + private val keyPatternsList = listOf( + "§eA §r§a§r§[6c]§r§[8c](?<key>Wither|Blood) Key§r§e was picked up!".toPattern(), + "(.*) §r§ehas obtained §r§a§r§[6c]§r§[8c](?<key>Wither|Blood) Key§r§e!".toPattern() + ) + private val witherDoorPattern = "(.*) opened a §r§8§lWITHER §r§adoor!".toPattern() + private val bloodDoorPattern = "§cThe §r§c§lBLOOD DOOR§r§c has been opened!".toPattern() + private var nextStep = "" private var searchForKey = false @@ -24,60 +35,49 @@ class DungeonCopilot { fun onChatMessage(event: LorenzChatEvent) { if (!isEnabled()) return - val message = event.message + val blockReason = copilot(event.message) + if (blockReason != "") event.blockedReason = blockReason + } - if (message.matchRegex("(.*) has started the dungeon countdown. The dungeon will begin in 1 minute.")) { + private fun copilot(message: String): String { + countdownPattern.matchMatcher(message) { changeNextStep("Ready up") } - if (message.endsWith("§a is now ready!")) { - var name = LorenzUtils.getPlayerName() - if (message.contains(name)) { - changeNextStep("Wait for the dungeon to start!") - } + + if (message.endsWith("§a is now ready!") && message.contains(LorenzUtils.getPlayerName())) { + changeNextStep("Wait for the dungeon to start!") } + // Key Pickup var foundKeyOrDoor = false - - //key pickup - if (message.matchRegex("(.*) §r§ehas obtained §r§a§r§6§r§8Wither Key§r§e!") || - message == "§eA §r§a§r§6§r§8Wither Key§r§e was picked up!" - ) { - changeNextStep("Open Wither Door") - foundKeyOrDoor = true - + keyPatternsList.any { + it.matchMatcher(message) { + val key = group("key") + changeNextStep("Open $key Door") + foundKeyOrDoor = true + } != null } - if (message.matchRegex("(.*) §r§ehas obtained §r§a§r§c§r§cBlood Key§r§e!") || - message == "§eA §r§a§r§c§r§cBlood Key§r§e was picked up!" - ) { - changeNextStep("Open Blood Door") - foundKeyOrDoor = true - } - - if (message.matchRegex("(.*) opened a §r§8§lWITHER §r§adoor!")) { + witherDoorPattern.matchMatcher(message) { changeNextStep("Clear next room") searchForKey = true foundKeyOrDoor = true } - if (message == "§cThe §r§c§lBLOOD DOOR§r§c has been opened!") { + bloodDoorPattern.matchMatcher(message) { changeNextStep("Wait for Blood Room to fully spawn") foundKeyOrDoor = true } - if (foundKeyOrDoor && SkyHanniMod.feature.dungeon.messageFilter.keysAndDoors) { - event.blockedReason = "dungeon_keys_and_doors" - } - + if (foundKeyOrDoor && SkyHanniMod.feature.dungeon.messageFilter.keysAndDoors) return "dungeon_keys_and_doors" - if (message == "§c[BOSS] The Watcher§r§f: That will be enough for now.") { - changeNextStep("Clear Blood Room") - } + if (message == "§c[BOSS] The Watcher§r§f: That will be enough for now.") changeNextStep("Clear Blood Room") if (message == "§c[BOSS] The Watcher§r§f: You have proven yourself. You may pass.") { - event.blockedReason = "dungeon copilot" changeNextStep("Enter Boss Room") + return "dungeon_copilot" } + return "" } private fun changeNextStep(step: String) { @@ -126,14 +126,14 @@ class DungeonCopilot { } private fun isEnabled(): Boolean { - return LorenzUtils.inDungeons && SkyHanniMod.feature.dungeon.dungeonCopilot.enabled + return LorenzUtils.inDungeons && config.enabled } @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - SkyHanniMod.feature.dungeon.dungeonCopilot.pos.renderString(nextStep, posLabel = "Dungeon Copilot") + config.pos.renderString(nextStep, posLabel = "Dungeon Copilot") } @SubscribeEvent |