Stop certain items to not drop

Discussion in 'Plugin Development' started by MordorKing78, Mar 2, 2015.

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

    MordorKing78

    So I am trying to not drop custom items.

    THIS IS THE CODE:
    (ONPLAYERDEATHEVEN)
    Code:
            final ArrayList<ItemStack> remove = new ArrayList<>();
    
            for(ItemStack drop : e.getDrops()) {
                final String name = drop.getItemMeta().getDisplayName();
                final int enchants = drop.getEnchantments().size();
               
                if(name.contains("§9Flame") || name.contains("§9Dark") || name.contains("§9Icy")){
                   
                    remove.add(drop);   
                   
                }else if(enchants > 0){
                    return;
                }else if(drop.getType().equals(new ItemStack(Material.GOLDEN_APPLE, (short)1))){
                    return;
                }else{
                    remove.add(drop);              
                }
            }
            
              for(ItemStack is : remove) {
    
                  e.getDrops().remove(is);
                         
              }  
    if there is 1 item thats enchanted or if its a gapple everything drops.. I understand why it does that (kinda) but I don't know how to fix it, I tried this but I didn't like it (it worked half though)
    Show Spoiler

    Code:
                /*if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Golden Apple")) {
                     remove.add(drop);
                 }
                if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Golden Apple")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§5Dark Sword")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§bIcy Sword")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Sword")) {
                     if(!(drop.getEnchantments().size() > 0)){
                         remove.add(drop);
                     }
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Bow")) {
                     if(!(drop.getEnchantments().size() > 0)){
                         remove.add(drop);
                     }
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Arrow")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§6Flame Helmet")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§6Flame Chestplate")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§6Flame Leggings")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§6Flame Boots")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Helmet")) {
                     if(!(drop.getEnchantments().size() > 0)){
                         remove.add(drop);
                     }
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Chestplate")) {
                     if(!(drop.getEnchantments().size() > 0)){
                         remove.add(drop);
                     }
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Leggings")) {
                     if(!(drop.getEnchantments().size() > 0)){
                         remove.add(drop);
                     }
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Boots")) {
                     if(!(drop.getEnchantments().size() > 0)){
                         remove.add(drop);
                     }
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§5Dark Helmet")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§5Dark Chestplate")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§5Dark Leggings")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§5Dark Boots")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§bIcy Helmet")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§bIcy Chestplate")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§bIcy Leggings")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§bIcy Boots")) {
                     remove.add(drop);
                 }
                 if(drop.getItemMeta().getDisplayName().equals("§bCold Drink")) {
                     remove.add(drop);
                 }*/


    it doesn't work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  2. Offline

    MordorKing78

  3. Offline

    Unica

    @MordorKing78

    You're returning in a for-loop..

    Code:
    for(ItemStack i : getDrops()){
         if(i is equal to an item I dont wanna drop) continue; //Skip current cycle
         drop.add(i); //Else add the itemstack
    }
    
    for(ItemStack a : drop){
        getDrops().remove(a);
    }
    Or just immediately remove it in the first for-loop :)
     
  4. Offline

    MordorKing78

    @Unica I'm not sure how this would work. Seems almost the same..
     
Thread Status:
Not open for further replies.

Share This Page