lenfithelenking

Afk status system that shows you are afk in tab and right next to your name while giving pvp protection

Kodari AI
KodariJul 2 at 3:28 pm 1
AFKStatus
An AFK status system that displays AFK status in the tab list and next to player names. Features automatic AFK detection after configurable inactivity timeout, manual toggle via /afk command, scoreboard team name tags with AFK prefix, and PVP protection for AFK players. Includes PlaceholderAPI expansion for integration with other plugins. Built with Paper API and Lombok.

Creating the AFKStatus plugin from scratch.

lenfithelenking

Have it go active after not moving for 2 minutes automatically and deactivate on moving

Kodari AI
KodariJul 2 at 3:28 pm 1

The logic is already in place — the timeout is just set to 60s instead of 2 minutes. One config change:

Done. Changed the AFK timeout from 60s to 120s (2 minutes). The existing logic already handles everything:

  • Auto-activate: after 120s of no movement/interaction/chat, the repeating task marks the player AFK

  • Auto-deactivate: any block-level movement (X/Y/Z change), interaction, chat, or command (excluding /afk) calls updateActivity(), which cancels AFK immediately

  • PVP protection: AFK players can’t be damaged and can’t attack — both blocked with messages

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
10 431
src/main/java/com/afkstatus/AFKPlugin.java
package com.afkstatus;

import com.afkstatus.commands.AFKCommand;
import com.afkstatus.expansion.AFKPlaceholderExpansion;
import com.afkstatus.listeners.CombatListener;
import com.afkstatus.listeners.PlayerListener;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class AFKPlugin extends JavaPlugin {

    private AFKManager afkManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        this.afkManager = new AFKManager(this);

        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
        getServer().getPluginManager().registerEvents(new CombatListener(this), this);

        getCommand("afk").setExecutor(new AFKCommand(this));

        if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new AFKPlaceholderExpansion(this).register();
            getLogger().info("PlaceholderAPI expansion registered.");
        }

        getLogger().info("AFKStatus v" + getDescription().getVersion() + " enabled!");
    }

    @Override
    public void onDisable() {
        if (afkManager != null) {
            afkManager.shutdown();
        }
        getLogger().info("AFKStatus disabled!");
    }
}