Create a written book?

Hi everyone,

I have a 6.1.0 sponge vanilla server and I’m compiling with sponge api 6.0.0 (gradle).

I’m trying to create a written book.
Here’s my current code:

if(src instanceof Player) {
	Player p = (Player) src;
	List<Text> lpages = new LinkedList<>();
	for(Report r : ReporterLab.getReports()) {
		Text head = r.toText(null);
	ItemStack book = ItemStack.builder()
	if(book.supports(Keys.BOOK_PAGES)) {
		book.tryOffer(Keys.BOOK_PAGES, lpages);
	} else {
		Text.of(TextColors.DARK_PURPLE, TextStyles.BOLD, "The Server"));
	LocalDateTime datetime =;
	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm, dd-MM-yyyy");
	book.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD,
		"Reports, as of ",

Where Report#toText(null); returns a Text made of several strings and numbers (no colors, no styles).

Whenever I run this command to get the book, the pages of the book are filled with:

“* Invalid book tag *”

However, the name (title?) and author are set correctly. book.tryOffer(...) (line 16) also doesn’t cause an error.

What am I doing wrong?

Do us a favor.

Once you’ve finished writing the book, print out the result of DataFormats.JSON.write(book.toContainer()). It will be informative.

A written book must have

  • Pages (Keys.BOOK_PAGES), each page must serialise to JSON with less than or equal to 32767 characters
  • Title (Keys.DISPLAY_NAME) less than or equal to 32 characters
  • Author (Keys.BOOK_AUTHOR)

Make sure your code meets those conditions

I did this today. It returned:

  "UnsafeData": {
    "author":"The Server",
    "title":"Book, as of 20:21, 27-06-2017"

As you can see, there are no pages, even though I’m adding a List<Text>.
Also, the data is listed as “UnsafeData”, does this mean anything?

what do you mean by that?


Okay, it seems I did something wrong. I now filled the pages with Text.of("TEXT") and pages look like


I can now see what you said about texts and JSON.

Still, the issue is not solved

The Minecraft protocol serialises Text objects as JSON (as shown here: You can serialise a Text object with TextSerializers.JSON.serialize(text) and see what the resulting length of the string is.

As for your issue, I’m not sure why it’s not working, there could be an issue with Keys.BOOK_PAGES

I wrote a book manually (in Minecraft) and wrote that to JSON. Here are the results:

  "UnsafeData" : {
        "{\"text\":\"I LIKE TO WRITE TEXT HERE.\\n\\nAND ALSO HERE\"}",
        "{\"text\":\"BUT NOT HERE\"}",