From 6ee3d4ed962d8d476d0052ae15af695620fbf4d1 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 7 Feb 2023 13:14:06 -0500 Subject: [PATCH] Fix #3537 --- .../geysermc/geyser/entity/type/player/PlayerEntity.java | 4 ++++ .../java/org/geysermc/geyser/scoreboard/Scoreboard.java | 3 ++- .../main/java/org/geysermc/geyser/scoreboard/Team.java | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 3501eb296..c77892ac5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -119,6 +119,8 @@ public class PlayerEntity extends LivingEntity { setBelowNameText(objective); } + // Update in case this entity has been despawned, then respawned + this.nametag = this.username; // The name can't be updated later (the entity metadata for it is ignored), so we need to check for this now updateDisplayName(session.getWorldCache().getScoreboard().getTeamFor(username)); @@ -339,6 +341,8 @@ public class PlayerEntity extends LivingEntity { this.nametag = this.username; } + System.out.println(this.username + " " + this.nametag + " " + needsUpdate); + if (needsUpdate) { dirtyMetadata.put(EntityData.NAMETAG, this.nametag); } diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java index f97693a62..a7178ac8d 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java @@ -352,7 +352,8 @@ public final class Scoreboard { // With the player's lack of a team in visibility checks updateEntityNames(remove, remove.getEntities(), true); for (String name : remove.getEntities()) { - playerToTeam.remove(name, remove); + // 1.19.3 Mojmap Scoreboard#removePlayerTeam(PlayerTeam) + playerToTeam.remove(name); } session.removeCommandEnum("Geyser_Teams", remove.getId()); diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java index 34db4a048..7738f5f42 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java @@ -65,7 +65,14 @@ public final class Team { if (entities.add(name)) { added.add(name); } - scoreboard.getPlayerToTeam().put(name, this); + scoreboard.getPlayerToTeam().compute(name, (player, oldTeam) -> { + if (oldTeam != null) { + // Remove old team from this map, and from the set of players of the old team. + // Java 1.19.3 Mojmap: Scoreboard#addPlayerToTeam calls #removePlayerFromTeam + oldTeam.entities.remove(player); + } + return this; + }); } if (added.isEmpty()) {