Commands/execute

is a versatile command that executes other commands in a variety of scenarios:


 * Syntax


 * Java Edition
 * Modifier sub-commands can change how the command is run:
 * executes a command using the entity  (but doesn't change position). If the   doesn't have an eye anchor point, the command will become anchored to the feet of the previous executor (Not the specified entity).
 * executes a command using the position, rotation, and dimension of the  (but doesn't change entity).
 * executes a command using the position of.
 * executes a command using the position (x y z) of the  but nothing else.
 * executes a command after aligning the current position to the block grid (rounding down),  is any combination of     and   (for example: , ,  and  ).
 * Examples:
 * using  will become
 * using  will become
 * executes a command as though the execution position is facing.
 * executes a command as though the execution position is facing the entity's eyes or feet.
 * executes a command as though the executor is rotated in the direction of the entity.
 * will run the command as though the executor is rotated in the specified direction.
 * executes a command as though the executor is in the specified dimension.
 * will make the rest of this command use feet or eyes for ^ ^ ^ coordinates or facing commands.
 * Conditional sub-commands can prevent the command from running at all. All conditions must be met for the test to pass and the command to run. Alternatively, the run portion can be excluded, in which case the command will return whether the test passed:
 * executes a command if (or unless)  matches.
 * executes a command if (or unless) the region between  and   matches.
 * executes a command if (or unless) the entity or block has any NBT data in.
 * executes a command if (or unless)  exists (returns 1 or more entities).
 * executes a command if (or unless) 's score relates to  's score based on the chosen criterion.
 * executes a command if (or unless) 's score is in the   (ie ,  ).
 * As replacement for, a new sub-command   lets you store the result or success of a command somewhere:
 * is the result of a command, which replaces these old stats:,  ,  ,.
 * is how many times the command was successful. This is usually  or , but if the command split up (for example  ) then it may be more than  . This replaces.
 * The value will be stored when the full command has finished executing.
 * If a command isn't successful ( is  ),   will always be set to.
 * It will be made clear what the expected result of each command is.
 * The value is stored into the scoreboard under  and.
 * The  must exist, but unlike with   you don't need to set an initial value for.
 * The value is stored in the nbt data at  of the block at   as a byte, double, float, int, long, or short.
 * The value is stored in the nbt data at  of one   entity as a byte, double, float, int, long, or short.
 * Like,   can't modify player NBT. NBT data inside the   key of items in the player's   or  is an exception and can be modified by.
 * The value is stored in the  or   setting of the boss bar with ID.
 * Data paths look like this:.
 * means foo's child called bar.
 * means element 0 of bar.
 * "quoted strings" may be used if a name of a key needs to be escaped.
 * Examples:
 * All sub-commands can be chained together.
 * After every sub-command players need to write another sub-command.
 * When the player are done with chaining sub-commands,  lets them write the actual command to be executed.
 * is not allowed before the command.
 * Example:
 * All sub-commands can be chained together.
 * After every sub-command players need to write another sub-command.
 * When the player are done with chaining sub-commands,  lets them write the actual command to be executed.
 * is not allowed before the command.
 * Example:
 * Example:


 * Bedrock Edition


 * An alternate syntax allows the command to be executed only if a specific block is detected:



Color added to make reading easier.


 * Arguments


 * origin: target
 * Specifies the target to be the command's executor. Must be a player name or target selector. If more than one entity is selected, the command will be run once as each of them.


 * position: x y z
 * Specifies the position from which to run the command. x and z must be within the range -30,000,000 to 30,000,000 (inclusive). Coordinates specified with tilde notation are relative to the target, not to the position of the command's execution.


 * command: command
 * Specifies the command to be run. Must be a valid command.


 * detectPos: x y z ( mode only)
 * Specifies the position of the block to check. x2 and z2 must be within the range -30,000,000 to 30,000,000 (inclusive). May use tilde notation to specify distances relative to (x,y,z).


 * block: Block ( mode only)
 * Specifies the block ID which the block at (x2,y2,z2) must match for the command to run. block must be a valid block id (for example, )


 * data: int ( mode only)
 * Must be a valid block data for that type of block or  to match any block data.


 * Result


 * Fails if arguments are not specified correctly, if entity fails to resolve to one or more valid entities (named players must be online), if the checked block is not of the correct block id, data or state, or if the specified command fails.


 * On success, executes the specified command as if executed by the specified target(s) with operator-level permission at the specified coordinate.


 * Examples


 * To summon lightning bolts at the positions of every zombie:


 * To summon lightning bolts at the positions of every zombie standing on any type of sand:


 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):

History
Befehl/execute 命令/execute