Skip to main content
Documentation menu
AntiAFKPlus · For Developers

API

Documents AntiAFKPlus 6.4.0 · mirrored from the product wiki, updated 2026-02-08

AntiAFKPlus provides a Java API for other plugins to interact with the AFK system.

Getting the API Instance

import com.antiafkplus.api.AntiAFKPlusAPI;

// Get the API from the plugin instance
AntiAFKPlus plugin = (AntiAFKPlus) Bukkit.getPluginManager().getPlugin("AntiAFKPlus");
AntiAFKPlusAPI api = plugin.getManagers().getAPI();

API Methods

AntiAFKPlusAPI Interface

public interface AntiAFKPlusAPI {

    // Check if a player is currently AFK
    boolean isAFK(Player player);
    boolean isAFK(UUID uuid);

    // Get how long the player has been inactive (milliseconds)
    long getInactiveTime(Player player);

    // Get the player's current AFK status
    AFKStatus getStatus(Player player);

    // Reset a player's AFK timer (marks them as active)
    void resetTimer(Player player);

    // Exempt a player from AFK detection for a duration
    void exemptPlayer(Player player, long durationMs);

    // Remove exemption from a player
    void unexemptPlayer(Player player);

    // Check if a player is exempt
    boolean isExempt(Player player);

    // Get all currently AFK players
    List<Player> getAFKPlayers();

    // Get the count of AFK players
    int getAFKCount();

    // Get AFK players excluding vanished ones
    List<Player> getVisibleAFKPlayers();

    // Get count of visible AFK players
    int getVisibleAFKCount();
}

AFKStatus Enum

public enum AFKStatus {
    ACTIVE,    // Player is actively playing
    AFK,       // Player is away from keyboard
    EXEMPT     // Player is exempt from AFK detection
}

Usage Examples

Check if a Player is AFK

if (api.isAFK(player)) {
    player.sendMessage("You are currently marked as AFK!");
}

Reset AFK Timer

Useful when your plugin performs an action that should count as activity:

api.resetTimer(player);

Temporarily Exempt a Player

// Exempt for 5 minutes (300,000 ms)
api.exemptPlayer(player, 300_000);

Get AFK Player Count for Scoreboard

int afkCount = api.getVisibleAFKCount();
// Use in scoreboard, placeholder, etc.

Soft-Depending on AntiAFKPlus

In your plugin.yml:

softdepend: [AntiAFKPlus]

Always check if the plugin is loaded before using the API:

Plugin antiafk = Bukkit.getPluginManager().getPlugin("AntiAFKPlus");
if (antiafk != null && antiafk.isEnabled()) {
    AntiAFKPlusAPI api = ((AntiAFKPlus) antiafk).getManagers().getAPI();
    // Use API safely
}

PlaceholderAPI Placeholders

If PlaceholderAPI is installed, AntiAFKPlus automatically registers the following placeholders:

Placeholder Description Example
%antiafk_status% Player's AFK status AFK or Active
%antiafk_status_colored% Color-coded status &cAFK or &aActive
%antiafk_time% Formatted inactive time 4m 30s
%antiafk_time_seconds% Inactive time in seconds 270
%antiafk_until_kick% Time remaining until kick 30s or Exempt
%antiafk_exempt% Whether the player is exempt true or false
%antiafk_count% Total number of AFK players 3

These work in any plugin that supports PlaceholderAPI — scoreboards, tab lists, holograms, chat formatting, etc.

See Also

  • Events — Bukkit events fired by AntiAFKPlus

Events

AntiAFKPlus fires three Bukkit events that other plugins can listen to.

PlayerAFKEvent

Fired when a player becomes AFK (reaches the first warning stage). Not cancellable.

import com.antiafkplus.api.events.PlayerAFKEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class MyListener implements Listener {

    @EventHandler
    public void onAFK(PlayerAFKEvent event) {
        event.getPlayer().sendMessage("You are now AFK!");
    }
}

PlayerAFKKickEvent

Fired when a player is about to be kicked for AFK. Cancellable — other plugins can prevent the kick.

import com.antiafkplus.api.events.PlayerAFKKickEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class MyListener implements Listener {

    @EventHandler
    public void onAFKKick(PlayerAFKKickEvent event) {
        // Prevent VIP players from being kicked
        if (event.getPlayer().hasPermission("vip.afk.bypass")) {
            event.setCancelled(true);
            return;
        }

        // Customize the kick message
        event.setKickMessage("§cYou were removed for inactivity.");
    }
}

Available methods:

Method Description
getPlayer() The player being kicked
getKickMessage() The current kick message
setKickMessage(String) Change the kick message
isCancelled() Whether the kick has been cancelled
setCancelled(boolean) Cancel or uncancel the kick

PlayerReturnEvent

Fired when a player returns from being AFK. Not cancellable.

import com.antiafkplus.api.events.PlayerReturnEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class MyListener implements Listener {

    @EventHandler
    public void onReturn(PlayerReturnEvent event) {
        long durationMs = event.getAFKDuration();
        long seconds = durationMs / 1000;
        event.getPlayer().sendMessage("Welcome back! You were AFK for " + seconds + "s.");
    }
}

Available methods:

Method Description
getPlayer() The player who returned
getAFKDuration() How long the player was AFK, in milliseconds

Example Plugin

import com.antiafkplus.api.events.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

public class AFKHooksPlugin extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onAFK(PlayerAFKEvent event) {
        getLogger().info(event.getPlayer().getName() + " went AFK");
    }

    @EventHandler
    public void onKick(PlayerAFKKickEvent event) {
        getLogger().info(event.getPlayer().getName() + " is being kicked for AFK");
    }

    @EventHandler
    public void onReturn(PlayerReturnEvent event) {
        long seconds = event.getAFKDuration() / 1000;
        getLogger().info(event.getPlayer().getName() + " returned after " + seconds + "s");
    }
}

Ready to run it? Get AntiAFKPlusConfigurable AFK detection with actions, permissions, and PlaceholderAPI.

API · AntiAFKPlus Minecraft plugin docs | InfinitePlugins