Change AFK Stopper to work based on real time

Fixes #lag145-bug-203.
This commit is contained in:
Lixfel
2024-08-16 17:32:51 +02:00
parent c65c23d5e2
commit 07284eae6a
@@ -35,20 +35,16 @@ import org.bukkit.event.player.PlayerQuitEvent;
@Linked
public class AFKStopperListener implements Listener {
private int afkTicks = 0;
private long lastMovementTime = System.currentTimeMillis();
public AFKStopperListener() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
switch (afkTicks) {
case 15:
for (Player p : Bukkit.getOnlinePlayers()) {
p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p));
}
case 14:
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
default:
afkTicks++;
}
long currentTime = System.currentTimeMillis();
if(currentTime - lastMovementTime > 10*60000) { // 10 Minutes
for (Player p : Bukkit.getOnlinePlayers())
p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p));
} else if(currentTime - lastMovementTime > 9*60000)
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
}, 1200, 1200); //every minute
}
@@ -60,7 +56,7 @@ public class AFKStopperListener implements Listener {
Location from = event.getFrom();
if (from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw())
afkTicks = 0;
lastMovementTime = System.currentTimeMillis();
}
@EventHandler(priority = EventPriority.LOWEST) //Potential fix for potential race condition with WE axe spontaneously not working