mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 14:37:31 +02:00
KeepAliveListener cleanup
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
6e16fb7b13
commit
022ec237ba
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user