Util Creating books with events

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

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

    The_Spaceman

    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)
    Code:
    FancyBook book = new FancyBook("title", "author");
    
    create a new page
    Code:
    FancyBookPage page = fancyBookPage();
    //or
    FancyBookPage page = new FancyBookPage();
    
    create a new text component
    Code:
    FancyTextComponent text = fancyTextComponent("text", ChatColor.GREEN, "italic");
    //or
    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:
    Code:
    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:
    Code:
    page.addText(textComponent);
    
    add page to book:
    Code:
    book.addPage(page);
    //or
    book.addPage(page, page2, page3, ...);
    
    and then now you have made a book. you can choose a couple of options:
    Code:
    ItemStack book = book.getBook();
    //returns a book with your text
    
    openBook(player);
    //this opens the book for the selected player
    
    String book = book.translateBook();
    //this returns the json of that book
    
    example:
    Code:
    //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(text);
    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
    System.out.println(book.translateBook());
    
    //open book for player
    book.openBook(player);
    
    code:
    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

    Zombie_Striker

    @The_Spaceman
    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

    The_Spaceman


    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