Disappear Items on the Ground

Discussion in 'Plugin Development' started by ajs333, Nov 3, 2013.

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

    ajs333

    Ok, I was wondering that when a player dies he will drop all of his items but only for 10 seconds then they will disappear. How would I do this?

    Anyone?
     
  2. Offline

    sd5

    When the player dies, save all the items so that you are able to find them again with your plugin, then start a sync delayed task which removes the items after 10 seconds if they are still there. That's my idea :)
     
  3. ajs333
    So do you want to delete the items after 10 seconds?
     
  4. Offline

    ajs333

  5. Basically you need to listen for the PlayerDeathEvent and then schedule a delayed task to clear the items. The code should look like this:

    Code:java
    1. @EventHandler
    2. public void onDeath(final PlayerDeathEvent event){
    3.  
    4. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    5.  
    6. @Override
    7. public void run() {
    8. event.getDrops().clear();
    9. Bukkit.getServer().broadcastMessage("Drops cleared!");
    10. }
    11.  
    12. }, 200L); //200 ticks = 10 seconds (20 ticks per second)
    13. }
     
  6. Offline

    ajs333

  7. Offline

    ajs333

    The Gaming Grunts
    How much of dis coding chu want?
    Here is the EventHandler:
    Code:
     @EventHandler
            public void onDeath(final PlayerDeathEvent event){
       
                getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
       
                    @Override
                    public void run() {
                        event.getDrops().clear();
                    }
       
                }, 100L);
            }
    
     
  8. Is it in your main class? Did you register your events?
     
  9. Offline

    ajs333

    Yea, its in my main class and yes I registered events!
     
  10. Offline

    sd5

    Yes, removing drops with clearing that getDrops() list somehow doesn't work, I already noticed that :/
     
  11. ajs333
    Hmm try this instead maybe:

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
     
  12. Offline

    ajs333

  13. ajs333
    It appears that the problem is that the timer is actually working, but the drops don't get cleared.
     
  14. Offline

    ajs333

    The Gaming Grunts
    Ok, so how is that problem fixed? I'v been looking around and can't find anything...
    What should I do?

    What is the proper way to clear the droped items?

    Can anyone help me... I really am confused and stuck...
     
  15. Offline

    ajs333

  16. Offline

    xTrollxDudex

  17. Offline

    ajs333

  18. Offline

    xTrollxDudex

    ajs333
    Did you implement listener?
     
  19. Offline

    ajs333

  20. Offline

    minekam20

    try this maybe it would work i found it at searching stuffs on google try it
    Code:java
    1. Iterator list = player.getNearbyEntities(Double.parseDouble(args[1]), Double.parseDouble(args[1]), Double.parseDouble(args[1])).iterator();
    2. while (list.hasNext()) {
    3. Entity entity = (Entity)list.next();
    4. if ((entity instanceof Item)) {
    5. ((Item)entity).remove();
     
  21. Offline

    ajs333

  22. Offline

    minekam20

    never mind i just tested and it didnt work :( sorry
     
  23. Offline

    ajs333

    minekam20
    Thanks for trying to help! :D

    So far I can't seem to find anyone who can help... :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    minekam20 likes this.
  24. Offline

    maxben34

    ajs333
    I've been trying to do this as well. I think what you can do is:
    Code:java
    1. //Call this itemspawn event method inside of your death event.
    2.  
    3. @EventHandler
    4. public void onItemSpawn(ItemSpawnEvent e){
    5. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    6. public void run(){
    7. e.getEntity().remove();
    8. }
    9. },10*20);
    10. }
     
  25. Offline

    ajs333

    maxben34
    It gives me an error saying that "void is an invalid type for that variable."
     
  26. Offline

    maxben34

    ajs333
    I think that is due to where you placed the @EventHandler.

    Did you put the event inside of your other event method? That won't work.

    You need to call onItemSpawn(); at the end of your death event.
     
  27. Offline

    ajs333

    maxben34
    Here?
    Code:
    @EventHandler
            public void PlayerDeath (PlayerDeathEvent e) {
                if (e.getEntity() == null) return;
                usedKit.remove(e.getEntity().getName());
                e.setDeathMessage(null);
                @EventHandler
                    public void onItemSpawn(ItemSpawnEvent event){
                    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                        public void run(){
                            event.getEntity().remove();
                        }
                    },10*20);
                }
            }
     
  28. Offline

    maxben34

    Code:
    @EventHandler
            public void PlayerDeath (PlayerDeathEvent e) {
                if (e.getEntity() == null){
                return;
                }
                usedKit.remove(e.getEntity().getName());
                e.setDeathMessage(null);
              }
    onItemSpawn();
    }
    @EventHandler
    public void onItemSpawn(ItemSpawnEvent event){
                    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                        public void run(){
                            event.getEntity().remove();
                        }
                    },10*20);
                }
            }
    Hopefully this works right.
     
  29. Offline

    ajs333

    maxben34
    Nope I still got errors... :/
     
Thread Status:
Not open for further replies.

Share This Page