From bd34b28c14940a0d21a08057e944c7d55d91a1fd Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:34:56 +0200 Subject: Backend: Improved Scoreboard Line joining with special formatting codes (#1333) --- src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt index b2cb66ef0..a18dbf502 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent +import at.hannibal2.skyhanni.utils.StringUtils.matches import net.minecraft.client.Minecraft import net.minecraft.scoreboard.Score import net.minecraft.scoreboard.ScorePlayerTeam @@ -13,6 +14,9 @@ class ScoreboardData { companion object { + private val minecraftColorCodesPattern = "(?i)[0-9a-fkmolnr]".toPattern() + + // TODO USE SH-REPO private val splitIcons = listOf( "\uD83C\uDF6B", @@ -42,10 +46,14 @@ class ScoreboardData { // get last color code in start val lastColorIndex = start.lastIndexOf('ยง') val lastColor = when { - lastColorIndex != -1 && lastColorIndex + 1 < start.length && (start[lastColorIndex + 1] in '0'..'9' || start[lastColorIndex + 1] in 'a'..'f') -> start.substring( + lastColorIndex != -1 + && lastColorIndex + 1 < start.length + && (minecraftColorCodesPattern.matches( start[lastColorIndex + 1].toString())) + -> start.substring( lastColorIndex, lastColorIndex + 2 ) + else -> "" } -- cgit