Kill Entity method?

Discussion in 'Spigot Plugin Development' started by SirLich, Sep 29, 2017.

  1. Hi guys,
    I am doing some work where I want to kill a mob via its Entity instance.
    I keep a map that connects a Entity and a custom class RpgEntity. Each of the custom mobs I am creating will be added to this map on spawn, and removed on death.

    I am adding methods to the RpgEntity class like rawDamage(int) and kill(), but the returned Entity is not that useful. I can't appear to kill the Entity, and I can't seem to set health or things like this.
    I am looking for methods like:
    damageEntity
    setHealth
    kill

    Should I be using EntityCreature or EntityLiving? How am I supposed to kill an Entity from its Entity instance.
    Thanks,
    ~Lich
     
    • Agree Agree x 2
  2. EntityLiving is nms, use LivingEntity and do setHealth(0) or damage it alot.
     
  3. Be aware that the entity instance is not persistent. Of course it will change across sever restarts, but it also changes if the chunk the entity is in gets unloaded. If you need a persistent reference then use the entities UUID.
     
  4. If you prefer just making the entity disappear and remove it from the world, then you may be interested to Entity#remove method that, as you see, is available for any entity. If you prefer the entity to make the death animation, then you have to check if it is an instance of Damageable, cast it, and then you can access some interesting method like damage (and I'm not sure if setting the health to 0 using one of the setters of that interface would make the entity correctly play the death animation). An alternative to this, is using Entity#playEffect-EntityEffect, passing the DEATH constant as parameter; I'm not sure, though, on how safe this is for a proper entity erasing, so I suggest eventually making some test like combining this method to the health setter of the damageable interface.
     
    • Useful Useful x 2