I am running a vanilla Minecraft server on my Azure account and have an idea for it that I'm not sure is possible or not. Essentially I want to set up an area, something like 8x8 chunks that is designated as a creative area.

In order to achieve this I'm thinking that I will need at least one command block running constantly checking for players entering or exiting the area and adjusting their game mode accordingly. The problem I'm having is that I can't think of or find a way to reliably detect the threshold crossing, specifically for any height.

One potential solution I've come up with is to surround the creative chunks with barrier blocks to limit the ways in which the player can leave the area, but this is not ideal.

Bonus #1: If the player attempts to fly out of the creative zone it would be nice to also teleport them to the ground so they don't die when the game mode is switched.

Bonus #2: Can I have another set of command blocks that will store/restore a players inventory when crossing the threshold.

  • Let me know if the scope of bonus #2 is too big, I was unsure if it warranted its own question. – user73272 May 11 '15 at 19:01
  • I thought for sure we just had a question specifically covering bonus #2, but now I can't find it... – John the Green May 11 '15 at 19:13
  • 1
    Bonus #1 should be possible, but bonus #2 is difficult and awkward in vanilla. The answer to this question is similar to how I would accomplish it. – SirBenet May 11 '15 at 20:36
  • You can try to switch to spigot server, then you can use specialised plugins for that - especially WorldGuard can do it automatically for any area. Or then you can load more maps at once and leave one map for creative things, with different inventories for each map (multiverse plugins) But yeah, it means to have some work with server. However, for players it will look pretty same vanilla as before. – Antoine Hejlík May 12 '15 at 12:44

This answer covers the main question and Bonus #1, but not Bonus #2.

Target selectors can be used to select a player in a cuboid area.

I'd first set up a dummy objective, which will store whether or not a player is in the area:

/scoreboard objectives add inCreativeArea dummy

As an overview, you then want to, in this order on a clock:

  1. Set everyone who is in this specific area's inCreativeArea score to 3
  2. Reduce everyone's inCreativeArea score by 1
  3. Give creative mode to anyone with an inCreativeArea score of 2, survival mode for anyone with an inCreativeArea score of below that
  4. Teleport anyone with an inCreativeArea score of 1 to the ground


The actual command for this part should look something like:

/scoreboard players set @a[X,Y,Z,dx=DX,dy=DY,dz=DZ] inCreativeArea 3

Replace the capital X, Y and Z with the coordinates of the most negative corner of the cuboid creative area, and the DX, DY, DZ with the length, height and width of the area.

This sets anyone who is in the creative area's score to 3.


/scoreboard players remove @a[score_inCreativeArea_min=1] inCreativeArea 1

This reduces everyone's inCreativeArea score by 1. People who are in the area will now have a score of 2, people who just left the area a score of 1, and others a score of 0.


/gamemode 1 @a[score_inCreativeArea_min=2,m=0]
/gamemode 0 @a[score_inCreativeArea=0,m=1]

These set the gamemodes appropriately. The m argument prevents it updating people who are already in that gamemode, which would work but spam their screen endlessly with the "Your game mode has been updated" message.


Finally, the easiest way to teleport players who have just left to the ground is a relative spreadplayers command which always chooses a location on a solid block:

/execute @a[score_inCreativeArea_min=1,score_inCreativeArea=1] ~ ~ ~ spreadplayers ~ ~ 0 1 false @p
| improve this answer | |
  • Never even thought to use a scoreboard, thanks a bunch. Also I've thought of a potential way to solve bonus #2, the goal of this was to prevent the player from using the creative area to give themselves blocks to us in the survival area. Would it be enough to run a command block on a fast clock that kills all entities in the creative zone? – user73272 May 11 '15 at 21:35
  • Just realized my mentioned idea would not entirely solve the problem. Oh well. – user73272 May 11 '15 at 21:38
  • One more clarification, I assume this would work best using the commandblock to replace a redstoneblock clock or would that cause a significant amount of overhead for the server? – user73272 May 11 '15 at 21:44
  • 1
    I implemented this last night with just a comparator clock and it works fantastically – user73272 May 12 '15 at 15:47
  • So these commands are triggered every tick to make this work? – The Matt Jul 1 '19 at 22:10

| | | command block-/gamemode 2 @a[r=2] | --------[Threshold]----------

   command block-/gamemode x @a[r=2]

This way it changes back and forth if you go past the threshold either way.

*x=other game mode which they were in before they passed the threshold

to view the format and image you need to click edit to see the diagram I made of the command blocks.

| improve this answer | |