How to set some world no keepinventory some world have keepinventory for exmaple pvp have keepinventory spawn no keepinventory
Use PlayerDeathEvent, check if player is in pvp world then set drops to an empty array and finally store the inventory items into a global array like this: PHP: $player = $event->getPlayer();if($player->getLevel()->getName() == "pvp") { $event->setDrops([]); $this->contents[$player->getName()] = $player->getInventory()->getContents();}// Array format would be like this$contents = [ "playerName" => $content]; Now you're going to use PlayerRespawnEvent and you're going to check if the player name is in the array, then you want to add those contents into the player inventory. Finally you're going to unset the player array. PHP: $player = $event->getPlayer();if(isset($this->contents[$username = $player->getName()])) { $player->getInventory()->setContents($this->contents[$username]); unset($this->contents[$username]);}
There's an even simpler method PHP: public function PlayerDeathEvent(PlayerDeathEvent $event){ if($event->getPlayer()->getLevel()->getName() === "pvp") $event->setKeepInventory(true);}