What is the best way to make a PVP free zone, whether it be using commands or by using settings, for a Minecraft realm.


Solution 1:

Put them on a team

Scoreboard teams have a friendly fire option, which, when it is set to false, makes it impossible for players on the same team to hurt each other.

First set up the team itself

/scoreboard teams add noPvP
/scoreboard teams option noPvP friendlyfire false

Place two command blocks on a clock (or use repeat/chain command blocks from 1.9) and have them run

/scoreboard teams join noPvP @a[team=!noPvP,x=X,y=Y,z=Z,r=R1]
/scoreboard teams leave noPvP @a[team=noPvP,x=X,y=Y,z=Z,rm=R2]

Replace X, Y, Z with the coordinates in the center of your PvP-free zone. R1 and R2 are the radii of the zone. They are different since you don't want the literal edge-case where a player constantly joins and leaves the team. By making R2 a few blocks larger than R1, the border is a bit more "fuzzy".

Note that players can't be on two teams at the same time, meaning that if you already have teams set up, things are a bit more complicated. You could, however, "remember" the originally assigned team by assigning a scoreboard tag corresponding to the team.