Make some items drop, others not.

Discussion in 'Plugin Development' started by triarry, Feb 7, 2013.

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

    triarry

    Hi there everyone. I've been racking my brain over this for the past couple of hours. I've successfully made a plugin that checks a blacklist of item IDs in a config. If a player has these these items when they die, they get removed from his inventory.

    HOWEVER, I'm trying to make them get DROPPED, not just removed.

    My function for removing items:
    Code:
     public void blacklistItems(Player p) {
            for (Integer itemList : plugin.getConfig().getIntegerList("blacklist.items")) {
                p.getInventory().remove(itemList);
            }
    }
    
    This works just fine.

    I place all the player's armor and items into two different hashmaps, and clear their inventory and drops.

    Code:
       
                    ItemStack[] content = player.getInventory().getContents();
                    ItemStack[] content_armor = player.getInventory().getArmorContents();
                    armor.put(player, content_armor);
                    items.put(player, content);
                    player.getInventory().clear();
                    event.getDrops().clear();
                    dropBlacklist(event);
     
    
    dropBlacklist is where the main code for dropping a player's items will go. Clearing the getDrops() makes sense, since all the drops already exist in the hashmap. I just can't think of a way to extract the FULL ItemStack from the HashMap, only using the itemID's from my config.

    Can anyone steer me in the right direction for extracting full ItemStacks from this HashMap using only the item ID it's associated with?

    If this is unclear I can try and describe it better.

    Code:
        public void dropBlacklist(PlayerDeathEvent event) {
    Player p = event.getEntity();
    for (Integer itemList : plugin.getConfig().getIntegerList("blacklist.items")) {
    for (ItemStack itemStackList : event.getDrops()) {
    System.out.print(itemList);
    if (itemStackList.getTypeId() == itemList) {
    p.getLocation().getWorld().dropItem(p.getLocation(), itemStackList);
    }
    }
    }
    event.getDrops().clear();
    }
    }
    EDIT: I GOT IT!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page