1

I know you can change all players to the 'adventure' game mode within a certain radius, but is there a way to exclude certain players from this?

The server I'm in is vanilla, with 0 plug-ins/mods and therefore, no claim blocks.

I am hoping there is a way to change the gamemode of everyone in the radius to adventure mode, except for the property owner. Is this even possible?

2
  • "... everyone in the radius except for the property owner..." by that you mean everyone except the player who executes the command? Or does the command need to exclude a specific player? Much like distance is a target selector argument, many other attributes can be used as well, including name, tag, type, ... Apr 20 at 21:23
  • 1
    Hi Forgest, I've edited your post to make it a bit clearer, but if you can - take a look at @MartyCagas' question and see if you can clarify it further?
    – Robotnik
    Apr 21 at 1:40
3

To set the gamemode to Adventure of all players whose name isn't "gamer" within 32 blocks from the entity invoking the command, simply use:

/gamemode adventure @a[distance=..32, name=!gamer]

The name selector argument can be used multiple times to exclude more entities (note the requirement of " in the case spaces are present in the name):

/gamemode adventure @a[distance=..32, name=!gamer, name=!"epic gamer"]

This is one of the most commonly used ways to exclude yourself from your own commands.


Another alternative is through the use of tags and the /tag command, which will allow you to permanently mark specific players to be excluded from having their gamemode changed.

To add a tag to the calling entity (in case it's a player) and then set everyone else's withing 32 blocks mode to Adventure, use these two commands:

/tag @s add noAdventure
/gamemode adventure @a[distance=..32, tag=!noAdventure]

... or alternatively you can set the mode for everyone having no tags:

/gamemode adventure @a[distance=..32, tag=]

To remove a tag from yourself use /tag @s remove noAdventure, to see all current tags on yourself, use /tag @s list.


Another approach coming to mind is taking advantage of knowing the number of players participating so that you would exclude yourself. If exactly 10 players are present in the 32 block area, then to set everyone else's mode except the one of yourself, use:

/gamemode adventure @a[distance=..32, limit=9, sort=furthest]

This leverages the fact the furthest entities will be targeted first and if there are at least 9 other players within the range with you, they will be targeted before you and the command will end before reaching you as well.


One last approach I can think of can be handy in case you are the only player nearby in Creative (say, after having built an adventure map for others). Then to set everyone else nearby to Adventure, the command once again becomes simple:

/gamemode adventure @a[distance=..32, gamemode=!creative]

A bonus command - to set everyone's game mode back to Survival from Adventure, use:

/gamemode survival @a[gamemode=adventure]

I hope one of these methods will come in handy. In case of any questions, don't hesitate to ask.

I invite you to read more about the target selector arguments in the excellent wiki article about commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.