Solved Killing LivingEntitys on "onDisable"

Discussion in 'Plugin Development' started by UniqueNameDen, Mar 23, 2015.

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

    UniqueNameDen

    Killing LivingEntitys on "onDisable", yes I know that when onDisable fires no ticks will be passed, is there a way to get around this?
     
  2. Offline

    mine-care

  3. Offline

    Konato_K

    @UniqueNameDen Iterate through all entities in the world and call remove on them?
     
  4. If thats true, no ticks will be passed AFTER onDisable got called and was finished.
    You can do entity.remove() or entity.setHealth(0.0);
     
  5. @UniqueNameDen
    Just do:
    for (World w : Bukkit.getWorlds()) {
    for (Entity e : w.getEntities()) {
    if (e instanceof LivingEntity) e.remove();
    }
    }
     
  6. Wouldn't this be dangerous because ts will remove every entity and every player(?) from every world.
     
    Last edited: Mar 23, 2015
  7. @FisheyLP
    he want to remove every living entity from the world. this will remove every living entity except for players (You can`t remove players without packets...)
     
  8. Okay. was just my opinion ._.
     
  9. Offline

    UniqueNameDen

    I think I explained it wrong,
    I already have
    Code:
    for (LivingEntity e : villagers) {
       e.remove();
    }
    
    but it doesn't work, but it works /w a command
     
  10. Show your code
     
  11. Offline

    UniqueNameDen

    Code:
    for (LivingEntity e : villagers) {
       e.remove();
    }
    
    oh this is my "onDisable" I have a custom plugin loader...
    and yes onUnload does fire...
    Code:
    public void onUnload() {
    for (LivingEntity e : villagers) {
       e.damage(999999);
    }
    villagers.clear();
    core = null;
    m = null;
    }
    
     
  12. ... a little bit more xD Thats the same as before
     
  13. Offline

    Konato_K

    Full code, we don't know what "villagers" is
     
  14. Offline

    UniqueNameDen

    public List<LivingEntity> villagers = new ArrayList<LivingEntity>();
    It works with a command...
    and After onDisable called, there will be no ticks anymore.
     
  15. @UniqueNameDen
    I`d removed entities and do stuff on disable and it worked. that isn`t the problem.
     
  16. Offline

    UniqueNameDen

    Code: http://pastebin.com/u5q24r01

    Bump
    Also, @Juancomaster1998 entity's do not get cleared on "onDisable", they get cleared when you restart the server, but the ones that have custom data [Nametags, etc], they don't get cleared, I tested this with a normal plugin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  17. Offline

    Hawktasard

    @Juancomaster1998
    Pretty sure calling .remove on a player will make them unable to do stuff (and maybe make him invisible to other players, not sure about that though).
     
  18. Offline

    UniqueNameDen

    I wan't to remove custom villagers it works /w a command but I need to find a way on how to do it on "onDisable"
     
  19. Offline

    Konato_K

    @UniqueNameDen
    Instead of using damage use remove, also, that is NOT your onDisable.
     
  20. Offline

    UniqueNameDen

    @Konato_K

    How many times I need to tell you that I don't use the default plugin loader... anyway I found a way how to get around this myself:
    Code:java
    1.  
    2. net.minecraft.server.v1_7_R3.Entity e = ((CraftEntity) entity).getHandle();
    3. e.getWorld().removeEntity(e);
    4.  

    I used a packet to remove it, because when onDisable fires there are no more ticks, because first, entitys are marked as DEAD, and on the next tick removed, but with this method it gets removed on the same tick that onDisable happends

    Also, if you are't sure about something, don't say it, instead of that google it.

    More facts:
    .damage();
    .die();
    .dead();
    .remove();
    all of them do the same this, but .damage() drops items the Entity would normaly drop
     
Thread Status:
Not open for further replies.

Share This Page