I need a command to stop a specific person from entering a radius. Lets call this player 'Bob'. I need Bob to not be able to entering an area.
I have tried clock running into '/testfor Bob [r=2]' and run that into a comparator, to tp them elsewhere, yet that didnt work. I also tried /execute @e[type=Bob] ~ ~ ~ /testfor @a[r=2] yet that would find entities with that name, not players.
After seeing this, I decided to play around and attempt to create something like this with pretty good results actually. It almost works just like a barrier.
I have it set up so if you get within range, it will rubberband you back to your xprevious and zprevious positions.
first I created an invisible, invulnerable, marker, NoGravity, custom named "Oldpos" to mark the player's previous position.
The idea is to teleport the player to the armor stand if within range, which should be a tick behind in position from the player at the time as long as the armor stand's position is updated last in the tick.
on a repeating command block: in 1.13
/execute as @p[distance=..5] at @s as @e[name=Oldpos] at @s run tp @p ~ ~ ~
or in 1.12:
/execute @p[r=5] ~ ~ ~ tp @s @e[name=Oldpos]
(or something like that, I'll need to check. It's been some time since I worked with 1.12.2 commands)
On an unconditional, always on chain command block linked to the repeating block in 1.13:
/execute as @p at @p run teleport @e[name=Oldpos] ~ ~ ~
/tp @e[name=Oldpos] @p
If you accidentally end up with this on with Oldpos also in range, you will get stuck, and will need to manually teleport Oldpos away
also, this would be for single player.
you would have to adjust it for multiplayer to have player create the armor stand, and be more specific in the player targeting.