[SPIGOT-6619] A setCause(DamageCause) method in EntityDamageEvent Created: 03/Jul/21  Updated: 11/Feb/24  Resolved: 11/Feb/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: ManosSef Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: API

Version: CraftBukkit version 3168-Spigot-a483d2c-bc00005 (MC: 1.17) (Implementing API version 1.17-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

This could be a way to change the DamageCause of EntityDamageEvent. I intend to change the DamageCause of damage dealt to players when the damage meets specific conditions, so that the death message is different.



 Comments   
Comment by Doc [ 11/Feb/24 ]

With the adition of https://hub.spigotmc.org/javadocs/spigot/org/bukkit/damage/DamageSource.html you can cancel the damage and force a new damage for this case.

Comment by Parker Hawke [ 03/Jul/21 ]

If you intend on changing the death message based on specific conditions, the PlayerDeathEvent and its #setDeathMessage() method are what you want, not the damage event. You can either associate Metadata with the player in the damage event under specific conditions, or keep reference to the Player or its UUID in a Set and handle it appropriately in the PlayerDeathEvent.

Comment by Black Hole [ 03/Jul/21 ]

This is nearly impossible to implement right. In vanilla Minecraft the damage source is an object that stores additional information about the damage. So you have to reconstruct that object and rerun the logic for this this damage source and this time without calling the event again. And then there are multiple sources that call this event.

Generated at Sat Apr 05 09:38:08 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.