How to construct ItemStack?

Discussion in 'Plugin Development' started by zajacmp3, Jul 3, 2012.

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

    zajacmp3

    Hello,

    I have a bit of a problem that blocks me from ending some code.
    I don't really get how ItemStack works.
    I want to add an item to player inventory on log on.
    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onLogin(final PlayerJoinEvent event){
            Player logging = event.getPlayer();
            boolean exist = (new File("world/players/"+logging.getName()+".dat")).exists();
            if(exist==false){
                logging.getInventory().addItem(armor);
                logging.getInventory().setChestplate(armor);
            }
        }
    My goal is to set ItemStack armor to be an item with id 299.
    I tried really many things and the main problem with almost all is... cannot convert void to itemstack... whatever that means.
     
  2. new ItemStack(material, amount) f.e

    There are different ways.
    More information in the java documentation
     
  3. Offline

    zajacmp3

    Thanks.
    Now I have got bukkit by the balls with that trick :)
     
  4. I think you forgot to define armor?
     
  5. Offline

    Jnorr44

    Material armor = Material.DIAMOND_CHESTPLATE
    logging.getInventory().setChestplate(new ItemStack,(armor));

    I think thats right...
    Maybe youll get an error on "Material armor" though...
     
Thread Status:
Not open for further replies.

Share This Page