aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
index 26915faf3..2287ae358 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
@@ -22,13 +22,7 @@ object ScoreboardData {
private var sidebarLines: List<String> = emptyList() // TODO rename to raw
var sidebarLinesRaw: List<String> = emptyList() // TODO delete
- val objectiveTitle: String get() = grabObjectiveTitle()
-
- fun grabObjectiveTitle(): String {
- val scoreboard = Minecraft.getMinecraft().theWorld?.scoreboard ?: return ""
- val objective = scoreboard.getObjectiveInDisplaySlot(1) ?: return ""
- return objective.displayName
- }
+ val objectiveTitle: String get() = Minecraft.getMinecraft().theWorld?.scoreboard?.getObjectiveInDisplaySlot(1)?.displayName ?: ""
private var dirty = false
@@ -39,16 +33,32 @@ object ScoreboardData {
val start = split[0]
var end = if (split.size > 1) split[1] else ""
+ /**
+ * If the line is split into two parts, we need to remove the color code prefixes from the end part
+ * to prevent the color from being applied to the start of `end`, which would cause the color to be
+ * duplicated in the final output.
+ *
+ * This fucks up different Regex checks if not working correctly, like here:
+ * ```
+ * Pattern: '§8- (§.)+[\w\s]+Dragon§a [\w,.]+§.❤'
+ * Lines: - '§8- §c§aApex Dra§agon§a 486M§c❤'
+ * - '§8- §c§6Flame Dr§6agon§a 460M§c❤'
+ * ```
+ */
val lastColor = start.lastColorCode() ?: ""
- // Determine the longest prefix of "end" that matches any suffix of "lastColor"
+ // Generate the list of color suffixes
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)
+ .toMutableList()
+
+ // Iterate through the colorSuffixes to remove matching prefixes from 'end'
+ for (suffix in colorSuffixes.toList()) {
+ if (end.startsWith(suffix)) {
+ end = end.removePrefix(suffix)
+ colorSuffixes.remove(suffix)
+ break
+ }
}
add(start + end)