Hello to the great community Pmmp, today I wanted to test an old code of one of my plugins and I found a bug (I think), i haven't found report of this bug on pmmp issues on github . I make sure before that it is a bug and that I use the function as it should be used. I try with this one to cancel the fact of being able to regenerate his life by having the food to the maximum and it can't cancel this event ! It's really a bug or it's me? (Sorry for my bad english, im french) Love. PHP: /*** @param EntityRegainHealthEvent $event*/public function RegainHealth(EntityRegainHealthEvent $event){ $entity = $event->getEntity(); $reason = $event->getRegainReason(); /*if($entity instanceof Player && $reason == EntityRegainHealthEvent::CAUSE_SATURATION){ var_dump($event->getAmount()); $entity->setHealth($entity->getHealth() - $event->getAmount()); var_dump($entity->getHealth()); }*/ //hack for fix this bug if($entity instanceof Player){ switch($event->getRegainReason()){ case EntityRegainHealthEvent::CAUSE_REGEN: case EntityRegainHealthEvent::CAUSE_EATING: case EntityRegainHealthEvent::CAUSE_CUSTOM: $event->setCancelled(); //no cancelled. break; } //It's really a bug or it's me? }}
Because I did several tests, i have just forget to put it back, but the value does not change anything, the event can not be canceled PHP: if($entity instanceof Player){ switch($event->getRegainReason()){ case EntityRegainHealthEvent::CAUSE_SATURATION: $event->setCancelled(); //no cancelled, always break; } }
PHP: if($entity instanceof Player){ switch($event->getRegainReason()){ case EntityRegainHealthEvent::CAUSE_SATURATION: if(!$event->isCancelled()){ $event->setCancelled(true); } //ToDo your code break; } }
PHP: public function RegainHealth(EntityRegainHealthEvent $event){ $event->setCancelled(true); //Ho, no cancelled, always :D }
Well, as nobody has any explanation to this problem I conclude that it is reelemeent a bug and so I will go open an issue on the pmmp of Github, I set thread "Solved".