aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-12-03 18:36:55 -0800
committerGitHub <noreply@github.com>2023-12-04 03:36:55 +0100
commit6d6f419317149753241b3e62d0db02581e18c544 (patch)
tree257c0822ff753e0e2a8bedfc840e1c047aab34e7 /src/main
parentafa56d7f528afd1dba6ee01afe3a4e838c09ad3f (diff)
downloadskyhanni-6d6f419317149753241b3e62d0db02581e18c544.tar.gz
skyhanni-6d6f419317149753241b3e62d0db02581e18c544.tar.bz2
skyhanni-6d6f419317149753241b3e62d0db02581e18c544.zip
Internal Change: Cleanup DungeonDeathCounter & Remove matchRegex (#645)
Nn longer creating new regex pattern elements each time. #645
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonDeathCounter.kt46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonDeathCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonDeathCounter.kt
index 36788e4b3..794736954 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonDeathCounter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonDeathCounter.kt
@@ -7,7 +7,7 @@ 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.matches
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class DungeonDeathCounter {
@@ -15,37 +15,39 @@ class DungeonDeathCounter {
private var display = ""
private var deaths = 0
- private fun isDeathMessage(message: String): Boolean = when {
- message.matchRegex("§c ☠ §r§7You were killed by (.*)§r§7 and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r§7(.*) was killed by (.*) and became a ghost§r§7.") -> true
+ private val deathPatternsList = listOf(
+ // TODO USE SH-REPO
+ "§c ☠ §r§7You were killed by (.*)§r§7 and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r§7(.*) was killed by (.*) and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You were crushed and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r§7§r(.*)§r§7 was crushed and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You were crushed and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r§7§r(.*)§r§7 was crushed and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You died to a trap and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r(.*)§r§7 died to a trap and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You died to a trap and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r(.*)§r§7 died to a trap and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You burnt to death and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r(.*)§r§7 burnt to death and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You burnt to death and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r(.*)§r§7 burnt to death and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You died and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r(.*)§r§7 died and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You died and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r(.*)§r§7 died and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You suffocated and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r§7§r(.*)§r§7 suffocated and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You suffocated and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r§7§r(.*)§r§7 suffocated and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You died to a mob and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r(.*)§7 died to a mob and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You died to a mob and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r(.*)§7 died to a mob and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7You fell into a deep hole and became a ghost§r§7.") -> true
- message.matchRegex("§c ☠ §r(.*)§r§7 fell into a deep hole and became a ghost§r§7.") -> true
+ "§c ☠ §r§7You fell into a deep hole and became a ghost§r§7.".toPattern(),
+ "§c ☠ §r(.*)§r§7 fell into a deep hole and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§(.*)§r§7 disconnected from the Dungeon and became a ghost§r§7.") -> true
+ "§c ☠ §r§(.*)§r§7 disconnected from the Dungeon and became a ghost§r§7.".toPattern(),
- message.matchRegex("§c ☠ §r§7(.*)§r§7 fell to their death with help from §r(.*)§r§7 and became a ghost§r§7.") -> true
+ "§c ☠ §r§7(.*)§r§7 fell to their death with help from §r(.*)§r§7 and became a ghost§r§7.".toPattern()
+ )
- else -> false
- }
+ private fun isDeathMessage(message: String): Boolean =
+ deathPatternsList.any { it.matches(message) }
@SubscribeEvent(receiveCanceled = true)
fun onChatPacket(event: LorenzChatEvent) {