What you are looking for looks something like this:
{Inventory:[{id:minecraft:written_book,tag:{pages:[0:"\"Test\""]}}]}
But the teleport command does not support NBT tags.
However, there is a workaround using scoreboards.
First add a scoreboard objective:
/scoreboard objectives add HoldingBook dummy HoldingBook
Then run these 2 commands on a fast clock:
/scoreboard players set @a HoldingBook 2 {Inventory:[{id:minecraft:written_book,tag:{pages:[0:"\"Test\""]}}]}
/scoreboard players remove @a HoldingBook 1
Now, you can teleport the players holing a written book with the word "Test" on the first page, and for example on team blue;
/tp @a[score_holdingbook_min=1,team=blue] <your-coords>
Hope this helps.
If you want to detect blocks, then /testforblocks is what you're looking for. /testfor is used to find entities, such as players, mobs or items.
/testforblocks is used as follows:
testforblocks <x1> <y1> <z1> <x2> <y2> <z2> <x> <y> <z> [mode]
from Minecraft Wiki:
Arguments:
x1 y1 z1
and x2 y2 z2
:
Specifies two opposing corners of the
region to use as the pattern to test for (the "source region"). x1,
z1, x2,
and z2
must all be between -30,000,000 and 30,000,000
(inclusive, without the commas), and y1 and y2 must be between 0 and
255 (inclusive). May use tilde notation to specify coordinates
relative to the command's position. The number of blocks in the source
region must not exceed 524,288.
x y z
Specifies the lower northwestern
corner (the corner with the most-negative values) of the region to be
checked (the "destination region"). x and z must both be between
-30,000,000 and 30,000,000 (inclusive, without the commas), and y must be between 0 and 255 (inclusive). May use tilde notation to specify
coordinates relative to the command's position. Source and destination
regions may overlap.
mode
(optional)
Specifies how to match blocks.
Must be one of:
all
— every block in the source and destination
regions must match exactly.
masked
— air blocks in the source region
will match any block in the destination region. If not specified,
defaults to all.
To use testforblocks, you will need an area on your map to compare against - this will need to be in a loaded chunk, so I would put it underground and out of sight somewhere.
Best Answer
/testfor @e
will output a signal strength based on how many entities it finds. For example, if 5 entities are found, the signal strength outputted will travel 5 blocks.To test for exactly one entity, you can do something like this with and add on an AND gate:
Alternatively, you can use another command block with the 'testforblock' command in it, testing for if the first command block has succeeded exactly once. The setup should look something like:
Where X Y Z are the coordinates of the first command block, and the comparator should come off of this second command block.