From d7705d8904ab720d1bd29162732c37dc5cb4a542 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 24 Feb 2024 15:10:29 +0100 Subject: [PATCH] Rollback removal usage of teams prefix to handle colored scoreboard sidebar (was not working on Bedrock clients and on some Java clients) --- .../lib/paper/util/ScoreboardUtil.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java index e3d663d..e80d1aa 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java @@ -9,6 +9,7 @@ import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; import java.util.List; @@ -63,9 +64,22 @@ public class ScoreboardUtil { */ int score = 1, i = 0; for (int lineIndex = Math.min(lines.length, 15) - 1; lineIndex >= 0; i++, score++, lineIndex--) { + String teamId = "sidebar_team" + score; String sbEntry = colors[i].toString(); + Team tLine = scBrd.getTeam(teamId); + if (tLine == null) { + tLine = scBrd.registerNewTeam(teamId); + } + if (!tLine.hasEntry(sbEntry)) { + tLine.addEntry(sbEntry); + } + + if (!tLine.prefix().equals(lines[lineIndex])) { + tLine.prefix(lines[lineIndex]); + } + Score scoreEntry = obj.getScore(sbEntry); - scoreEntry.customName(lines[lineIndex]); + // scoreEntry.customName(lines[lineIndex]); // not for now x) if (scoreEntry.getScore() != score) { scoreEntry.setScore(score); } @@ -73,11 +87,17 @@ public class ScoreboardUtil { // clean older data when we are reducing the number of line displayed for (; i < colors.length; i++, score++) { + String teamId = "sidebar_team" + score; String sbEntry = colors[i].toString(); if (obj.getScore(sbEntry).isScoreSet()) { scBrd.resetScores(sbEntry); } + + Team tLine = scBrd.getTeam(teamId); + if (tLine != null && !tLine.prefix().equals(Component.empty())) { + tLine.prefix(Component.empty()); + } } }