diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java index 81e2f4dd..479dd394 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AFKStopperListener.java @@ -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