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 @Linked
public class AFKStopperListener implements Listener { public class AFKStopperListener implements Listener {
private int afkTicks = 0; private long lastMovementTime = System.currentTimeMillis();
public AFKStopperListener() { public AFKStopperListener() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
switch (afkTicks) { long currentTime = System.currentTimeMillis();
case 15: if(currentTime - lastMovementTime > 10*60000) { // 10 Minutes
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers())
p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p));
} } else if(currentTime - lastMovementTime > 9*60000)
case 14: BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
default:
afkTicks++;
}
}, 1200, 1200); //every minute }, 1200, 1200); //every minute
} }
@@ -60,7 +56,7 @@ public class AFKStopperListener implements Listener {
Location from = event.getFrom(); Location from = event.getFrom();
if (from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw()) 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 @EventHandler(priority = EventPriority.LOWEST) //Potential fix for potential race condition with WE axe spontaneously not working