From 4003666c2710f3e227d1576d310a066d3d60d2d4 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Fri, 11 Jun 2021 23:32:49 -0400 Subject: [PATCH] Cache pointers --- .../java/com/velocitypowered/api/proxy/Player.java | 10 ---------- .../proxy/connection/client/ConnectedPlayer.java | 12 ++++++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index 7cfbe75c9..27fa6f299 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -28,7 +28,6 @@ import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Keyed; -import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -284,15 +283,6 @@ public interface Player extends CommandSource, Identified, InboundConnection, @Override boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data); - @Override - default @NotNull Pointers pointers() { - return CommandSource.super.pointers().toBuilder() - .withDynamic(Identity.UUID, this::getUniqueId) - .withDynamic(Identity.NAME, this::getUsername) - .withDynamic(Identity.DISPLAY_NAME, this::getDisplayName) - .build(); - } - @Override default @NotNull Key key() { return Key.key("player"); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 64bb15122..94b2fd1f5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -94,6 +94,7 @@ import java.util.concurrent.ThreadLocalRandom; import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; @@ -105,6 +106,7 @@ import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.jetbrains.annotations.NotNull; public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @@ -142,6 +144,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private final Queue outstandingResourcePacks = new ArrayDeque<>(); private @Nullable ResourcePackInfo pendingResourcePack; private @Nullable ResourcePackInfo appliedResourcePack; + private final @NotNull Pointers pointers = Player.super.pointers().toBuilder() + .withDynamic(Identity.UUID, this::getUniqueId) + .withDynamic(Identity.NAME, this::getUsername) + .withDynamic(Identity.DISPLAY_NAME, this::getDisplayName) + .build(); ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, @Nullable InetSocketAddress virtualHost, boolean onlineMode) { @@ -1069,6 +1076,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return minecraftOrFmlMessage || knownChannels.contains(message.getChannel()); } + @Override + public @NotNull Pointers pointers() { + return pointers; + } + private class IdentityImpl implements Identity { @Override public @NonNull UUID uuid() {