Hello, so I am trying to setup an anti-grieving measure in vanilla which will set a player to adventure mode if they are in a certain area (defined by a rectangle), if the player is within the area then they are automatically set to adventure mode (I accomplished this very easily with - gamemode adventure @a[x=-433,y=0,z=-433,dx=866,dy=256,dz=866,gamemode=survival]. However, I am having much trouble moving them back into survival mode if they leave the area. I have tried doing so with tags, but the best I can do involves the issue that anyone inside the area oscillates back and forth between survival and adventure and anyone outside is set to survival. May anyone provide insight into how to solve this conundrum?
/execute as @a at @s if entity @s[x=-433,y=0,z=-433,dx=866,dy=256,dz=866,distance=..256] run gamemode adventure @s
(distance is required, for some reason it works everywhere if you don't include it)
/execute as @a at @s unless entity @s[x=-433,y=0,z=-433,dx=866,dy=256,dz=866,distance=..256] run gamemode survival @s
What I usually do is count how large the rectangle is and set the distance to that, for example: if x=0,y=64,z=0 and dx=10,dy=74,dz=10 the distance would be distance=..10 because the are is 10x10. But when it comes to different sizes like a wide and flat rectangle you will have to play around with different values.