Util Creating books with events

Discussion in 'Resources' started by The_Spaceman, Feb 15, 2018.

Thread Status:
Not open for further replies.
  1. Offline


    hello readers,

    I've made a util that lets make you books with colors, attributes and events.

    create the book (title and author can be empty ("") when you let the util open the book)
    FancyBook book = new FancyBook("title", "author");
    create a new page
    FancyBookPage page = fancyBookPage();
    FancyBookPage page = new FancyBookPage();
    create a new text component
    FancyTextComponent text = fancyTextComponent("text", ChatColor.GREEN, "italic");
    FancyTextComponent text = new FancyTextComponent("text", "green");
    you can add normal colors ("green") and ChatColors (ChatColor.GREEN)
    and the 'italic' is an attribute wich it optional (options: "bold", "italic", "underlined", "strikethrough" and "obfuscated").

    create text component with event:
    FancyHoverEvent hEvent = fancyHoverEvent(fancyTextComponent("HOVER!!!"));
    hEvent.addText(fancyTextComponent("\nMORE HOVER!!!", ChatColor.BLUE));
    //you can add more lines to a hoverEvent
    FancyClickEvent cEvent = fancyClickEvent("run_command", "/help");
    //add events to a chat component:
    FancyTextComponent eventText = fancyTextComponent("events", "blue", cEvent, hEvent);
    clickEvent types are "run_command" and "change_page"

    add chat component to a page:
    add page to book:
    book.addPage(page, page2, page3, ...);
    and then now you have made a book. you can choose a couple of options:
    ItemStack book = book.getBook();
    //returns a book with your text
    //this opens the book for the selected player
    String book = book.translateBook();
    //this returns the json of that book
    //create book
    FancyBook book = new FancyBook("book", player.getName());
    //create page
    FancyBookPage page = fancyBookPage();
    //create text component
    FancyTextComponent text = fancyTextComponent("test ", ChatColor.GREEN, "bold");
    //create hover event
    FancyHoverEvent hEvent = fancyHoverEvent(fancyTextComponent("HOVER!!!"));
    hEvent.addText(fancyTextComponent("\nMORE HOVER!!!", ChatColor.BLUE));
    //create click event
    FancyClickEvent cEvent = fancyClickEvent(runCommand, "/help");
    //add text to page 1
    page.addText(fancyTextComponent("hover ", "blue", hEvent));
    page.addText(fancyTextComponent("clickEvent", "red", cEvent));
    //create new page
    FancyBookPage page2 = new FancyBookPage();
    //add text to page 2
    page2.addText(fancyTextComponent("new page :D", ChatColor.DARK_AQUA, fancyClickEvent(runCommand, "/help"), fancyHoverEvent(fancyTextComponent("/stranded"))));
    //add pages to book
    book.addPage(page, page2);
    //print json book to console
    //open book for player
    https://pastebin.com/YMjDZeN4 FancyBook.java
    https://pastebin.com/U8jzFpwT FancyBookPage.java
    https://pastebin.com/CFC84Sc6 FancyTextComponent.java
    https://pastebin.com/ezqhyJwN FancyClickEvent.java
    https://pastebin.com/3Lid0j7S FancyHoverEvent.java

    replace the YOUR.PACKAGE.HERE to the destnation of that class
    Horsey and Zombie_Striker like this.
  2. Offline


    Nice util! Having a simple class that can handle all the json formatting is great.

    I do have one suggestion though; try moving all of the sub classes into one file. It just makes it easier for other users to copy and paste, instead of having to create a new file for each of the classes.
  3. Offline


    that was my fist option when i made a this, but then you have all these long names like "new FancyBook.FancyTextComponent("text")", you see?
Thread Status:
Not open for further replies.

Share This Page