Commands/testfor

Counts entities (players, mobs, items, etc.) matching specified conditions.


 * Syntax


 * Java Edition


 * Pocket Edition


 * Arguments


 * player (PE: victim: target)
 * Specifies the targets to count. Must be a player name or a target selector ( is permitted to target entities other than players).


 * dataTag (optional)
 * Specifies the data tags the entities must have to match successfully. Must be a compound NBT tag (for example, ).


 * Result


 * Fails if the arguments are not specified correctly, or if player fails to resolve to one or more entities (named players must be online).


 * On success, produces a success count equal to the number of targets matching player, which can be measured by a redstone comparator facing away from the command block.


 * Examples


 * To test if Alice is online:


 * To count the number of players in survival mode within a 3-block radius of (0,64,0):


 * To count the number of zombies within a 20-block radius of (0,64,0):


 * To count the number of players currently flying:


 * To test if an arrow is in a block: