Class AFK

java.lang.Object
valorless.rarespawns.player.AFK
All Implemented Interfaces:
org.bukkit.event.Listener

public class AFK extends Object implements org.bukkit.event.Listener
Tracks player AFK (Away From Keyboard) status for RareSpawns.

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
    Constructor
    Description
    AFK()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Initialises the AFK subsystem.
    static boolean
    isAFK(org.bukkit.entity.Player player)
    Returns whether the given player is currently AFK.
    void
    onPlayerCommand(org.bukkit.event.player.PlayerCommandPreprocessEvent event)
    Resets a player's AFK timer whenever they run a command.
    void
    onPlayerMove(org.bukkit.event.player.PlayerMoveEvent event)
    Resets a player's AFK timer whenever they move.
    void
    onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event)
    Removes a player from the AFK tracking map when they leave the server.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 - the PlayerMoveEvent fired 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 - the PlayerQuitEvent fired 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 - the PlayerCommandPreprocessEvent fired 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 against AFK_THRESHOLD:

      • If the player has no recorded activity they are treated as not AFK.
      • If the elapsed time since last activity is ≥ AFK_THRESHOLD they are AFK.
      Parameters:
      player - the player to check
      Returns:
      true if the player is AFK, false otherwise