This does not remove the level from the server. This finalizes the level, but only Server::unloadLevel() properly removes the reference from the server to the level.
What? One level instance represents once the level gets loaded. If two level references are the same object, the level isn't reloaded. Why "can't load it anymore"? If you properly reload something, you are getting it completely fresh, just like it was never loaded before.
PHP: $this->getLevelByName("lol")->unload();$this->getLevelByName("lol")->load(); That does UNLOAD it and then LOAD it! what's wrong with it?
LOL Did understand it now PHP: 380 public function unload($force = false){LevelUnloadEvent($this);getName() . "\"");getPlayers() as $player){Level){ 400 $player->teleport($this->server->getDefaultLevel()->getSafeSpawn()); 401 } 402 } 403 404 if($this === $defaultLevel){ 405 $this->server->setDefaultLevel(null); 406 } 407 408 $this->close(); 409 410 return true; 411 } It just kicks the player out of the world!
They are internal methods used by PocketMine internal implementation to properly free the resources. If you unload() then load(), it is indeed a "reload", but that doesn't do the purpose of a reloading, that is to create an entirely new loading of the level. Level is not a dummy object used merely for references. It is an actual object that has contents inside it that have to be freed properly. Also, unload() calls close(), which frees the level provider, hence the level data. On the other hand, load() tries to load data using the level provider initialized in constructor, but unload() destroyed the level provider. unload() and load() are just internal handler-like functions that are called when unloading and loading.
PHP: public function backupExists($wname){ return is_file($this->getServer()->getDataPath()."worlds/$wname - Backup/level.dat"); }public function reset($world){ if($world instanceof Level){ $wname = $world->getName();if(!$this->backupExists($wname)) return false; $spawn = $this->getServer()->getDefaultLevel()->getSafeSpawn(); foreach($world->getPlayers() as $p){ $p->teleport($spawn); $p->sendMessage(TextFormat::GOLD."- Restoring current world, teleporting you to spawn"); } $this->getServer()->unloadLevel($world); } $path = $this->getServer()->getDataPath(); $this->recurse_copy($path."worlds/$wname - Backup",$path."worlds/$wname");//$this->getServer()->loadLevel($wname); //optionally load level return true; }public function recurse_copy($src,$dst){ $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { $this->recurse_copy($src . '/' . $file,$dst . '/' . $file); } else { copy($src . '/' . $file,$dst . '/' . $file); } } } closedir($dir); }