Fixed NPE when channel of user is null

This commit is contained in:
RaphiMC 2023-01-14 15:07:11 +01:00
parent 109ef52ec7
commit 97464ce3b0
2 changed files with 15 additions and 13 deletions

View File

@ -6,4 +6,4 @@ org.gradle.configureondemand=true
# Project properties
maven_name=ViaLegacy
maven_group=net.raphimc
maven_version=2.2.0
maven_version=2.2.1

View File

@ -1189,19 +1189,21 @@ public class Protocol1_7_2_5to1_6_4 extends AbstractProtocol<ClientboundPackets1
}
userConnection.put(new ChunkTracker(userConnection));
userConnection.getChannel().pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
if (userConnection.getProtocolInfo().getState().equals(State.PLAY) && ctx.channel().isWritable() && userConnection.get(PlayerInfoStorage.class).entityId != -1) {
final PacketWrapper disconnect = PacketWrapper.create(ServerboundPackets1_6_4.DISCONNECT, userConnection);
disconnect.write(Types1_6_4.STRING, "Quitting"); // reason
disconnect.sendToServer(Protocol1_7_2_5to1_6_4.class);
Thread.sleep(50); // Wait for the packet to arrive at the server
}
if (userConnection.getChannel() != null) {
userConnection.getChannel().pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
if (userConnection.getProtocolInfo().getState().equals(State.PLAY) && ctx.channel().isWritable() && userConnection.get(PlayerInfoStorage.class).entityId != -1) {
final PacketWrapper disconnect = PacketWrapper.create(ServerboundPackets1_6_4.DISCONNECT, userConnection);
disconnect.write(Types1_6_4.STRING, "Quitting"); // reason
disconnect.sendToServer(Protocol1_7_2_5to1_6_4.class);
Thread.sleep(50); // Wait for the packet to arrive at the server
}
super.close(ctx, promise);
}
});
super.close(ctx, promise);
}
});
}
}
}