i tried: PHP: public function onDeath(PlayerDeathEvent $event) { $player = $event->getPlayer(); $name = $player->getName(); $xp = $player->getXpDropAmount(); $this->xp[$name] = $xp; if ($event->getDrops() instanceof ExperienceOrb) { $event->setDrops([]); } } public function onRespawn(PlayerRespawnEvent $event) { $player = $event->getPlayer(); $player->setXpLevel($this->xp[$player->getName()]); unset($this->xp[$player->getName()]); } but dont work it does not give my xp back
I know this issue was brought up a while back, but there are a few weird issues with PlayerRespawnEvent. It's called before attributes are reset, so the xp you set is immediately set back to default, as you can see here: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php#L3657-L3685. XP is an attribute, which is handled by the AttributeMap. In these lines, all attributes are reset. If you were to try to set different health, hunger, etc. to a player on RespawnEvent, it wouldn't seem to work. It does work, it just gets negated. One workaround would be to delay setting the experience with a task, or possibly, PlayerSpawnEvent could be helpful? This issue is similar, and may need reopened since it's relevant now.