From b0a8f0a0c712b606e20f0c9b36d65b4c8ce70c35 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:19:53 +0200 Subject: Fix: ScoreboardData and splitting (#2345) --- src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt index 0ade6a946..a403db112 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt @@ -35,8 +35,14 @@ object ScoreboardData { val lastColor = start.lastColorCode() ?: "" - if (end.startsWith(lastColor)) { - end = end.removePrefix(lastColor) + // Determine the longest prefix of "end" that matches any suffix of "lastColor" + val colorSuffixes = generateSequence(lastColor) { it.dropLast(2) } + .takeWhile { it.isNotEmpty() } + .toList() + + val matchingPrefix = colorSuffixes.find { end.startsWith(it) } ?: "" + if (matchingPrefix.isNotEmpty()) { + end = end.removePrefix(matchingPrefix) } add(start + end) -- cgit