Compatibility
Minecraft: Java Edition
Platforms
Supported environments
75% of ad revenue goes to creators
Support creators and Modrinth ad-free with Modrinth+Creators
Details
Detect AFK Players
Detects player inactivity based on head rotation - simple, accurate, and fast. Intended as a dependency for other datapacks and server operators.
This data pack doesn't do much without add-ons (better performance), so you'll probably want to download one of those too.
Core Functionality
- Tags players as
afk
after 3 minutes - Detection based on head rotation, more accurate than position
- Significantly better performance than alternatives
- Modular (see below for add-ons)
To configure how long it takes to become AFK, use the command below. By default, this is set to 3600 (which is 3 minutes).
/scoreboard players set .threshold afk.settings NUMBER_OF_TICKS
To enable players using /trigger afk
, use the following command. No players are allowed to become AFK manually unless enabled by an admin.
/scoreboard players enable PLAYER afk
Add-ons
- Pause Day Cycle - Pauses time when all players are AFK
- AFK Sleep - Allows sleeping when players are AFK
- AFK Dim Names - Player names are dimmed when AFK
- AFK Message - Chat notifications for player status
Performance
Common AFK detection methods check X/Y/Z, inventory changes, and block interactions - often on every tick. Instead, this data pack does a single head rotation NBT check per player every 1.5 seconds, resulting in a significantly less computation as compared to alternatives, sometimes by up to two orders of magnitude.
The head rotation method also eliminates false triggers from automation such as water streams.
API
Two function tags are provided:
afk:away
- Executed as player on AFKafk:back
- Executed as player on return
Additional documentation is provided on GitHub, such as all the stable scoreboard objectives and how to use them.
Example implementation:
kick-afk-players/data/afk/tags/functions/away.json
{ "values": ["afk_kick:kick"] }
kick-afk-players/data/afk_kick/functions/kick.mcfunction
kick @s AFK