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.
This commit is contained in:
Rsl1122 2018-08-30 18:10:16 +03:00
parent 08d1067bd8
commit 333936cfa8
3 changed files with 18 additions and 0 deletions

View File

@ -65,4 +65,14 @@ public class AFKTracker {
lastMovement.remove(uuid); lastMovement.remove(uuid);
usedAFKCommand.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;
}
} }

View File

@ -63,6 +63,10 @@ public class PlayerOnlineListener implements Listener {
return; return;
} }
UUID uuid = event.getPlayer().getUniqueId(); UUID uuid = event.getPlayer().getUniqueId();
if (AFKListener.AFK_TRACKER.isAfk(uuid)) {
return;
}
Processing.submit(new KickProcessor(uuid)); Processing.submit(new KickProcessor(uuid));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.system.listeners.sponge;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.cache.SessionCache; 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.Processing;
import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor;
import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor;
@ -52,6 +53,9 @@ public class SpongePlayerListener {
public void onKick(KickPlayerEvent event) { public void onKick(KickPlayerEvent event) {
try { try {
UUID uuid = event.getTargetEntity().getUniqueId(); UUID uuid = event.getTargetEntity().getUniqueId();
if (AFKListener.AFK_TRACKER.isAfk(uuid)) {
return;
}
Processing.submit(new KickProcessor(uuid)); Processing.submit(new KickProcessor(uuid));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);