KeepAliveListener cleanup

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-10-10 03:29:51 +02:00
parent 6e16fb7b13
commit 022ec237ba

View File

@ -5,21 +5,18 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.client.play.ClientKeepAlivePacket;
public class KeepAliveListener {
public final class KeepAliveListener {
private static final Component KICK_MESSAGE = Component.text("Bad Keep Alive packet", NamedTextColor.RED);
public static void listener(ClientKeepAlivePacket packet, Player player) {
final long packetId = packet.id;
final long playerId = player.getLastKeepAlive();
final boolean equals = packetId == playerId;
if (!equals) {
player.kick(Component.text("Bad Keep Alive packet", NamedTextColor.RED));
if (packetId != player.getLastKeepAlive()) {
player.kick(KICK_MESSAGE);
return;
}
player.refreshAnswerKeepAlive(true);
// Update latency
final int latency = (int) (System.currentTimeMillis() - packet.id);
final int latency = (int) (System.currentTimeMillis() - packetId);
player.refreshLatency(latency);
}
}