Add attacker's name to entity's metadata?
afoxxvi opened this issue · 2 comments
I'm making my own plugin to modify damage event, In this case I have to know who is the attacker.
However sometimes I can not get attacker from EntityDamageEvent caused by a Damage Action if damage type is changed.
(which means when I use event.getDamager(), it returned null.)
So is it possible to leave attacker's name in defender's metadata?
By defender.setMetadata("last_attacker", new FixedMetadataValue(....))
If you are listening for the EntityDamageByEntityEvent
I think getDamager should never be null.
It will sometimes be a projectile, in which case you need to getShooter
from that, which will be in the player.
In the case of “magic” damage, the attacker will be a ThrownPotion entity, which functions like a projectile.
Please let me know if that helps- internally, this is what magic does to track who damaged who.
Thanks a lot, it does help.
I have many damage types want to use, but when damage type is set to generic, burn, drown, lava, stuck, EntityDamageByEntityEvent is never called, as for other damage types, event.getCause() always return MAGIC, so I had trouble.
But luckily I have found a new way to seperate different damage types.
If you have time please note that when damage type is set to anvil, cactus, dragon_breath, falling_block, An IllegalStateException might be thrown.