Solved Entity Death Event Help

Discussion in 'Plugin Development' started by AlexLeporiday, Mar 19, 2013.

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



    I'm looking to get some help with monitoring entity deaths.
    I only want to monitor entities that are killed by players. EntityDeathEvent has no method to get the cause of the death.

    I looked around and found many instances of people saying to use EntityDamageByEntityEvent and get the entities health but the EntityDamageByEntityEvent doesn't get called when the entity is struck by a killing blow.

    Any help would be greatly appreciated. I'll attach the example code I am using incase I have missed something simple.

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onEnitiyDamageByEntity(EntityDamageByEntityEvent event) {
        if((event.getDamager() instanceof Player) && (event.getEntity() instanceof LivingEntity)) {
            Bukkit.getLogger().info("Player attacking the living entity");
            LivingEntity entity = (LivingEntity) event.getEntity();
            if(entity.getHealth() == 0) {
                Bukkit.getLogger().info("Entity Dead");
    Solved it myself. Heh.
    Got to listen to EntityDeathEvent and use if(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page