[Feature Request] EntityHealthChangeEvent (Cancelable)
Title says mostly it. An Event that is called when the Health are tried to be changed.
This opens the possibility to cancel the event and handle own logic at that point. Probably not a big change and makes Minestom a little bit more customizeable.
Specific Use-case:
- Whenever a player's Health will be set to 0 from any extension or other source, then there is an option to check it and cancel it
- So you can prevent a player from getting the respawn screen (especially to prevent the "loading world" screen after clicking respawn or automatically respawning) because you can teleport the player to the same location and handle the death custom
I think EntityDamageEvent should cover the use cases here, and if you want to prevent a player from going through the respawn screen, you could
1 - Send a packet that tells the client that doImmediateRespawn is true 2 - Add a listener to Entity Damage Event with something along the lines of:
if(event.getDamage() > event.getEntity().getHealth()) {
event.setCancelled(true);
}
Good point but while i was reading it seems that the Event will not be called if some code executes
Player player;
player.setHealth(0);
In which case you can simply use EntityDeathEvent or equivalent and call your own EntityHealthChangeEvent
EntityDeathEvent is not cancelable