Rollback removal usage of teams prefix to handle colored scoreboard sidebar (was not working on Bedrock clients and on some Java clients)

Marc Baloup 2024-02-24 15:10:29 +01:00
parent 649e1a56c8
commit bae70598d6
1 changed files with 20 additions and 0 deletions

View File

@ -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,7 +64,20 @@ 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]);
if (scoreEntry.getScore() != 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());
}
}
}