Solved Remove drops x seconds after death

Discussion in 'Plugin Development' started by DrTURTLE2, May 26, 2014.

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


    This is what I have.
    1. @EventHandler
    2. public void deathdropTimer(PlayerDeathEvent e){
    3. new BukkitRunnable(){
    4. public void run(){
    6. }
    7. }.runTaskLater(plugin, 100L);
    8. }
    10. }

    Now how would I get all the dropped items and then remove them?
  2. Offline


    did you tried to store dropped items somewhere?
  3. Offline


    DrTURTLE2 in the run():
    1. e.getDrops().clear(); // should work
    but you need to do the "e" variable final. I think you need to do this:
    1. public void deathdropTimer(final PlayerDeathEvent e){
  4. Offline


    Yeah I already tried that, and then tried it again and it won't delete.

    Thanks for replying.,
  5. Offline


    That doesn't make sense. When the event is called, the actual drops don't exist yet.

    @OP I guess you'll have to clear the drops from the event and spawn them yourself. Then run a timer and remove them all. Make sure you listen on a higher priority so you get any modifications to the drop list.
  6. Offline


    WhatAaCow getDrops() returns a List<ItemStack> object. The class List doesn't have any Bukkit methods defined for it. Instead, OP, you should iterate through this list to get each individual ItemStack and perhaps use setAmount(0) for each. It's been a while since I've deleted items and such - not quite sure if that's how you do it.
  7. Offline


    Event#getDrops()#clear() would work, but the issue is that the OP want's a delay. Which, as Garris0n pointed out, has to make sure the event parameter isn't final or else there will be no drops.
  8. Offline


    I use so I do not know if it will be useful for you.

    1. @EventHandler
    2. public void Morte(PlayerDeathEvent evt){
    3. evt.getDrops().clear();
    4. evt.setDeathMessage("");
    5. }
  9. Offline


    After a lot of frustration trying what you are asking ive found no way of doing it.
    We tried using the Runnable function which seemed not to work, if anyone has an answer I'd love to hear it.
  10. DrTURTLE2 keaton64
  11. Offline


    i already provided valid answer to question of thread, but it was ignored.
  12. Offline


    Are you aware of a way to get the dropped items in the first place?
  13. Offline


    Okay thank you everyone for your replies, anyway I found a different solution to my problem. Because I was removing drops from when they die and when a player drops them, I could just use ItemSpawnEvent. Thank you all.

    Here is the code if anyone is interested.
    1. @EventHandler
    2. public void dropDeath(final ItemSpawnEvent e){
    4. new BukkitRunnable(){
    5. public void run(){
    6. e.getEntity().remove();
    7. }
    8. }.runTaskLater(plugin, 100L);
    9. }
    10. }
  14. Offline


    Ofc i aware, did you opened core method that process drops from event?
  15. Offline


    Actually, now that I think about it, you could tag the ItemStacks with some unique metadata and listen for the ItemSpawnEvent, then remove the data...
    Hacky, but it would work.
  16. Offline



    You could loop through the event.getDrops(), and add their entity uuid's to a list, then after the delay, loop through the list getting the item from the uuid, and remove them.
  17. Offline


    getDrops() is a list of ItemStacks, not Items.
    Gater12 likes this.
  18. Offline


    getDrops() return ItemStack list not Item entity.
    Garris0n likes this.
  19. Offline


    its obvious for anyone with a bit of logic in head

            for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
                if (stack == null || stack.getType() == Material.AIR) continue;
                world.dropItemNaturally(entity.getLocation(), stack);
    You clean drops from your plugin and drop items expected to drop from your own code.
    At same time you can store dropped items *somewhere*.

    Marking items with metadata or running task in order to do it is useless waste of resources - items have buildin time to life of 600 seconds (12000 ticks) and this time can be altered at time of item creation.
  20. Offline


    That's the first thing I said, except for the point about the built-in life. I would prefer the metadata (as in just tag it with a unique piece of lore) solution simply because it doesn't alter the way the event fires. Either one works, but I'd personally prefer not screwing up any plugins listening to the event on MONITOR.

    As for the timer, it can't actually be modified via Bukkit. While Entity does have a setTicksLived() method which modifies the ticksLived value, EntityItem uses its own age value to despawn. Of course, you could just get the handle and modify it, but I don't like recommending NMS to random people when they could just use Bukkit (the scheduler).
  21. Offline


    Ugly implementation of API is valid reason to use NMS directly.
  22. Offline


    Seems like it would be a better idea to, say, fix the API.

    And, in the meantime, use a workaround via the scheduler to avoid somebody who doesn't know how NMS works breaking something.
  23. Offline


    i will perform original research - i will post pull request to bukkit and cbukkit and will measure time to react over my commit.
  24. Offline


Thread Status:
Not open for further replies.

Share This Page