aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-08-23 09:52:47 +0200
committerGitHub <noreply@github.com>2024-08-23 09:52:47 +0200
commit7bcc247bd3f27735bbfff207ce72b3e2cffb512e (patch)
tree6d0c6faaa4620cccba93e1ef9833a7206b505e7e /src/main/java/at
parentb2a86892cc7078aa00ea68296919bfb496bb3451 (diff)
downloadskyhanni-7bcc247bd3f27735bbfff207ce72b3e2cffb512e.tar.gz
skyhanni-7bcc247bd3f27735bbfff207ce72b3e2cffb512e.tar.bz2
skyhanni-7bcc247bd3f27735bbfff207ce72b3e2cffb512e.zip
Fix: Double Color in ScoreboardData Part 2 (#2382)
Diffstat (limited to 'src/main/java/at')
-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)