diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 97da7ee5c..e0a28bf6c 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -183,7 +183,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, // Adventure private Identity identity; - private Pointers pointers; + private final Pointers pointers; public Player(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) { super(EntityType.PLAYER, uuid); @@ -212,6 +212,11 @@ public class Player extends LivingEntity implements CommandSender, Localizable, playerConnectionInit(); this.identity = Identity.identity(uuid); + this.pointers = Pointers.builder() + .withDynamic(Identity.UUID, this::getUuid) + .withDynamic(Identity.NAME, this::getUsername) + .withDynamic(Identity.DISPLAY_NAME, this::getDisplayName) + .build(); } /** @@ -2550,14 +2555,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable, @Override public @NotNull Pointers pointers() { - if (this.pointers == null) { - this.pointers = Pointers.builder() - .withDynamic(Identity.UUID, this::getUuid) - .withDynamic(Identity.NAME, this::getUsername) - .withDynamic(Identity.DISPLAY_NAME, this::getDisplayName) - .build(); - } - return this.pointers; } diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index 1f0fafa3f..0015a33a2 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -110,7 +110,7 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< private final PFInstanceSpace instanceSpace = new PFInstanceSpace(this); // Adventure - private Pointers pointers = null; + private final Pointers pointers; /** * Creates a new instance. @@ -127,6 +127,10 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< this.worldBorder = new WorldBorder(this); this.eventNode = EventNode.value("instance-" + uniqueId, EventFilter.INSTANCE, this::equals); + + this.pointers = Pointers.builder() + .withDynamic(Identity.UUID, this::getUniqueId) + .build(); } /** @@ -1122,12 +1126,6 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< @Override public @NotNull Pointers pointers() { - if (this.pointers == null) { - this.pointers = Pointers.builder() - .withDynamic(Identity.UUID, this::getUniqueId) - .build(); - } - return this.pointers; } } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/scoreboard/Team.java b/src/main/java/net/minestom/server/scoreboard/Team.java index bae78c1dd..f316c44b8 100644 --- a/src/main/java/net/minestom/server/scoreboard/Team.java +++ b/src/main/java/net/minestom/server/scoreboard/Team.java @@ -76,7 +76,7 @@ public class Team implements PacketGroupingAudience { private boolean isPlayerMembersUpToDate; // Adventure - private Pointers pointers; + private final Pointers pointers; /** * Default constructor to creates a team. @@ -96,6 +96,11 @@ public class Team implements PacketGroupingAudience { this.suffix = Component.empty(); this.members = new CopyOnWriteArraySet<>(); + + this.pointers = Pointers.builder() + .withDynamic(Identity.NAME, this::getTeamName) + .withDynamic(Identity.DISPLAY_NAME, this::getTeamDisplayName) + .build(); } /** @@ -595,13 +600,6 @@ public class Team implements PacketGroupingAudience { @Override public @NotNull Pointers pointers() { - if (this.pointers == null) { - this.pointers = Pointers.builder() - .withDynamic(Identity.NAME, this::getTeamName) - .withDynamic(Identity.DISPLAY_NAME, this::getTeamDisplayName) - .build(); - } - return this.pointers; } }