Book API to tide you over

Discussion in 'Resources' started by codename_B, Aug 7, 2012.

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

    codename_B

    Till Bukkit pulls either my Book API or one of their own, here's my one to tide you over!
    You will need both of these somewhere in your project, feel free to rebase the packages as you see fit and also feel free to edit as you please.

    Only license is if you use it, say somewhere that I wrote this bit :)

    (interface, documentation etc)
    http://pastie.org/4407418
    (implementation, requires craftbukkit)
    http://pastie.org/4452153

    Example of use

    Code:
    public void setLines(ItemStack book, String[] lines) {
        Book b;
        try {
            b = new CraftBook((CraftItemStack) book);
      } catch (Exception e) {
      return;
      }
      b.setLines(lines);
    }
    
    Now with added plugin!

    http://forums.bukkit.org/threads/fun-bookbio-v1-0-let-your-players-write-their-tale-1-3-r1.91652/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
    Eviltechie, jtjj222, Icyene and 6 others like this.
  2. Offline

    bartboy8

  3. Offline

    codename_B

    Well, for a start, you're not adding anything to the players inventory.

    Code:
    if(cmd.getName().equalsIgnoreCase("ppp")){
        Book b;
    CraftItemStack book = new CraftItemStack(Material.WRITTEN_BOOK);    
    try {
            b = new CraftBook(book);
        } catch (Exception e) {
            return false;
        }
        b.setAuthor("Kyle");
        player.getInventory().addItem(book);
        player.updateInventory();
    }
     
  4. Offline

    bartboy8

    codename_B
    I still can't get it to work. I get an error on CraftBook at line 74:
    Code:
    s.tag.setString("author", author);
    Its also a null pointer exception
     
  5. Offline

    codename_B

    Which vresion of it are you using? Paste me the CraftBook code - I may need to send you my latest chenges (tag doesn't instantiate itself so I need to call that in the constructor)

    http://pastie.org/4452153
    fixed

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

    bartboy8

  7. Offline

    darkhelmet

    If I wanted to drop a written book, after setting the contents, how could that work?

    Code:
    block.getWorld().dropItemNaturally(block.getLocation(), b);
    Doesn't work because dropItemNaturally accepts an ItemStack and casting b back won't work.

    I looked at your example above, where you give the player "book" and not the "b" CraftBook, so I tried it but all I get is a written book without any of the content the code I supposed to add:

    Code:
    Book b = null;
    CraftItemStack book = new CraftItemStack(Material.WRITTEN_BOOK);
    try {
        b = new CraftBook(book);
      } catch (Exception e) {
     
      }
     
    String[] content = {"Hi there"};
     
    b.setTitle("TEST BOOK");
    b.setAuthor("darkhelmet");
    b.setPages(content);
    block.getWorld().dropItemNaturally(block.getLocation(), book);
     
  8. Offline

    codename_B

    darkhelmet due to a quirk of minecraft, this is how it needs to be done.

    Code:
            Book b = null;
            CraftItemStack book = new CraftItemStack(Material.WRITTEN_BOOK);
            
            book = (CraftItemStack) block.getWorld().dropItemNaturally(block.getLocation(), book).getItemStack();
    
            try {
                b = new CraftBook(book);
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            String[] content = {"Hi there"};
    
            b.setTitle("TEST BOOK");
    
            b.setAuthor("darkhelmet");
    
            b.setPages(content);
    
     
  9. Offline

    bartboy8

    For me getTitle() returns nothing. I am getting the item in my hand which is a written book:
    Code:
        Book b121;
        CraftItemStack book121 = new CraftItemStack(player.getItemInHand());
        try {
            b121 = new CraftBook(book121);
        } catch (Exception e) {
            return false;
        }
        player.sendMessage(b121.getTitle());
    It just sends a blank line.
     
  10. Offline

    codename_B

    Do it like this
    CraftitemStack book121 = (CraftItemStack) player.getItemInHand();
     
  11. Offline

    bartboy8

    Thanks!
     
  12. Offline

    dvdbrander

    import org.bukkit.book.Book; gives me The import org.bukkit.book cannot be resolved
    I am using craftbukkit R2.
     
  13. Offline

    KeybordPiano459

    I'm looking at some comments, and I'm noticing stuff about the book author/title. Is it possible to actually write stuff in the book? Also, I can pretty honestly say that I've never used an API before, so I'm just gonna ask, where do I put it? Right now I'm putting it as another class in my package and I'm getting lots of errors.
     
Thread Status:
Not open for further replies.

Share This Page