Skip to content

Commit

Permalink
Always get the latest ServerPlayerEntity from ServerPlayNetworkHandler (
Browse files Browse the repository at this point in the history
#3735)

(cherry picked from commit 0dca034)
  • Loading branch information
modmuss50 committed Apr 26, 2024
1 parent d18c253 commit bd46f3a
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit bd46f3a

Please sign in to comment.