Don't lazily initialise pointers

This commit is contained in:
Kieran Wallbanks 2021-06-15 14:06:56 +01:00
parent 81afe75756
commit dd82635c6f
3 changed files with 17 additions and 24 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}