Can you share what you tried, and what about them didn't work? Did you get any errors? I believe you can just listen for EntityRegainHealthEvent and cancel it.
Code: public function onRegainHealth(EntityRegainHealthEvent $event){ $p = $event->getEntity(); if($p instanceof Player){ if($event->getRegainReason() === EntityRegainHealthEvent::CAUSE_EATING || $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_CUSTOM || $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_REGEN || $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_SATURATION){ $event->setCancelled(true); } } }
Are there any regain reasons that you don't want to cancel for? You could remove the check if so, and just cancel all regen. Do you get any errors? If you only want to allow one regain reason, for example, CAUSE_MAGIC, You can try this: PHP: if(!$event->getRegainReason() === EntityRegainHealthEvent::CAUSE_MAGIC) { $event->setCancelled(); } How are you testing your code?
Make sure You've registered listeners and added class paths (damn, I still don't know how to call it because `import` is just not correct). Adding echo or any other thing that can leave mark you can see, should help you to debug your code. It basically tells you if code were execute in that scope. If you don't know how to add an echo statement, stop coding!
I put everything in my code >:v But the only thing that does not work is regeneration>: v It is done but it does not work the events are registered and they are use them well
Client-sided health regeneration is a client bug, it's been noted at https://github.com/pmmp/PocketMine-MP/issues/23