From 9a159bf8be2111d30b95b73331369f04c7ed006b Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Fri, 22 Oct 2021 23:31:40 -0400 Subject: [PATCH] Fix instances of invisible/flickering scoreboards --- .../geysermc/connector/scoreboard/Objective.java | 14 -------------- .../geysermc/connector/scoreboard/Scoreboard.java | 12 +++++++----- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Objective.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Objective.java index 41d35d42f..5a7748f79 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Objective.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Objective.java @@ -150,20 +150,6 @@ public final class Objective { updateType = UpdateType.REMOVE; } - public ScoreboardPosition getPositionCategory() { - return switch (displaySlot) { - case PLAYER_LIST -> ScoreboardPosition.PLAYER_LIST; - case BELOW_NAME -> ScoreboardPosition.BELOW_NAME; - default -> ScoreboardPosition.SIDEBAR; - }; - } - - public boolean hasTeamColor() { - return displaySlot != ScoreboardPosition.PLAYER_LIST && - displaySlot != ScoreboardPosition.BELOW_NAME && - displaySlot != ScoreboardPosition.SIDEBAR; - } - public TeamColor getTeamColor() { return switch (displaySlot) { case SIDEBAR_TEAM_RED -> TeamColor.RED; diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java index c32353b78..682ff8331 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java @@ -104,7 +104,7 @@ public final class Scoreboard { Objective storedObjective = objectiveSlots.get(displaySlot); if (storedObjective != null && storedObjective != objective) { - objective.pendingRemove(); + storedObjective.pendingRemove(); } objectiveSlots.put(displaySlot, objective); @@ -166,6 +166,12 @@ public final class Scoreboard { correctSidebar = objectiveSlots.get(ScoreboardPosition.SIDEBAR); } + for (Objective objective : removedObjectives) { + // Deletion must be handled before the active objectives are handled - otherwise if a scoreboard display is changed before the current + // scoreboard is removed, the client can crash + deleteObjective(objective, true); + } + handleObjective(objectiveSlots.get(ScoreboardPosition.PLAYER_LIST), addScores, removeScores); handleObjective(correctSidebar, addScores, removeScores); handleObjective(objectiveSlots.get(ScoreboardPosition.BELOW_NAME), addScores, removeScores); @@ -194,10 +200,6 @@ public final class Scoreboard { session.sendUpstreamPacket(setScorePacket); } - for (Objective objective : removedObjectives) { - deleteObjective(objective, true); - } - lastAddScoreCount = addScores.size(); lastRemoveScoreCount = removeScores.size(); }