This question already has an answer here:
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.