-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Is your feature request related to a problem?
Currently, AFAIK, there is no way to retrieve which Entity could have caused a PlayerItemDamageEvent to fire, such as when an entity hits a player who is currently using a shield which loses durability for doing so.
In my plugin LevelledMobs, I would like to add a feature where higher-level mobs are able to inflict more durability damage to players' shields so that they are less effective against those mobs.
If you were unfamiliar with the concept: a mob's 'Level' determines how strong they are, i.e. a higher level mob is stronger than lower level mobs.
Describe the solution you'd like.
I think a great way to go about solving this is to add a new event - PlayerItemDamageByEntityEvent. This event extends PlayerItemDamageEvent, and is fired when an entity causes PlayerItemDamageEvent to fire, i.e., during combat.
This event contains a method which references which entity caused the event to fire.
This event could also contain a reference to a linked EntityDamageByEntityEvent which caused the PlayerItemDamageByEntityEvent to fire.
Describe alternatives you've considered.
I have thought about using a bit of hack-ish code to get around it, but I'd rather not
since it could cause weird side-effects. For instance, applying a 1-tick-expiry
temporary metadata value to the defending player in EntityDamageByEntityEvent with the shield breaker multiplier value, and then referencing
that in the PlayerItemDamageEvent by changing the damage value to be multiplied by the multiplier stored in the metadata.
There's also player#getLastDamageCause.getEntity() - although close, that would still be a hack-ish workaround: there is no guarantee that it would return the entity which has caused the particular PlayerItemDamageEvent to fire. Imagine that an entity hit a player 20 minutes ago, and then the player's item was damaged 20 minutes later. That method would return the entity from 20 minutes ago which was completely unrelated.
Other
No response