Fix edge case in removing below name objectives

This commit is contained in:
Camotoy 2021-10-01 16:38:04 -04:00
parent 86c0c009e7
commit b58cbd00bc
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 6 additions and 6 deletions

View file

@ -355,7 +355,9 @@ public class PlayerEntity extends LivingEntity {
session.sendUpstreamPacket(packet); session.sendUpstreamPacket(packet);
} }
} else { } else {
if (valid && metadata.remove(EntityData.SCORE_TAG) != null) { // Always remove the score tag first, then check for valid.
// That way the score tag is removed if the player was spawned, then despawned, and is being respawned
if (metadata.remove(EntityData.SCORE_TAG) != null && valid) {
SetEntityDataPacket packet = new SetEntityDataPacket(); SetEntityDataPacket packet = new SetEntityDataPacket();
packet.setRuntimeEntityId(geyserId); packet.setRuntimeEntityId(geyserId);
packet.getMetadata().put(EntityData.SCORE_TAG, ""); packet.getMetadata().put(EntityData.SCORE_TAG, "");

View file

@ -70,11 +70,9 @@ public class JavaScoreboardObjectiveTranslator extends PacketTranslator<ServerSc
if (objective != null && objective == scoreboard.getObjectiveSlots().get(ScoreboardPosition.BELOW_NAME)) { if (objective != null && objective == scoreboard.getObjectiveSlots().get(ScoreboardPosition.BELOW_NAME)) {
// Clear the score tag from all players // Clear the score tag from all players
for (PlayerEntity entity : session.getEntityCache().getAllPlayerEntities()) { for (PlayerEntity entity : session.getEntityCache().getAllPlayerEntities()) {
if (!entity.isValid()) { // Other places we check for the entity being valid,
// Player hasn't spawned yet - don't bother // but we must set the below name text as null for all players
continue; // or else PlayerEntity#spawnEntity will find a null objective and not touch EntityData#SCORE_TAG
}
entity.setBelowNameText(session, null); entity.setBelowNameText(session, null);
} }
} }