Detect AFK Players
Detects player activity based on mouse movement for the most accurate, best performing AFK detection. Mouse movement can't be faked.
This datapack is intended to be used by other datapacks and server operators.
Features:
- Accuracy: Mouse movement is a better indicator of activity than location
- Performance: Your server does way less work with this than with any of the alternatives. Keeps your MSPT low.
- Add-ons: Add just the features you want, so you don't pay a performance penalty for things you don't care about
- Simplicity: It's easy to build on top of this data pack and extend it if there's nothing that does what you want
Tags players as afk
after 3 minutes without rotating their head.
This data pack is intended primarily as a library for other data packs and commands to build on its functionality - there's no user-facing behavior.
Add-ons
Pause Day Cycle uses this data pack to detect when online players aren't actually playing so it can pause the game.
AFK Sleep allows you to sleep while players are AFK by dynamically adjusting the playersSleepingPercentage
, respecting your original value.
AFK Dim Names dims player names in chat and the player list when they go AFK.
AFK Message sends a message in chat to announce the status change to the server.
Details
This datapack detects whether a player is AFK based on their camera's horizontal rotation (the player head). This is a reliable way to detect if a player is actively playing because even tiny mouse movements are reflected in the angle of the camera. It's also impossible to change a player's camera angle without commands, but water streams can circumvent movement detection.
Usage as a library
The player tag is used to build logic that doesn't depend on when a player goes AFK. The function tags are used to execute logic as the player at the exact moment they go AFK.
The function two tags this data pack provides are afk:away
and afk:back
. These will be called as the player that has gone AFK or come back, allowing references to @s
in the functions that get called.
- If the mouse hasn't moved for 3 minutes, the player is tagged as
afk
and theafk:away
functions are executed. - Once the player has moved their head again after being tagged as
afk
, the tag is removed andafk:back
is executed.
Below is a demonstration of how to use this to kick AFK players - you may want to do this in a more complicated way, but this will work!
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
90% of ad revenue goes to creators
Support creators and Modrinth ad-free with Modrinth+