Minecraft – way that I can stop people from standing still too long

minecraft-commandsminecraft-java-edition

I want to make a map where the player is not allowed to stand still in a certain radius of blocks (only sprint parkour, no stopping!) and if I search Google it comes up with how to create a AFK machine.

Is there a way that I can stop people from standing still?

Best Answer

Setup

/scoreboard objectives add walkDistance stat.walkOneCm
/scoreboard objectives add walking dummy

Clock

/scoreboard players set @a walking 0
/scoreboard players set @a[score_walkDistance_min=1] walking 1
/<command> @a[score_walking=0]
/scoreboard players set @a walkDistance 0

A walk distance is maintained and if the player does not move after the last execution of this command sequence, his walking score will not be set to 1 and the command will be executed on him.