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.entity.Player;
|
||||||
import net.minestom.server.network.packet.client.play.ClientKeepAlivePacket;
|
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) {
|
public static void listener(ClientKeepAlivePacket packet, Player player) {
|
||||||
final long packetId = packet.id;
|
final long packetId = packet.id;
|
||||||
final long playerId = player.getLastKeepAlive();
|
if (packetId != player.getLastKeepAlive()) {
|
||||||
final boolean equals = packetId == playerId;
|
player.kick(KICK_MESSAGE);
|
||||||
if (!equals) {
|
|
||||||
player.kick(Component.text("Bad Keep Alive packet", NamedTextColor.RED));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.refreshAnswerKeepAlive(true);
|
player.refreshAnswerKeepAlive(true);
|
||||||
|
|
||||||
// Update latency
|
// Update latency
|
||||||
final int latency = (int) (System.currentTimeMillis() - packet.id);
|
final int latency = (int) (System.currentTimeMillis() - packetId);
|
||||||
player.refreshLatency(latency);
|
player.refreshLatency(latency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user