SOLVED - Adding Custom Item to Inventory

Discussion in 'Plugin Help/Development/Requests' started by Benlewis9000, Dec 10, 2014.

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

    Benlewis9000

    Just a simple problem I can't seem to get my head around. In the past I have always added custom items (as in an item with new metadata) to the player inventory with player.getInventory().addItem(item). However, Eclipse keeps saying that it can't add invisibook because it isn't and ItemStack?
    This is what I am trying to use;
    Code:
                        ItemStack invisibook = new ItemStack(Material.ENCHANTED_BOOK, 1, (short) 1);
                        ItemMeta bookmeta = invisibook.getItemMeta();
                        bookmeta.setDisplayName("§d§lSpell §fInvisibilty");
                        invisibook.setItemMeta(bookmeta);
                        player.getInventory().addItem(invisibook);
    If anyone has a quick solution to what I am doing wrong please share?
     
    Last edited: Dec 11, 2014
  2. Offline

    techboy291

    Can't you just create a new ArrayList and add invisibook to it?
     
  3. Offline

    TGRHavoc

    @Benlewis9000
    What version of Bukkit are you developing against? The latest API allows you to add a single ItemStack to the inventory.
    Refer Here

    Edit: It seems that you may be getting setContents and addItem mixed up...
     
  4. Offline

    Skionz

  5. Offline

    Benlewis9000

    @TGRHavoc
    At th time of creating this post I was using a 1.7.5 build, but just updated to craftbukkit-1.8-R0.1-SNAPSHOT. Nothing else about the plugin was changed, but the problem still persists.
    @Skionz I'm honestly not sure where I got the ArrayList idea from, I must have just misread one of those tips Eclipse tries to give you. The item I am trying to give it is an ItemStack, so I don't know why it isn't taking it. I still have no idea why it doesn't think the itemstack I created is an itemstack...
     
  6. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
  7. Offline

    TGRHavoc

    @Benlewis9000
    What ItemStack class are you importing? Make sure that it's from the "org.bukkit.inventory" package.
     
  8. Offline

    Benlewis9000

    @TGRHavoc
    Yes, it is.
    The exact message from Eclipse is:
    Code:
    The method addItem(ItemStack[]) in the type Inventory is not applicable for arguments (ItemStack)
     
  9. Offline

    TGRHavoc

    @Benlewis9000
    Hmmm, this is a weird issue. Have you tried adding an array of ItemStack ?
    Code:
    addItem(new ItemStack[] { invisibook });
     
    Benlewis9000 likes this.
  10. Offline

    Benlewis9000

    @TGRHavoc
    Wow, worked perfectly! Still not sure why it wants this, but thank you very much for the fix :)
     
  11. Offline

    TGRHavoc

    Benlewis9000 likes this.
Thread Status:
Not open for further replies.

Share This Page