Remove all Items from a world

Discussion in 'Plugin Development' started by Terradominik, Jul 11, 2012.

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

    Terradominik

    I want to remove all Dropped Blocks/Items from a world, it sounds easy, but for some reason it don't work. I can't find the mistake....

    Here is the code
    Code:
    List<Entity> list = world.getEntities();
            for (Iterator<Entity> entities = list.iterator(); entities.hasNext();) {
                if (entities.hasNext()) {
                    Entity entity = entities.next();
                    if (entity instanceof Item) {
                        entity.remove();
                    }
                }
            }
     
  2. Offline

    VeryBIgCorp

    Use a while loop.
     
    Terradominik likes this.
  3. Offline

    Terradominik

    instead of the for loop ? what would this change ?
     
  4. "It doesn't work" - What doesn't work? We can't read your mind.
     
  5. Offline

    Terradominik

    It doesnt delete the items
     
  6. Offline

    stelar7

    try this
    Code:
    List<Entity> list = world.getEntities();
    Iterator<Entity> entities = list.iterator();
    while (entities.hasNext()) {
        Entity entity = entities.next();
        if (entity instanceof Item) {
            entity.remove();
        }
    }
    
     
    Terradominik likes this.
  7. Offline

    Terradominik

    thx, no idea why but it works now
     
  8. Offline

    CorrieKay

    i typically just inject the list directly into the for loop (for(Object obj : list)), so im just throwing ideas around, but it does look like the for loop would only cycle once. (ive never really seen a for loop set up this way though, so take this with a grain of salt)
     
    Terradominik likes this.
  9. Offline

    Terradominik

    yeah i thought the same way,but i took this code from worldedit, thats why i wonderd
     
Thread Status:
Not open for further replies.

Share This Page