I am trying to use teleport with the constructor Position and also tried $level->getSafeSpawn() but I think the level is not loaded because it teleports to the same level you are on. This happened in different servers I tested and if it doesn't work on multiple servers it might be a pocketmine bug. I also tried $server->getLevelByName("world2")->getName() and it crashes with the error of "Call to a member function getName() on null" So anyone know a fix to this or how to load levels better, or is there a better way to teleport to multiples levels?
PHP: //onEnable $this->getServer()->loadLevel($level);//$player->teleport(new Position($x,$y$z,$this->getServer()->getLevelByName($level)); teleport to Default spawn PHP: $player->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn());
Try loading level/s on enable. PHP: public function OnEnable(){# I suppose it's more than 1 level.$to_load = ["Level Name","Level Name 2" /* ... */];# You can get the server by folder name, but in this case I'll get it by the level name.foreach($to_load /* levels */ as $level){$level = $this->getServer()->getLevelByName($level);$this->getServer()->loadLevel($level);}# Now all levels inside $to_load are loaded.}