Books

Discussion in 'Spigot Plugin Development' started by ItsWill, May 16, 2015.

  1. Hey, there are no errors in this code. The title and author works perfectly fine, however I cannot open the book.
    PHP:
    case LEATHER_CHESTPLATE:
                 
                //teleportInWorld(player);
                player.sendMessage(ChatColor.GREEN + "You have been teleported to " + ChatColor.GRAY + "Kitzer" + ChatColor.GREEN + ".");
                ItemStack star = new ItemStack(Material.NETHER_STAR);
                ItemMeta star1 = star.getItemMeta();
                ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
                BookMeta meta = (BookMeta) book.getItemMeta();
                meta.setTitle(ChatColor.GREEN + "" + ChatColor.BOLD + "Kitzer" + ChatColor.GRAY + "" + ChatColor.BOLD + " Rules");
                meta.setAuthor(ChatColor.GRAY + "mansionwill");
                meta.addPage(
                        ChatColor.GREEN + "" + ChatColor.BOLD + "Kitzer" + ChatColor.GRAY + "" + ChatColor.BOLD + " Rules" +
                        ChatColor.GREEN + "lel" +
                        ChatColor.GREEN + "lol");
                star.setItemMeta(star1);
                book.setItemMeta(meta);
                player.getInventory().setItem(8, book);
                player.closeInventory();
                break;
                default:
                    player.closeInventory();
                break;
    Help would be appreciated.
     
    #1 ItsWill, May 16, 2015
    Last edited: May 16, 2015
  2. Ok to create a book you need a few requirements: An itemstack that is a written book, a bookmeta, set the title of the book, set the author of the book, set the book's meta to bookmeta, and add pages. If my example doesn't work, it is something else that is going on in your plugin. Hope I helped!

    My example:
    Code (Text):
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);

    BookMeta bookMeta = (BookMeta) book.getItemMeta();
    championMeta.setTitle(ChatColor.DARK_RED + "TITLE HERE");
    championMeta.setAuthor("AUTHOR HERE");

    bookMeta.addPage(ChatColor.DARK_RED + "Page Text Here\n" + "MORE TEXT\n");

    book.setItemMeta(bookMeta);
     
    • Informative Informative x 1