Adding items to an inventory

Discussion in 'Plugin Development' started by Suprem20, Aug 26, 2011.

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


    I am stuck on this :

    I want to add items to an inventory on a certain event. I also want to add items in the armory slots and in the hotbar.

    The context :

    I am making a TeamDeathMatch plugin for pvp, I want to add a basic load out for the players including armor, food, items and such. I also want to add a certain method so players can't hurt a player that is in the same team.

    Any help?
  2. Offline


    Here's an example for the helmet:

    To add an item:
    player.getInventory().addItem(new ItemStack(itemid, amount));


    player.getInventory().addItem(new ItemStack(itemid, amount, (byte)damagevalue));
  3. Offline


    1. PlayerInventory inv = player.getInventory();
    2. ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);
    3. inv.addItem(i);

  4. Offline


    for the helmet i can add anything right? like a wool block? and thanks btw
  5. Offline


    You'll probably get a stack trace error if you try to use anything else but an actual helmet.
  6. Offline


    mmk, gotta test that out any ideas for the anti-ff?
  7. Offline

    Randy Schouten

    Any block should work for helmets.

    There are several plugins out there in which you can change your helmet to a block.
    It's quite fun. :p
  8. Offline


    yeah okay well... better get to work!

    hmm i get and error with this


    error :

    method setHelmet in interface org.bukkit.inventory.PlayerInventory cannot be applied to given types ;
    required : org.bukkit.inventory.itemstack
    found : org.bukkit.Material
    reason : actual argument org.bukkit.material cannot be converted to org.bukkit.inventory.itemstack by method invocation inversion

    any help?

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


    umm, since normally that itme cant go there i think it must be done another way, try looking at the source of the 'SimpleHat' Plugin.
  10. Offline


    Can't find the source :(

    Any suggestions?
  11. You need to pass an ItemStack and not a Material, look at the constructors of ItemStack.
  12. ^^ i.e.

    player.getInventory().setHelmet(new ItemStack(itemid, amount));
Thread Status:
Not open for further replies.

Share This Page