Event for player health regeneration


#1

Hello toghether,

I currently switching from Spigot to Sponge to support mods on my server. Due to that I have to migrate my old Spigot based plugin to Sponge.

In the Spigot world there was an event for the players and entities health regeneration called EntityRegainHealthEvent. I always canceled this event, because I have developt my own health mangement. In the Sponge java docs I only could found the HealEntityEvent event which isn’t triggering when for example the player regenerates health.

Is there any other event I could us to stop the default health regeneration?

Regards
Sascha


#2

Sponge works differently to spigot with events. The main difference is you can listen to interfaces, the other difference is that events are trigged by plugins too, so the “default” heath regeneration is something you will need to filter for.

However due to health being related to data, you can use the ChangeDataHolderEvent.ValueChange which should fire any time any data changes, from there you can filter the data using getOriginalChanges.

I would also post a issue on sponge api github page to say that EntityRegainHealthEvent is not firing.


#3

I tried to use the ChangeDataHolderEvent.ValueChange event. It get fired for example when I start or stop sprinting but it didn’t get fired when the players food or health level changed.

I opened an issue on Github for the HealEntityEvent event


#4

Answer from the developers: @Sago92 correct, it hasn’t been implemented. An oversight on our end! I’ll see what I can whip up to implement it in a rough manne

I will update this post when the implementation is done