Item help

Discussion in 'Spigot Plugin Development' started by Ayresy, May 21, 2015.

  1. Code (Text):
     }else{
            e.setCancelled(true);
            p.updateInventory();
         
            p.sendMessage(ChatColor.AQUA + "You must wait " + ChatColor.YELLOW + ChatColor.BOLD + cooldown.get(p) + ChatColor.AQUA + " seconds before you enderpearl again!");
            if(p.getInventory().contains(Material.ENDER_PEARL)){
                  ItemStack ep = new ItemStack(Material.ENDER_PEARL);
                  ItemMeta meta = ep.getItemMeta();
                  meta.setDisplayName("§eEnderpearl Cooldown: §c" + cooldown.get(p));
                  ep.setItemMeta(meta);
                  p.getInventory().remove(Material.ENDER_PEARL);
                  p.getInventory().addItem(ep);
    How would i get the amount of enderpearls the player has in his inventory then save that as a variable or something then set the new itemstack i made to the same amount he previously had
     
  2. int pearls = 0;
    for(ItemStack stack : p.getInventory().getItems()){
    if(stack.getType().equals(Material.ENDER_PEARL)) pearls = pearls + stack.getSize();
    }
     
    • Like Like x 1