Minecraft – Select player not in a specific position

minecraft-commandsminecraft-java-edition

I am making an AFK machine where people go stand when they want to be AFK in vanilla Minecraft. So I am trying to detect players that is still in the AFK team (@a[team=AFK]) but not in the place where you stand to be AFK. I then want to remove them from the AFK team.

The AFK "place" (where you stand to be AFK) is cubic. Is it possible to detect players not in this 3x3x2 cubic place rather than within a radius?

Best Answer

Use the dX, dY, dZ selectors

Setup:

/scoreboard objectives add inAFK

Clock:

/scoreboard players set @a inAFK 0
/scoreboard players set @a[x=<X>,y=<Y>,z=<Z>,dX=<X length>,dY=<Y length>,dZ=<Z length>] inAFK 1
/scoreboard players join <Team Name> @a[score_inAFK_min=1]
/scoreboard players leave <Team Name> @a[score_inAKF=0]