Well, if you want an alternative method, use villagers. Just create a small shack with a villager and a door. You can make it really small, and hook it up with pressure plates.
Now villagers will go outside as soon as it get light, and will go inside again when it gets dark. Using this system you have a day-night system.
To make it a little secure you can fence the shack in, leaving just a small space for him to roam around.
If you need some more details feel free to ask, I kept my explanation extremely basic.
I have two possible solutions for you.
First Solution
If you are trying to select a player using the selector relative to where the player is located from a specific coordinate, the selector code doesn't except the '~' character like many commands do to communicate relative coordinates. Instead use dx, dy, & dz. As an example, using the numbers from your execute command
execute @p[x=X,y=Y,z=Z,dx=10,dy=0,dz=15] ~ ~ ~ setblock 400 15 400 dirt 0 replace
This will select a player remotely, as you described above, if your command block is far away (within 16 loaded chunks I believe), and will set up a "volume" or a "box" that is x=~10, dy=~0, and dz=~15 that has an origin (starting corner) at the specific coordinate x=X, y=Y, & z=Z, where X, Y, & Z are positive or negative integers: decimal numbers are not excepted.
As long as the location/zone where the player needs to be detected isn't moving to some other location in the world, this should work just fine.
Second Solution
If the player walking over blue stained glass, for example, could be used to trigger your event instead, here's how you might accomplish that.
execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stained_glass 11 setblock 400 15 400 dirt 0 replace
The documentation from the official minecraft wiki looks like this
execute <entity> <x> <y> <z> detect <x2> <y2> <z2> <block> <data> <command …>
where <data>
is where you would enter the data value of the color of glass you wish to use to trigger a specific event (11 being blue). <x2> <y2> <z2>
are just the coordinates of the block you'd like to detect. In the example I used ~ ~-1 ~
which just detects for a blue stained glass block below all players (which the all players @a selector can be replaced with whatever selector you happen find best to use).
Hopefully this helps.
As a Warning
Based on what I have read from the wiki, it may cause the execute command to fail if a player who does not have permission to execute the specified command is selected. Which means, if your players are meant to be in survival or adventure mode, you may have to use the execute command on an invisible entity (such as an armor stand with NBT tags set to {Marker:1,Inivisible:1}
) to detect whether a player has entered the specified area, and then trigger the event that way.
Best Answer
No, this is impossible unless you want to add command blocks for every block type.