Closed nellieldev closed 9 months ago
For everyone who needs a hotfix:
/* Put into your initializer */
{
final Field field = PacketProcessor.class.getDeclaredField("playHandler");
field.setAccessible(true);
final ClientPacketsHandler handler = (ClientPacketsHandler.Play) field.get(MinecraftServer.getPacketProcessor());
handler.register(0x1e, PingRequestPacket::new);
MinecraftServer.getPacketListenerManager().setPlayListener(PingRequestPacket.class, (pingPacket, playerConnection) -> playerConnection.sendPacket(new PingResponsePacket(pingPacket.payload())));
}
The two classes:
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.client.ClientPacket;
import org.jetbrains.annotations.NotNull;
public record PingRequestPacket(long payload) implements ClientPacket {
public PingRequestPacket(final NetworkBuffer buffer) {
this(buffer.read(NetworkBuffer.LONG));
}
@Override
public void write(@NotNull final NetworkBuffer networkBuffer) {
networkBuffer.write(NetworkBuffer.LONG, this.payload);
}
}
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record PingResponsePacket(long payload) implements ServerPacket {
@Override
public void write(@NotNull final NetworkBuffer networkBuffer) {
networkBuffer.write(NetworkBuffer.LONG, this.payload);
}
@Override
public int getId(@NotNull final ConnectionState state) {
return state == ConnectionState.PLAY ? 0x34 : PacketUtils.invalidPacketState(this.getClass(), state, ConnectionState.PLAY);
}
}
When pressing
F3 + 3
the network monitor of minecraft will be opened and ping request packets (play) are being sent contantly to the server. They are not implemented so this error will occurr:java.lang.IllegalStateException: Packet id 0x1e isn't registered!
Dont forget to implement Ping Response (play) too.