Problem with DamageSources


#1

I’m working on a plugin where I want to replace all the damage values by own ones.

Therefore I use a DamageEntityEvent and from there on I retrieve the DamageSource by event.getSource();

My problem is now that I don’t see a way to distinguish for example explosion damage of creepers of that of tnt or to distinguish different damage potions.

If you print out the Source you can see that the information of whether the explosion was the one of a creeper or a tnt is saved in there:

[11:13:24 INFO] [STDOUT]: EntityDamageSource{Name=explosion.player, Type=minecraft:explosive, Source=EntityCreeper[‘Creeper’/241, l=‘world’, x=’-230,70, y=67,00, z=322,70]}

But there is no method to retrieve the values Name and Source. There is one for Type but the type is the same for the tnt and the creeper.

So my question is, is there an way to get these values or if not is there another way to distinguish different damage sources?


#2

Cast DamageSource into EntityDamageSource. From there use .getEntity() and then use instanceof to check if it was a creeper or entity tnt