From 0dca0349ce48ad9a0f6ef410f6ee95221a0678fc Mon Sep 17 00:00:00 2001 From: modmuss Date: Fri, 26 Apr 2024 22:14:28 +0100 Subject: [PATCH] Always get the latest ServerPlayerEntity from ServerPlayNetworkHandler (#3735) --- .../networking/server/ServerPlayNetworkAddon.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java index b758912038..6f27923ad1 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java @@ -48,7 +48,7 @@ public ServerPlayNetworkAddon(ServerPlayNetworkHandler handler, ClientConnection super(ServerNetworkingImpl.PLAY, connection, "ServerPlayNetworkAddon for " + handler.player.getDisplayName()); this.handler = handler; this.server = server; - this.context = new ContextImpl(handler.player, this); + this.context = new ContextImpl(handler, this); // Must register pending channels via lateinit this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.PLAY); @@ -129,10 +129,15 @@ protected boolean isReservedChannel(Identifier channelName) { return NetworkingImpl.isReservedCommonChannel(channelName); } - private record ContextImpl(ServerPlayerEntity player, PacketSender responseSender) implements ServerPlayNetworking.Context { + private record ContextImpl(ServerPlayNetworkHandler handler, PacketSender responseSender) implements ServerPlayNetworking.Context { private ContextImpl { - Objects.requireNonNull(player, "player"); + Objects.requireNonNull(handler, "handler"); Objects.requireNonNull(responseSender, "responseSender"); } + + @Override + public ServerPlayerEntity player() { + return handler.getPlayer(); + } } }