Clearing Items

Discussion in 'Plugin Development' started by CoderRevolq, Mar 28, 2014.

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


    How do I clear items? For example after x amount of seconds the items on the ground despawn. Please help, include how to remove it and the timer on when to remove the items
  2. Offline


    You loop through all entities:
    for(Entity e : world.getEntitities())
    Then you will check if it's an Dropped Item: if(e.getType() == EntityType.DROPPED_ITEM)
    And if so you'll do: e.remove();

    For the timer you should use a repeating task:
    int seconds = 100; (time every seconds it should run this)
    //OnEnable Method
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    public void run()
    Your stuff here
    }, 0L, seconds*20L);
  3. Offline


    Im still confused of what you said, what event should I use, ItemSpawnEvent or something else?
  4. Offline


    Jalau Code but compiled
    1. int seconds = 100;
    2. //OnEnable Method
    3. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    4. {
    5. public void run()
    6. {
    7. for(Entity e : world.getEntitities())
    8. e.remove();
    9. }
    10. }, 0L, seconds*20L);
  5. Offline


    You forget the part to check if it's a dropped item :D
Thread Status:
Not open for further replies.

Share This Page