Add Item to Inventory?

Discussion in 'Plugin Development' started by KaiBB, Dec 24, 2011.

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

    KaiBB

    How do you add an item to inventory? All I have for the section where it gives an item is this:
    Code:
    Santa.getInventory();
    How do I tell it to add one diamond to the player's inventory?
     
  2. Inventory.addItem(ItemStack)
     
  3. Offline

    KaiBB

    Thanks :D

    What's wrong with this? An error comes up on "Santa" (I named the player Santa instead of p). The error is "cannot be resolved to a type."
    Code:
    Santa.getInventory Inventory = Inventory(Inventory.addItem(Material.DIAMOND));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  4. Offline

    Sagacious_Zed Bukkit Docs

    @KaiBB
    The compiler thinks that Santa.getInventory is a Type and you are creating a variable Inventory of type Santa.getInventory
     
  5. Offline

    KaiBB

    I still don't understand the fix. I don't exactly want you to straight up gimme the fix, but can you tell me HOW to fix it? Please? Thanks! :D
     
  6. Offline

    ZachBora

    Pretty much you shouldn't need an =, just something like player.inventory.add
     
  7. Santa.getInventory().add(Material.DIAMOND);
    Should work
     
  8. Offline

    KaiBB

    Ohh I get it now. Thanks :D
     
  9. When I say Inventory. I mean a instance of the Inventory class ;)
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    @KaiBB
    To understand the fix, you have to understand the problem!
    But ill give you the answer again.
    Code:
    final Inventory inventory = Player.getInventory();
    inventory.addItem(ItemStack)
     
  11. Offline

    KaiBB

    Using add doesn't work. I have exactly what you guys suggested, and it says "The method add(Material) is undefined for type PlayerInventory."

    Oh you answered my question above. Thanks :D ^^

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

    Sagacious_Zed Bukkit Docs

    @KaiBB
    you have to stop simply copy and pasting....
     
    tips48 likes this.
  13. Offline

    Chiller

    Get on skype!
     
  14. Sorry, I wasn't quite sure if you could add a material, but figured you could since you tried to :p Oops, never again :D
     
  15. Offline

    KaiBB

    I did what you said, just changed this:
    Code:
    addItem(Material.DIAMOND);
    To this:
    Code:
    addItem(new Itemstack(Material.DIAMOND, 1);
     
  16. Yep, thats correct
     
  17. Offline

    KaiBB

    Yeah I fixed everything, it's running like a charm!
     
    gabrielmaennl555 likes this.
Thread Status:
Not open for further replies.

Share This Page