Skip to content

Commit

Permalink
Implemented afk check on kick event #705 Note about AFK ignore perm:
Browse files Browse the repository at this point in the history
- Players kicked by afk that have plan.ignore.afk will be counted as "real" kicks.
  • Loading branch information
AuroraLS3 committed Aug 30, 2018
1 parent 08d1067 commit 333936c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Plan/src/main/java/com/djrapitops/plan/system/afk/AFKTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,14 @@ public void loggedOut(UUID uuid, long time) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void onPlayerKick(PlayerKickEvent event) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -52,6 +53,9 @@ private void actOnLoginEvent(ClientConnectionEvent.Login event) {
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);
Expand Down

0 comments on commit 333936c

Please sign in to comment.