NoSuchMethodError - Book metadata error

Discussion in 'Plugin Development' started by Rprrr, Dec 18, 2012.

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

    Rprrr

    Hi,

    I'm trying to create a book and quil with some text, an author and a title in it.
    This is the code I've made:
    Code:
        @EventHandler
        public void onPlayerLogin(PlayerLoginEvent e){
       
            Player p = e.getPlayer();
            PlayerInventory inv = p.getInventory();
       
            //The book
            ItemStack book = new ItemStack(Material.BOOK_AND_QUILL, 1);
            BookMeta meta = (BookMeta) book.getItemMeta();
       
            meta.setTitle("To: " + p.getName());
            meta.setAuthor("Santa");
            meta.setPage(0, "From: Santa. To: " + p.getName());
            meta.setPage(1, "Hi!                      Love, Santa." + " :D");
       
            if (inv.contains(Material.AIR)){
                inv.addItem(book);
           
            }
            else {
                ItemStack r = inv.getItemInHand();
                inv.remove(r);
                p.getWorld().dropItemNaturally(p.getLocation(), r);
                inv.setItemInHand(r);
            }
        }
    But this gave me an error:
    Show Spoiler
    Caused by: java.lang.NoSuchMethodError: org.bukkit.inventory.ItemStack.getItemMe
    ta()Lorg/bukkit/inventory/meta/ItemMeta;

    Line 32 is a }..

    Does anyone know why this isn't working? Thanks in advance!
     
  2. Offline

    fireblast709

    Update the server, as your server is outdated compared to the code
     
  3. Offline

    desht

    What fireblast709 said - your craftbukkit server is out of date compared to the version of Bukkit you built against.

    Plus, you'll probably want to run that code in a handler for PlayerJoinEvent, not PlayerLoginEvent.

    Oh - and you also need to put the updated metadata back in the book:
    Code:
    book.setItemMeta(meta);
    
     
    fireblast709 likes this.
Thread Status:
Not open for further replies.

Share This Page