mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Fix ping
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
1c3bb5b0ff
commit
b35954c05d
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user