I just made a minecraft server and was wondering if in the server it would be possible to change a player's gamemode when they visit someone else's building(s) (this excludes the owner of the building).

I used the /testfor command but I'm not sure how to select a specific land and change the game mode of the player on it.

  • assuming you know some things about minecraft commands, you could make it so that when someone gets within a certain range which would be the area of the building, they're switched to a different gamemode – Riftcaster Sep 6 '16 at 16:24

Selectors (you should probably use @a for this) can have "Selector arguments". The ones you're interested in for selecting a specific area are:

  • x, y, z - the coordinates for the starting point of the selection, useless without at least one of the three below:
  • r - the max radius that a player can be from the starting point (like a sphere)
  • rm - the min radius that a player can be from the starting point (so targets anyone outside the sphere)
  • dx, dy, dz - the max x, y, and z that a player can be from the starting point (like a cuboid)

Using a radius is the easiest method. If the build is at 20, 64, -10 for example, you could change your commands to:

/gamemode 1 @a[x=20,y=64,-10,r=15]

Which sets the gamemode of anyone within 15 blocks of that point to creative.

With the cuboid selectors, your starting point should be the corner of the cuboid with the lowest coordinates on all axis (so lowest north-western).

dx, dy, dz should then be the positive width, height, and length of the cuboid, as such:

Cuboid selectors

These are more complicated than a radius selector, which you might want to stick with, but will allow you a more accurate area if your build area is cuboid.

Two more selector arguments you should use for this, along with the area selection, are m and name.

  • m stands for gamemode, which means you can set layers to survival only if their in creative, and vice versa, to avoid repeatedly changing the gamemode of someone already in the gamemode you want them in
  • name will allow you to "exclude the owner of the building"

Your final command should look something like:

/gamemode 1 @a[x=20,y=64,-10,r=15,m=!1,name=!LyadLaphir]

Which changes the gamemode to creative for anyone within 15 blocks of 20, 64, -10, if they're not already in creative, and if their name is not "LyadLaphir" (the !'s mean "not").

|improve this answer|||||
  • dude thx alot, but when i do the command in using dz, dy , dx it changes my gamemode where ever i go – Iyad Laphir Sep 8 '16 at 15:41
  • @lyadLaphir Could you paste the command you're using? Remember that dx,dy,dz are positive offsets from the starting point, so if you want from X=500 to X=510, then you should do x=500,dx=10, and not x=500,dx=510. – SirBenet Sep 8 '16 at 16:39
  • dude it works and u just helped my server become more widespread.thx :) – Iyad Laphir Oct 15 '16 at 15:31
  • or dude cause im a noob at this place what do click to vote – Iyad Laphir Oct 15 '16 at 15:51
  • @lyadLaphir No problem, there should be a clickable checkmark to the left of my question for accepting the answer. – SirBenet Oct 15 '16 at 17:37

This isn't as complex or as fine as the other most popular answer, but I hope it will do.

You can place a powered repeating command block underneath a person's home, and simply use

/gamemode 1 @a[r=whateveryouwant,m=!1]

If you want to exclude a certain person or team, use @a[team=!xxx] or @a[name=!xxx], because an exclamation point before the selector means "not".

|improve this answer|||||
  • whoops! ignore those last two lines! – Nathan Jun 7 '18 at 8:28
  • You should be able to edit your own posts. – DJ Pirtu Jun 7 '18 at 8:57

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