Checking for book page text length

Discussion in 'Plugin Development' started by PDKnight, Oct 5, 2015.

Thread Status:
Not open for further replies.
  1. Hey, Bukkit, today I've been working on my CGeo_ plugin and I don't know what to do now. For better explanation I've made a screenshot:
    [​IMG]
    Last log is "Najdena uplnou nahodou. TFTC", so as you can see, the sentence showed above was cut and not moved to second page. Code:
    Code:java
    1. public ItemStack CGmodifyEmptyBook(ItemStack book, String chest_name) {
    2. BookMeta bm = (BookMeta) book.getItemMeta();
    3. List<String> found = pl.getConfig()
    4. .getStringList("found." + chest_name);
    5. String book_log_str = "";
    6. for (Object o : found) {
    7. String log_path = "log." + chest_name + "." + o;
    8. String log = pl.getConfig().contains(log_path) ? "&8: " + pl.getConfig()
    9. .getString(log_path) : "";
    10. book_log_str += p((found.indexOf(o) + 1) + ". " + o + log
    11. + "&r\n");
    12. }
    13. bm.setAuthor(ChatColor.AQUA + "CGeo_");
    14. bm.setTitle(ChatColor.AQUA + "GeoChest Log");
    15. bm.addPage(parseColors(pl.getConfig().getString("log_who_found"))
    16. + "\u00a70\n\n" + book_log_str);
    17. book.setItemMeta(bm);
    18.  
    19. return book;
    20. }

    Config:
    Code:
    log:
      Mountain:
        PDKnight: a
        Forest_18: Najdena uplnou nahodou. TFTC
    How to check for page size to move text to another page? Thanks in advance :)
     
    Last edited: Oct 7, 2015
  2. Have you tried looking in the JavaDocs?
     
    Gonmarte likes this.
  3. I know
    Code:java
    1. bm.getPage(i).length();
    gets the length of a page, but there are also \n's, so when I use 14 \n's, the word after them won't be on the first page, it will be hidden. So the question is: How to make it so the word after 14 \n's will appear on the second page?


    @Gonmarte help, if you can ^ ;)
     
  4. I'm not sure about this but can you make it so when there are 10 things then it moves to page 2?
     
  5. @Binner_Done Sure I can, but as you can see, the tenth player was logged and I don't know how many lines the log will take, so the message was cut :(
     
  6. bumpidy bump... :D
     
  7. @PDKnight

    Well, you can add 14 to the value before you divide it up. Assuming 14 is the most new lines you will have.
     
Thread Status:
Not open for further replies.

Share This Page