What is the best way to remove a creature?

Discussion in 'Plugin Development' started by Schwarzer Zylinder, Jan 21, 2012.

Thread Status:
Not open for further replies.
  1. Hey,
    one of my plugins deals with mobs and I have to remove them on plugin disable. Only way I found were creature.remove() and creature.damage(1000)
    Which is the better one? creature.remove() doesn't work very good for now...
     
  2. Offline

    troed

    What is it that doesn't work? It's what I use.
     
  3. Offline

    caldabeast

    I would just kill them all by setting their health to zero or by causing them damage.
     
  4. Offline

    skore87

    I would create 100 explosions with a yield of 10 for each entity.
     
    DirtyStarfish likes this.
  5. Offline

    bergerkiller

    Time for a real answer...lol

    Achem.

    Entities have a 'dead' boolean property. When calling remove() or die() (native) it sets the entity dead. The NEXT TICK this entity is removed from the server.

    When removing entities from the server ondisable, you can't use .remove(), as that is not in the same tick. To instantly remove an entity, use:
    Code:
    Entity entity = ?
    net.minecraft.server.Entity e = ((CraftEntity) entity).getHandle();
    e.world.removeEntity(e);
     
  6. Offline

    skore87

    The nuke idea is fun though. =)
     
  7. Works fine, thanks!
     
  8. Offline

    troed

    Thanks, that's indeed worrying. However, I haven't seen .remove() fail in my plugin and I do use it in onDisable. Is it simply a race condition? (I'd seldom have more than a few to remove).

    (I try to stay away from accessing CraftBukkit directly)
     
  9. Offline

    bergerkiller

    troed it's not bad, when the world is disabled and starts saving, it will remove dead entities then too. (I believe)

    But other plugins could still notice this entity to be alive and use it one way or the other. Or it would get stored anyway.
     
Thread Status:
Not open for further replies.

Share This Page