Class AFK
- All Implemented Interfaces:
org.bukkit.event.Listener
When EssentialsX is present this class defers entirely
to EssentialsHook.isAfk(Player) so the two systems never conflict.
When Essentials is absent, a Bukkit Listener is registered that
records the last time each player moved or issued a command; a player is considered AFK
once that timestamp is older than AFK_THRESHOLD.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidinit()Initialises the AFK subsystem.static booleanisAFK(org.bukkit.entity.Player player) Returns whether the given player is currently AFK.voidonPlayerCommand(org.bukkit.event.player.PlayerCommandPreprocessEvent event) Resets a player's AFK timer whenever they run a command.voidonPlayerMove(org.bukkit.event.player.PlayerMoveEvent event) Resets a player's AFK timer whenever they move.voidonPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event) Removes a player from the AFK tracking map when they leave the server.
-
Constructor Details
-
AFK
public AFK()
-
-
Method Details
-
init
public static void init()Initialises the AFK subsystem.Registers this class as a Bukkit event listener only when EssentialsX is not hooked; if Essentials is present its own AFK tracking is used instead to avoid duplicate state.
This method should be called during plugin enable/startup after EssentialsHook.Hook() to ensure proper integration.
-
onPlayerMove
public void onPlayerMove(org.bukkit.event.player.PlayerMoveEvent event) Resets a player's AFK timer whenever they move.- Parameters:
event- thePlayerMoveEventfired by Bukkit
-
onPlayerQuit
public void onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event) Removes a player from the AFK tracking map when they leave the server.- Parameters:
event- thePlayerQuitEventfired by Bukkit
-
onPlayerCommand
public void onPlayerCommand(org.bukkit.event.player.PlayerCommandPreprocessEvent event) Resets a player's AFK timer whenever they run a command.- Parameters:
event- thePlayerCommandPreprocessEventfired by Bukkit
-
isAFK
public static boolean isAFK(org.bukkit.entity.Player player) Returns whether the given player is currently AFK.If EssentialsX is hooked, this method delegates to
EssentialsHook.isAfk(Player). Otherwise it compares the player's last-activity timestamp againstAFK_THRESHOLD:- If the player has no recorded activity they are treated as not AFK.
- If the elapsed time since last activity is ≥
AFK_THRESHOLDthey are AFK.
- Parameters:
player- the player to check- Returns:
trueif the player is AFK,falseotherwise
-