diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index c82922607..595ba0e84 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -6,6 +6,7 @@ import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; @@ -182,6 +183,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, // Adventure private Identity identity; + private Pointers pointers; public Player(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) { super(EntityType.PLAYER, uuid); @@ -2533,6 +2535,19 @@ public class Player extends LivingEntity implements CommandSender, Localizable, return this.identity; } + @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; + } + @Override public void setUuid(@NotNull UUID uuid) { super.setUuid(uuid); diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index 3e7c81261..1f0fafa3f 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -1,6 +1,8 @@ package net.minestom.server.instance; import com.google.common.collect.Queues; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.pointer.Pointers; import net.minestom.server.MinecraftServer; import net.minestom.server.Tickable; import net.minestom.server.UpdateManager; @@ -107,6 +109,9 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< // Pathfinder private final PFInstanceSpace instanceSpace = new PFInstanceSpace(this); + // Adventure + private Pointers pointers = null; + /** * Creates a new instance. * @@ -1114,4 +1119,15 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< public PFInstanceSpace getInstanceSpace() { return instanceSpace; } + + @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 83e3ef4f5..bae78c1dd 100644 --- a/src/main/java/net/minestom/server/scoreboard/Team.java +++ b/src/main/java/net/minestom/server/scoreboard/Team.java @@ -1,6 +1,8 @@ package net.minestom.server.scoreboard; import com.google.common.collect.MapMaker; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.MinecraftServer; @@ -73,6 +75,9 @@ public class Team implements PacketGroupingAudience { private final Set playerMembers = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap()); private boolean isPlayerMembersUpToDate; + // Adventure + private Pointers pointers; + /** * Default constructor to creates a team. * @@ -587,4 +592,16 @@ public class Team implements PacketGroupingAudience { return this.playerMembers; } + + @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; + } }