Hey Guys, When a Player dies on my server my PlayerDeathListener calls a function which gives the Player an effect + items and more but he will get this on the death screen and not after. Is it possible to make this in the death event instad of respawn event?
I would do it on the PlayerRespawnEvent so here is how to give item now as for Potion Effects i don't know. PHP: public function PlayerRespawnEvent(PlayerRespawnEvent $ev){ $item = Item::DIAMOND; $ev->getPlayer()->getInventory()->setItem($ev->getPlayer()->getInventory()->firstEmpty(), $item); } Sorry that i do not know effects but i still hope this was of help. If anyone knows how to set effects i would also like to know. Edit: I Figured it out i think as i haven't had time to test it but just add PHP: $ev->getPlayer()->addEffect(Effect::SPEED); You can change the effect to waterever the different ones are here
No, when the player is dead, his new things aren't set up yet. The setup at respawn (before PlayerRespawnEvent is fired) will override most changes.
Mentioning doesn't show alerts to me. Effect->setDuration E.g. Effect::getEffect($effectId)->setDuration($durationInTicks)
PHP: $item = Item::DIAMOND;$sender->getPlayer()->getInventory()->setItem($ev->getPlayer()->getInventory()->firstEmpty(), $item); should be PHP: $item = Item::get(Item::DIAMOND);$sender->getInventory()->setItem($sender->getInventory()->firstEmpty(), $item); since you checked that $sender is instance of Player, you do not need to getPlayer() on sender