From 0c183cfcc5df4c4913061e5249feaf75b93d3753 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sat, 28 Oct 2023 18:24:33 +0100 Subject: [PATCH 1/3] Refactor isMilestoneMessage to use patterns and a list Move patterns to list Change logic to use list --- .../dungeon/DungeonMilestonesDisplay.kt | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt index 69b06c0ce76f..e63935313021 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt @@ -7,26 +7,29 @@ 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.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer class DungeonMilestonesDisplay { companion object { + + // TODO USE SH-REPO + private val milestonePatternList = listOf( + "§e§l(.*) Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)".toPattern(), + "§e§lArcher Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Ranged Damage so far! §r§a(.*)".toPattern(), + "§e§lHealer Milestone §r§e.§r§7: You have healed §r§a(.*)§r§7 Damage so far! §r§a(.*)".toPattern(), + "§e§lTank Milestone §r§e.§r§7: You have tanked and dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)s".toPattern() + ) + private var display = "" var color = "" var currentMilestone = 0 var timeReached = 0L - fun isMilestoneMessage(message: String): Boolean = when { - message.matchRegex("§e§l(.*) Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)") -> true - message.matchRegex("§e§lArcher Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Ranged Damage so far! §r§a(.*)") -> true - message.matchRegex("§e§lHealer Milestone §r§e.§r§7: You have healed §r§a(.*)§r§7 Damage so far! §r§a(.*)") -> true - message.matchRegex("§e§lTank Milestone §r§e.§r§7: You have tanked and dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)s") -> true - - else -> false - } + fun isMilestoneMessage(message: String): Boolean = + milestonePatternList.any { it.matchMatcher(message) { } != null } } init { @@ -83,10 +86,13 @@ class DungeonMilestonesDisplay { fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - SkyHanniMod.feature.dungeon.showMileStonesDisplayPos.renderString(color + display, posLabel = "Dungeon Milestone") + SkyHanniMod.feature.dungeon.showMileStonesDisplayPos.renderString( + color + display, + posLabel = "Dungeon Milestone" + ) } private fun isEnabled(): Boolean { return LorenzUtils.inDungeons && SkyHanniMod.feature.dungeon.showMilestonesDisplay } -} \ No newline at end of file +} From 08d2727c66370bf977e644972e62822a4a14faae Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sat, 2 Dec 2023 18:16:09 +0000 Subject: [PATCH 2/3] Update usage to appropriate function Signed-off-by: Walker Selby --- .../java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt | 4 ++-- .../skyhanni/features/dungeon/DungeonMilestonesDisplay.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt index 33509b606bb8..226f5fb83179 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpaceAndResets import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -417,7 +417,7 @@ class ChatFilter { * @see messagesStartsWithMap */ private fun String.isPresent(key: String) = this in (messagesMap[key] ?: emptyList()) || - (patternsMap[key] ?: emptyList()).any { it.matchMatcher(this) { } != null } || + (patternsMap[key] ?: emptyList()).any { it.matches(this) } || (messagesContainsMap[key] ?: emptyList()).any { this.contains(it) } || (messagesStartsWithMap[key] ?: emptyList()).any { this.startsWith(it) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt index 4fc2d56fa4f4..0ee69f36fb36 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.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.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer @@ -30,7 +30,7 @@ class DungeonMilestonesDisplay { var timeReached = 0L fun isMilestoneMessage(message: String): Boolean = - milestonePatternList.any { it.matchMatcher(message) { } != null } + milestonePatternList.any { it.matches(message) } } init { From 6d1a6360d839a3cf16cd448269f28bae392cfb67 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 4 Dec 2023 04:04:13 +0100 Subject: [PATCH 3/3] code cleanup --- .../skyhanni/features/dungeon/DungeonMilestonesDisplay.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt index 0ee69f36fb36..fc5462901c2c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt @@ -29,14 +29,14 @@ class DungeonMilestonesDisplay { var currentMilestone = 0 var timeReached = 0L - fun isMilestoneMessage(message: String): Boolean = - milestonePatternList.any { it.matches(message) } + fun isMilestoneMessage(message: String): Boolean = milestonePatternList.any { it.matches(message) } } init { fixedRateTimer(name = "skyhanni-dungeon-milestone-display", period = 200) { - if (!isEnabled()) return@fixedRateTimer - checkVisibility() + if (isEnabled()) { + checkVisibility() + } } }