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}
The last damage cause is an event object. You need to get the cause inside the object to compare with the int constant.
PHP: public function onDeath(PlayerDeathEvent $e){if($e->getCause() == 3){ $e->setDeathMessage('');}}
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); } } }
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.