Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-08-03 13:09:03 +02:00
parent 1c3bb5b0ff
commit b35954c05d
4 changed files with 14 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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) {

View File

@ -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) {