Hello
i need to get the cause of the death of an entity.
I use the DestructEntityEvent.Death Event. I can check if the death was directly caused by a player with if(_e.getCause().first(Player.class).isPresent()) but it starts to get tricky when i want to get checked if an entity got killed by an arrow.
I also have problems when the entity gets killed by fire, from a fire arrow for example.
So i need a way to check if an entity got killed by a player, either by sword/directly (works) or by an arrow/fire arrow.
From there you can tell if it was caused by a explosion or fire, if it is castable to ProjectileDamageSourse then a projectile did it, the ProjectileDamageSource will then tell you what entityprojectile did it.
I know this works in DamageEntityEvent (which has a “willCauseDeath” option. I dont see why it wont in DestructEntityEvent
Ok it works like this. Im not sure if i miss any events though.
if (_e.getCause().first(DamageSource.class).get().getType().getId() == "fire") {
if (_e.getCause().getContext().get(EventContextKeys.NOTIFIER).isPresent()) {
}
}