1

/testfor written book in inventory

q2u's Avatar q2u3/31/18 11:03 pm
1 emeralds 1.4k 5
4/14/2018 4:51 pm
ShelLuser's Avatar ShelLuser
Hello!

I am setting up a command block to give a book to players when they enter the server. So setup a command block to test for it.

/testfor @p[r=10] {Inventory:[{id:"minecraft:written_book",tag:{title:"Community Agreements"]}}]}

I keep getting the following error:

[03:50:37] q2u did not match the required data structure

Any assistance would be greatly appreciated.

The book itself works ok. here is the command for it:

/give @p written_book 1 0 {pages:["{\"text\":\"By participating as a community member on our server, I agree to...\",\"bold\":true}","\"\",{\"text\":\"Respect Everyone.\",\"bold\":true},{\"text\":\"\\nThis includes Players, Moderators, and all staff members. Respect simply means treating others with common decency, courtesy, as you would want someone to treat you.\",\"color\":\"reset\"}]","{\"text\":\"If someone asks you to stop doing something (like for example you are in their house and they ask you to leave), please do so.\"}","[\"\",{\"text\":\" Lift up others. \",\"bold\":true},{\"text\":\"\\nCompliment, give advice and encourage new players. Making fun of someone for an aspect of themselves (Their weight, religion, sexual preference, ect) isn\\u2019t what this community stands for.\",\"color\":\"reset\"}]","[\"\",{\"text\":\"Keep the chat clean.\",\"bold\":true},{\"text\":\"\\nParticipating in Minecraft chat is an experience we\\u2019d all like to enjoy. We\\u2019d prefer if you didn\\u2019t advertise, repeat messages over and over (aka spam) or curse in this community.\",\"color\":\"reset\"}]","[\"\",{\"text\":\"Be Authentic to myself.\",\"bold\":true},{\"text\":\"\\nThere\\u2019s no need to act like anyone else or pretend to be someone you aren\\u2019t. You are the most awesome when you are yourself, so please don\\u2019t try to act like another player, impersonate or disguise.\",\"color\":\"reset\"}]","[\"\",{\"text\":\"Focus on having fun, not making money.\",\"bold\":true},{\"text\":\"\\nOur community is a place to relax, have fun, and unwind. We respectfully ask that you don\\u2019t advertise other servers, youtube channels, games ect.\",\"color\":\"reset\"}]","{\"text\":\"There is a time and place for that, and we\\u2019d like to keep our server as a space free from those distractions.\"}","[\"\",{\"text\":\"Honor the power of language.\",\"bold\":true},{\"text\":\"\\nLanguage is a very powerful tool. It can build people up, or tear them down. As a member of our community, please don\\u2019t use language to insult, demean, or belittle others.\",\"color\":\"reset\"}]","[\"\",{\"text\":\"Honor the rules of Minecraft.\",\"bold\":true},{\"text\":\"\\nEvery one comes to our server to have a good time. Those that attempt to break the game, whether through a hacked client, cheat codes or other means, lessen the good time had by all and will be asked to leave.\",\"color\":\"reset\"}]","[\"\",{\"text\":\"Respect consent of others.\",\"bold\":true},{\"text\":\"\\nVery simply put, ask for permission before messing with someone else's stuff. (Some may call it griefing to mess with someone else's build without their permission) Stop if you are asked to stop.\",\"color\":\"reset\"}]","[\"\",{\"text\":\"Keep the waters clear.\",\"bold\":true},{\"text\":\"\\nWe\\u2019ve all felt extremely stressed from bullies and other nasty people. This community is a place to relax and enjoy the company of others, not a place to instigate feelings or anger, frustration or shame (Some may call this trolling).\",\"color\":\"reset\"}]","{\"text\":\"Players that show through their actions, that they no longer agree to the community agreements will be given some time to get to an emotionally calm place and given the right resources to make sure this community maintains itself as a safe, fun place to play.\"}"],title:"Community Agreements",author:"Mod Team"}
Posted by q2u's Avatar
q2u
Level 1 : New Miner
0

Create an account or sign in to comment.

5

1
04/14/2018 4:51 pm
Level 57 : Grandmaster Engineer
ShelLuser
ShelLuser's Avatar
I know this is an older thread but there is a much better solution for this. See, the problem is that you're more or less assuming that players will have this book in their inventory at all times, which doesn't have to be the case. So if they store the book somewhere, then log off and back on again the system would automatically give them the book again. Something I'd consider highly annoying!

Solution: use the scoreboard. In specific: use tags. Whenever a player gets the starting book tag them with the "gotbook" tag. This way all you have to do is check for that tag to be present.

So... Start with a command block which contains: /give @p[tag=!gotbook] minecraft:written_book 1 0 {}.

This makes sure that a player which doesn't have the gotbook tag will get the book.

Now, place a conditional chain commandblock behind it which contains: /scoreboard players tag @p[tag=!gotbook] add gotbook.

This makes sure that the tag gets added to the player.

As a result all players will get one book no matter what.
1
04/01/2018 11:50 am
Level 1 : New Miner
q2u
q2u's Avatar
Hello,

Yes Iwe are running 1.12.2. I fixed the bracket issue.

With inventory: shouldn't this command return true if it anywhere in the inventory?

I agree Scoreboard and Tags are way powerful feature. I am glad they are making them easier to use in 1.13.
1
04/01/2018 1:21 pm
Level 29 : Expert Engineer
SUPERIONtheKnight
SUPERIONtheKnight's Avatar
Yes the command will return true when the book is placed anywhere in the inventory, but you must also be within a 10 block radius from the command block or it will fail. If you don't want this and want it to work no matter where you are, you'll have to remove the [r=10] which should result in the following command:

/testfor @p {Inventory:[{id:"minecraft:written_book",tag:{title:"Community Agreements"}}]}

~SUPERI0NtheKnight
1
04/01/2018 2:02 amhistory
Level 29 : Expert Engineer
SUPERIONtheKnight
SUPERIONtheKnight's Avatar
Due to the commands you are using, I'm going to assume you are using 1.12.2. If this isn't the case, just let me know and I will adjust my answer for the appropriate version.

When using your testfor command, I don't receive the same error. This is because you have an extra "]". Here is the fixed command: /testfor @p[r=10] {Inventory:[{id:"minecraft:written_book",tag:{title:"Community Agreements"}}]}

That command will work if the player is both holding the book, and is within a radius of 10 from the executor(In your case, the command block). If this isn't the case, you will get the error you mentioned in your post:
[03:50:37] q2u did not match the required data structure

If you are still getting this error while you are next to the command block and holding the book, make sure that it's turned on and is actually running the command.

Also your book command seems to have nothing on page 2, Is this Intentional?

Now with all of that said, may I recommend looking into tags?(Note: This link is for 1.13. If you want a command for 1.12, add the following right before tag: "scoreboard players ") There isn't really anything that /testfor can do that tags can't. In fact, I'd argue that tags can do more. Something else to note is that /testfor is going to be removed in 1.13 whereas tags are simply having their syntax changed.

I hope this info helps you. If you need help with anything else, Let me know. :)
~SUPERI0NtheKnight
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome