Always get the latest ServerPlayerEntity from ServerPlayNetworkHandler (#3735)

(cherry picked from commit 0dca0349ce)
This commit is contained in:
modmuss 2024-04-26 22:14:28 +01:00 committed by modmuss50
parent d18c2535c2
commit bd46f3a075

View file

@ -48,7 +48,7 @@ public final class ServerPlayNetworkAddon extends AbstractChanneledNetworkAddon<
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 @@ public final class ServerPlayNetworkAddon extends AbstractChanneledNetworkAddon<
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();
}
}
}