Hey! I have been trying to Simulate Death Event in the reason to skip the death screen and make my actions after the death. Is there a way to do such a thing? I know I am not able to directly cancel the EntityDeathEvent. My Code: PHP: public function onDamage(EntityDamageEvent $event){ $player = $event->getEntity(); if($player instanceof Player){ if($event->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK){ if($event->getFinalDamage() >= $player->getHealth()){ $event->setCancelled(); $player->teleport($player->getLevel()->getSafeSpawn()); } } }} Now, the code works, but I want it to act like the player actually died.
clear the players inventory set health and food to 20 remove all effects and call playerdeathevent $this->getServer()->getPluginManager()->callEvent(new PlayerDeathEvent($player, [], ""));
Thanks Here is the code: PHP: public function onDamage(EntityDamageEvent $event){ $player = $event->getEntity(); if($player instanceof Player){ if($event->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK){ if($event->getFinalDamage() >= $player->getHealth()){ $event->setCancelled(); $player->teleport($player->getLevel()->getSafeSpawn()); $this->getServer()->getPluginManager()->callEvent(new EntityDeathEvent($player, [], 1)); } } }}