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.
I can't seem to get it to work... Code: if(cmd.getName().equalsIgnoreCase("ppp")){ Book b; try { b = new CraftBook((CraftItemStack) new ItemStack(Material.WRITTEN_BOOK)); } catch (Exception e) { return false; } b.setAuthor("Kyle"); player.updateInventory(); }
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(); }
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
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.
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);
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);
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.
import org.bukkit.book.Book; gives me The import org.bukkit.book cannot be resolved I am using craftbukkit R2.
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.
KeybordPiano459 Yes you can change the page contents... setPages(). & dvdbrander This is an implementation for craftbukkit, it shouldn't just be copy pasted blindly. There's a another API that's ready-to-use as external tough: http://forums.bukkit.org/threads/simple-temp-book-api.93562/