1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved EntityRegainHealthEvent bug or me?

Discussion in 'Help' started by Pab45O, Mar 3, 2018.

  1. Pab45O

    Pab45O Spider Jockey

    Messages:
    37
    GitHub:
    Pab450
    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? 

        
    }

    }
     
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    don't you need a case for CAUSE_SATURATION in the switch?
     
  3. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    cancel your condition and test it.
     
  4. Pab45O

    Pab45O Spider Jockey

    Messages:
    37
    GitHub:
    Pab450
    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;
                }

            }
     
  5. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    PHP:
    if($entity instanceof Player){

                switch(
    $event->getRegainReason()){

                    case 
    EntityRegainHealthEvent::CAUSE_SATURATION:
                        if(!
    $event->isCancelled()){
                           
    $event->setCancelled(true);
                        }
                       
    //ToDo your code
                        
    break;
                }

            }
     
  6. Pab45O

    Pab45O Spider Jockey

    Messages:
    37
    GitHub:
    Pab450
    PHP:
    public function RegainHealth(EntityRegainHealthEvent $event){
            
    $event->setCancelled(true); //Ho, no cancelled, always :D
            
        
    }
     
  7. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Why not ;)
     
  8. Pab45O

    Pab45O Spider Jockey

    Messages:
    37
    GitHub:
    Pab450
    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".
     
  9. Pab45O

    Pab45O Spider Jockey

    Messages:
    37
    GitHub:
    Pab450
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.