Minecraft – How to keep endermen in an arena

minecraft-commandsminecraft-java-edition

I'm making an arena minigame, and I realized a problem with the endermen: they would teleport out of the arena if left alone too long. I cannot fill in the area around the arena because the lobby is right next to it, and I really don't want to disable all the command blocks summoning the endermen. If the endermen cannot be kept in the arena, can they at least, through commands, be convinced to teleport back into the arena?

Best Answer

The rm parameter allows you to obtains targets outside an area. You can use this to teleport endermen that left back to a certain location.

The following teleports endermen that are 50 blocks away or further from the specified coordinates back to the specified coordinates.

/tp @e[type=Enderman,x=10,y=64,z=10,rm=50] 10 64 10