I Need a Plugin that makes players drop a drop upon death

Discussion in 'Plugin Development' started by DJ_BLADERUNNER, May 29, 2012.

  1. Offline

    DJ_BLADERUNNER

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hello i need a plugin that not only allows players to drop items upon death but can be configured to any item and quantity in game. If there already is a plugin out there it would be awesome if someone could link me to it. Otherwise if someone could make it for me that would be amazing. I have no coding experience so i don't know if what i'm asking is possible/easy/difficult. Thx for your time.
  2. Offline

    Mike111177

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    this should be in plugin request
  3. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  4. Offline

    DJ_BLADERUNNER

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thank you and sry for posting this in the wrong section i dont use these forums alot
  5. Offline

    Wundark

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Here is an example I ad from a previous Project.

    Code:
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event) {
        Entity ent = (Entity) event.getEntity();
        if (ent instanceof Player) {
            Player player = (Player) ent;
            if (player.getName().equals("PLAYER")) {
                ent.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(Material.MELON_BLOCK.getId(), 1, (short) 0));
            }
        }
    }

    This post has been edited 1 time. It was last edited by Wundark May 29, 2012.
  6. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @Wundark Why not edit the drop list directly?
    Code:java
    1. public void manipulateDrops(EntityDeathEvent event)
    2. {
    3. List<ItemStack> dropList = event.getDrops();
    4. dropList.clear(); // To remove everything from the list. you could also iterate over it and remove some things, example to remove all apples:
    5. /*
    6.   Iterator<ItemStack> iter = dropList.iterator();
    7.   ItemStack is;
    8.   while(iter.hasNext())
    9.   {
    10.   is = iter.next();
    11.   if(is.getType() == Material.APPLE)
    12.   iter.remove();
    13.   }
    14.   */
    15. dropList.add(new ItemStack(Material.APPLE)); // To add a apple to the list...
    16. }
  7. Offline

    Wundark

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @V10lator He specifically asked for Players and he never asked for drops to be removed just for a customisable drop upon death. We can add both of out code together.

    As for customisation you can add it via a config and permissions. EG. If the config had a string that contained a item value for a drop. (member: "1,1;2,5"). This would drop 1 of Stone and 5 of Grass Blocks.

    Code:
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event) 
    {
        Entity ent = (Entity) event.getEntity();
        if (ent instanceof Player) 
        {
            Player player = (Player) ent;
            if(player.hasPermission("death.member"))
            {
             for(String itemProcess : getConfig().getString("member").split(";"))
             {
              String[] itemProc = itemProcess.split(",");
              event.getDrops().add(new ItemStack(Integer.valueOf(itemProc[0]) , Integer.valueOf(itemProc[1]), (short) 0));
             }
            }
        }
    }
     
    
  8. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Copy&paste error, sorry, simply change
    public void manipulateDrops(EntityDeathEvent event)
    to
    public void manipulateDrops(PlayerDeathEvent event)
    then. ;)
    true, but removing drops would be a nice optional feature, wouldn't it? Also I could say "and he never asked for permissions".


    But what I wanted to ask with my last post was why you where creating extra drops instead of adding the new items to the existent drop list. The seconds sounds better cause it may be faster code (have to check CB code to confirm and don't want right now) + higher compatibility with other drop handling plugins (like the ones that take the list and flush it directly into the killers inventory instead of dropping).

    This post has been edited 1 time. It was last edited by V10lator May 29, 2012.

Share This Page