From 6a46a2fcd6495293a3357117b1d53eb8873f047d Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Sat, 25 May 2024 09:40:09 +0200 Subject: Fix: Dungeon Rank Tablist Color (#1878) --- .../features/dungeon/DungeonRankTabListColor.kt | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt index 3e0a719fa..b12b99ca0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt @@ -2,31 +2,43 @@ package at.hannibal2.skyhanni.features.dungeon import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.TabListLineRenderEvent -import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal +import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.stripHypixelMessage +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class DungeonRankTabListColor { private val config get() = SkyHanniMod.feature.dungeon.tabList - private val pattern = "§r(?.*) §r§f\\(§r§d(?.*) (?.*)§r§f\\)§r".toPattern() + private val patternGroup = RepoPattern.group("dungeon.tablist") + + /** + * REGEX-TEST: §8[§r§9319§r§8] §r§bEmpa_ §r§7α §r§f(§r§dMage XXXIV§r§f) + */ + private val pattern by patternGroup.pattern( + "rank", + "^(?:§.)*(?\\[(?:§.)*\\d+(?:§.)*]) (?(?:§.)*\\[(?:§.)*[^]]+(?:§.)*])? ?(?\\S+) (?[^(]*)\\((?:§.)*(?\\S+) (?[CLXVI]+)(?:§.)*\\)(?:§.)*$" + ) @SubscribeEvent fun onTabListText(event: TabListLineRenderEvent) { if (!isEnabled()) return - pattern.matchMatcher(event.text) { + pattern.matchMatcher(event.text.stripHypixelMessage()) { + val sbLevel = group("sbLevel") + val rank = groupOrNull("rank") ?: "" val playerName = group("playerName") - val split = playerName.split(" ") - val sbLevel = split[0] - val cleanName = split[1].cleanPlayerName(displayName = true) - + //val symbols = group("symbols") val className = group("className") - val level = group("classLevel").romanToDecimal() - val color = DungeonAPI.getColor(level) + val classLevel = group("classLevel") + + val cleanName = playerName.cleanPlayerName(true) + val color = DungeonAPI.getColor(classLevel.romanToDecimalIfNecessary()) - event.text = "$sbLevel $cleanName §7(§e$className $color$level§7)" + event.text = "§8$sbLevel $rank$cleanName §f(§d$className $color$classLevel§f)" } } -- cgit