Help with Item Stacks

Discussion in 'Plugin Development' started by DragonSlayer1920, Jun 20, 2014.

Thread Status:
Not open for further replies.
  1. Hello,
    I am checking if a player has a certain itemstack in there inventory, with this said it does not detect the item stack if the item has any durability taken down. How would I allow it to detect even if there is durability?
    Thanks

    Code:
    Code:
    @EventHandler
        public void onDeath(PlayerDeathEvent e) {
            ItemStack helm = new ItemStack(Material.CHAINMAIL_HELMET);
           
                                           
                    if(e.getDrops().contains(helm)) {
                        e.getEntity().sendMessage("Has");
                    } else {
                        e.getEntity().sendMessage("Does not");
                    }
                }
     
  2. Offline

    Bavestry

    Maybe instead of creating an itemstack and seeing if the drops contains it, you could iterate through the drops, and check if e.getDrops().get(i).getType().equals(Material.CHAINMAIL_HELMET)? Then it would be just checking the item type, rather than comparing it to a new chainmail helmet that you created, which would have full durability.

    Code:
    @EventHandler
    public void onDropTest(PlayerDeathEvent event){
     
    List<ItemStack> drops = event.getDrops();
     
    for(int i = 0; i < drops.size(); i++){
     
    if(drops.get(i).getType().equals(Material.CHAINMAIL_HELMET)){
     
    player.sendMessage("Has");
     
    }else{
    player.sendMessage("Doesn't have");
    }
     
    }
     
    }
    Hope this helped!
     
Thread Status:
Not open for further replies.

Share This Page