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

How can I hide suffocation message?

Discussion in 'Development' started by Levi, Oct 28, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    how can I hide suffocation and other cause from sending in chat?
    PHP:
    public function onDeath(PlayerDeathEvent $event)
        {
            
    $cause $event->getEntity()->getLastDamageCause();
            if (
    $cause instanceof EntityDamageByEntityEvent) {
                
    $event->setDeathMessage("");
            }
        }
    i tried if($cause == EntityDamageEvent::CAUSE_FALL){
    $event->setDeathMessage(""); but don't work
    }
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The last damage cause is an event object. You need to get the cause inside the object to compare with the int constant.
     
    jasonwynn10 likes this.
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PHP:
    public function onDeath(PlayerDeathEvent $e){
    if(
    $e->getCause() == 3){
       
    $e->setDeathMessage('');
    }
    }
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    doesn't work.
     
  5. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Try this
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
            
    $player $event->getPlayer();
            if (
    $player instanceof Player){
                
    $cause $player->getLastDamageCause()->getCause();
                if(
    $cause === EntityDamageEvent::CAUSE_SUFFOCATION){
                    
    $event->setDeathMessage(null);
                }
            }
        }
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    A player can die without a damage cause. Your code will lead to calling a method on null.
     
    jasonwynn10 likes this.
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    What's NPE?
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I meant trying to use a null as an object and call a method upon it. NullPointerException is the name of this infamous exception in Java for this kind of errors.
     
    jasonwynn10 and Kyd like this.
  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.