Minecraft – How to make a spot to enter codes

minecraft-java-edition

I would like to make a Minecraft minigame map where you can enter a code to get something. Here is how I would like it to work.

When you first join you get a written book inside it says:

Instructions:
Bla bla bla
Click "here" if you have a code.

Then if you click "here" it gives you a book and quill that says:

Enter code below:
Code:

Then they type a code, sign, close it and title it "code". Then takes it and gives them a reward or something.

Best Answer

There are two methods that come to mind:

Book and Quill

If you want to use the book and quill, you could detect what metadata the book had in it by using this command:

/testfor @p {SelectedItem:{id:minecraft:writable_book,tag:{pages:["CODE"]}}}

You can replace @p by whatever Target Selector (+Arguments) you like, but note the space after @p. This also works for written books with a specific title.

 /testfor @p {SelectedItem:{id:minecraft:written_book,tag:{title:"TITLE",pages:["CODE"]}}}

Check the wiki page for item NBT structure.

Item Name

As has been suggested, you could test for the name of an item (like in the map The Code by JesperTheEnd).

/clear @p paper 0 0 {display:{Name:"CODE"}}