Creating A Custom Book

Discussion in 'Plugin Development' started by BungeeTheCookie, May 23, 2014.

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

    BungeeTheCookie

    Hello people of the Bukkit community! I was wondering how you can create a book from a .txt file: Taking all the text inside a config and putting it into a book. I know there is a limited amount of characters for each book page, so how would you take the characters from the config and split it?
     
  2. Offline

    NathanWolf

    Hmm... I wonder if InfoBook is open source- doesn't look like it, sadly. I think that does just what you're describing, though in a more config-driven way.

    If you just want to take any old text file and load it into a book, then I guess you would have to break it up yourself based on character count. Might be nice to get "fancy" and only break at the beginning of a sentence or paragraph, maybe.

    Ok, well... I was of no help! :)
     
  3. Offline

    BungeeTheCookie

    NathanWolf
    Oh, ok. Thanks anyways!

    Any other ideas..?
     
  4. Offline

    xTigerRebornx

    NathanWolf likes this.
  5. Offline

    BungeeTheCookie

    Thanks, but it uses IEssentials and other Essentials components

    xTigerRebornx
    Ok, so it looks like I can use it. The only thing IEssentials, etc is used for is for throwing exceptions and etc

    But, how can we utilize it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    xTigerRebornx

    BungeeTheCookie Look into the algorithm it uses for writing the pages, such as how it distributes it into lines.
     
  7. Offline

    BungeeTheCookie

    Is there any simpler method? Because I cannot find the base it uses to write books.
     
  8. Offline

    xTigerRebornx

    BungeeTheCookie Could try turning the whole text file into a char[] or something that can store a massive amount of chars, and loop through that, putting a char down until you hit the line length, then go to the next line, repeat that until the end of the page, and make the next page?
     
  9. Offline

    Onlineids

    Forget where I got this from but this worked for me:
    Code:java
    1. StringBuilder sb = new StringBuilder();
    2. Scanner sc = new java.util.Scanner("sample.txt");
    3. while (sc.hasNext()) {
    4. sb.append(sc.nextLine ());
    5. }
     
  10. Offline

    BungeeTheCookie

    xTigerRebornx
    Uhm... I may try that if I really want to.

    Onlineids
    How is it able to tell when the characters run over the page?
     
  11. Offline

    Onlineids

    Scanners read files if its a text it goes line by line, you make sure theres another line with .hasNextLine()
     
  12. Offline

    BungeeTheCookie

    Onlineids
    So how would you use this in the creation of a book?
     
  13. Offline

    Onlineids



    This might work with the string builder you get from before
    String[] lines = sb.toString().split("\\n");
    this will return essentialy exactly how the .text file was formated afaik.
     
  14. Offline

    BungeeTheCookie

    I know \n creates a new line, but what does \\n do? Also, does this work for like, Enters?
     
  15. Offline

    Onlineids

    Just a typo :p its \n
     
  16. Offline

    BungeeTheCookie

    Ok. thanks. :p
     
Thread Status:
Not open for further replies.

Share This Page