From 333936cfa8682ac3dd3d88cdc01d319293ba6c9e Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 30 Aug 2018 18:10:16 +0300 Subject: [PATCH] Implemented afk check on kick event #705 Note about AFK ignore perm: - Players kicked by afk that have plan.ignore.afk will be counted as "real" kicks. --- .../com/djrapitops/plan/system/afk/AFKTracker.java | 10 ++++++++++ .../system/listeners/bukkit/PlayerOnlineListener.java | 4 ++++ .../system/listeners/sponge/SpongePlayerListener.java | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/afk/AFKTracker.java b/Plan/src/main/java/com/djrapitops/plan/system/afk/AFKTracker.java index d9c7f85a6..0dd7a512e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/afk/AFKTracker.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/afk/AFKTracker.java @@ -65,4 +65,14 @@ public class AFKTracker { lastMovement.remove(uuid); usedAFKCommand.remove(uuid); } + + public boolean isAfk(UUID uuid) { + long time = System.currentTimeMillis(); + + Long lastMoved = lastMovement.get(uuid); + if (lastMoved == null || lastMoved == -1) { + return false; + } + return time - lastMoved > afkThresholdMs; + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index c28f0f4a8..5daaf4d84 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -63,6 +63,10 @@ public class PlayerOnlineListener implements Listener { return; } UUID uuid = event.getPlayer().getUniqueId(); + if (AFKListener.AFK_TRACKER.isAfk(uuid)) { + return; + } + Processing.submit(new KickProcessor(uuid)); } catch (Exception e) { Log.toLog(this.getClass(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java index d0f4c478c..c7f5897f5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java @@ -2,6 +2,7 @@ package com.djrapitops.plan.system.listeners.sponge; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.cache.SessionCache; +import com.djrapitops.plan.system.listeners.bukkit.AFKListener; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor; @@ -52,6 +53,9 @@ public class SpongePlayerListener { public void onKick(KickPlayerEvent event) { try { UUID uuid = event.getTargetEntity().getUniqueId(); + if (AFKListener.AFK_TRACKER.isAfk(uuid)) { + return; + } Processing.submit(new KickProcessor(uuid)); } catch (Exception e) { Log.toLog(this.getClass(), e);