diff --git a/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java b/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java index 27f9869d8..b216a8dad 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java +++ b/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java @@ -4,10 +4,8 @@ import net.minestom.server.network.packet.client.status.PingPacket; import net.minestom.server.network.packet.client.status.StatusRequestPacket; public class ClientStatusPacketsHandler extends ClientPacketsHandler { - public ClientStatusPacketsHandler() { register(0x00, StatusRequestPacket::new); register(0x01, PingPacket::new); } - } diff --git a/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java b/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java index 94128833d..87361e984 100644 --- a/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java @@ -16,12 +16,8 @@ public class StatusRequestPacket implements ClientPreplayPacket { public void process(@NotNull PlayerConnection connection) { final ServerListPingType pingVersion = ServerListPingType.fromModernProtocolVersion(connection.getProtocolVersion()); final ServerListPingEvent statusRequestEvent = new ServerListPingEvent(connection, pingVersion); - EventDispatcher.callCancellable(statusRequestEvent, () -> { - final ResponsePacket responsePacket = new ResponsePacket(); - responsePacket.jsonResponse = pingVersion.getPingResponse(statusRequestEvent.getResponseData()); - - connection.sendPacket(responsePacket); - }); + EventDispatcher.callCancellable(statusRequestEvent, () -> + connection.sendPacket(new ResponsePacket(pingVersion.getPingResponse(statusRequestEvent.getResponseData())))); } @Override diff --git a/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java b/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java index 972ed8423..a654281c1 100644 --- a/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java @@ -7,7 +7,11 @@ import org.jetbrains.annotations.NotNull; public class ResponsePacket implements ServerPacket { - public String jsonResponse = ""; + public String jsonResponse; + + public ResponsePacket(String jsonResponse) { + this.jsonResponse = jsonResponse; + } @Override public void write(@NotNull BinaryWriter writer) { diff --git a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java index 9ecfc5544..8b0270c04 100644 --- a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java +++ b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java @@ -228,12 +228,13 @@ public class NettyPlayerConnection extends PlayerConnection { } public void attemptWrite(ByteBuffer buffer) { + buffer.flip(); synchronized (tickBufferLock) { try { this.tickBuffer.put(buffer); } catch (BufferOverflowException e) { try { - this.channel.write(tickBuffer); + this.channel.write(tickBuffer.flip()); this.channel.write(buffer); } catch (IOException ex) { MinecraftServer.getExceptionManager().handleException(ex); @@ -245,12 +246,12 @@ public class NettyPlayerConnection extends PlayerConnection { } public void flush() { - if (tickBuffer.remaining() == 0) { - // Nothing to write - return; - } - // Retrieve safe copy synchronized (tickBufferLock) { + this.tickBuffer.flip(); + if (tickBuffer.remaining() == 0) { + // Nothing to write + return; + } try { channel.write(tickBuffer); } catch (IOException e) {