From ecb9df2cfcf6b6cbf88b71b7d313d53f43ce2bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bro=C4=8Dko?= Date: Fri, 16 Aug 2019 22:45:30 +0200 Subject: [PATCH] extended API --- pom.xml | 2 +- src/cz/gamesites/mc/antiafk/AntiAFK.java | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index d209b2a..5d4f04e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 cz.gamesites.mc AntiAFK - 0.0.1-SNAPSHOT + 1.0-SNAPSHOT AntiAFK AntiAFK Spigot plugin diff --git a/src/cz/gamesites/mc/antiafk/AntiAFK.java b/src/cz/gamesites/mc/antiafk/AntiAFK.java index 9c76635..fbaa3ad 100644 --- a/src/cz/gamesites/mc/antiafk/AntiAFK.java +++ b/src/cz/gamesites/mc/antiafk/AntiAFK.java @@ -30,9 +30,9 @@ import net.md_5.bungee.api.ChatColor; public class AntiAFK extends JavaPlugin implements Listener { // frequency of checks - private static final int CHECK_INTERVAL = 2 * 20; + public static final int CHECK_INTERVAL = 20 * 20; // how many times a check has to fail in order to mark the player as AFK - private static final int STRIKES_AFK = 3; + public static final int STRIKES_AFK = 3; private static AntiAFK INSTANCE = null; private HashMap lastPositions = new HashMap<>(); @@ -159,7 +159,23 @@ public class AntiAFK extends JavaPlugin implements Listener { } } } - + + public static boolean isAFKWarningMenu(Inventory inv) { + return INSTANCE.inventories.contains(inv); + } + + public static boolean isPlayerAway(Player p) { + return INSTANCE.strikes.getOrDefault(p, 0) > STRIKES_AFK; + } + + public static long getPlayerAwaySeconds(Player p) { + return INSTANCE.strikes.getOrDefault(p, 0) * CHECK_INTERVAL / 20; + } + + public static void resetPlayerAwayTimer(Player p) { + INSTANCE.strikes.put(p, 0); + } + public static List getAwayPlayers() { return INSTANCE.strikes.entrySet() .stream()