summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-07-28 10:03:57 +0200
committerGitHub <noreply@github.com>2024-07-28 10:03:57 +0200
commit40faf50e3f109d0028e67b6dd916ff79f2cb5604 (patch)
tree9d037dfe359a3e72b6546f24528f7517ce649129 /src/main/java/at/hannibal2/skyhanni/data
parentb2082d1d6008d943ffa2269cbdddb1b4fc72b8ce (diff)
downloadskyhanni-40faf50e3f109d0028e67b6dd916ff79f2cb5604.tar.gz
skyhanni-40faf50e3f109d0028e67b6dd916ff79f2cb5604.tar.bz2
skyhanni-40faf50e3f109d0028e67b6dd916ff79f2cb5604.zip
Fix: Double Color in ScoreboardData (#2264)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
index b24f08b04..0ade6a946 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
@@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.events.RawScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
-import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.StringUtils.lastColorCode
import net.minecraft.client.Minecraft
import net.minecraft.network.play.server.S3CPacketUpdateScore
import net.minecraft.network.play.server.S3EPacketTeams
@@ -26,30 +26,21 @@ object ScoreboardData {
private var dirty = false
- private val minecraftColorCodesPattern = "(?i)[0-9a-fkmolnr]".toPattern()
-
- fun formatLines(rawList: List<String>): List<String> {
- val list = mutableListOf<String>()
+ private fun formatLines(rawList: List<String>) = buildList {
for (line in rawList) {
val separator = splitIcons.find { line.contains(it) } ?: continue
val split = line.split(separator)
val start = split[0]
- var end = split[1]
- // get last color code in start
- val lastColorIndex = start.lastIndexOf('ยง')
- val lastColor = if (lastColorIndex != -1
- && lastColorIndex + 1 < start.length
- && (minecraftColorCodesPattern.matches(start[lastColorIndex + 1].toString()))
- ) start.substring(lastColorIndex, lastColorIndex + 2)
- else ""
-
- // remove first color code from end, when it is the same as the last color code in start
- end = end.removePrefix(lastColor)
-
- list.add(start + end)
- }
+ var end = if (split.size > 1) split[1] else ""
+
+ val lastColor = start.lastColorCode() ?: ""
- return list
+ if (end.startsWith(lastColor)) {
+ end = end.removePrefix(lastColor)
+ }
+
+ add(start + end)
+ }
}
@HandleEvent(receiveCancelled = true)