Hello, I want to copy a world and I have this error : Code: "pocketmine\utils\LevelException: "Invalid empty level name" (EXCEPTION) in "/src/pocketmine/Server" at line 1160" "[Network] Stopped interface pocketmine\network\RakLibInterface due to Call to a member function getName() on null" "zend_mm_heap corrupted" My code (based on that of PEMapModder) : PHP: public function copyWorld(){ $src = $this->getDataFolder() . "/Map/Test"; $dst = $this->getServer()->getDataPath() . "/worlds"; $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))){ if(($file != '.') && ($file != '..')){ if(is_dir($src . '/' . $file)){ $this->copyWorld($src . '/' . $file, $dst . '/' . $file); }else{ copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); } Thank you.
https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.php#L959 Are you loading the copied world?
Before copying, I unload and delete the world and after copying I load the world. My code for delete : PHP: public function deleteWorld(){ $dirPath = $this->getServer()->getDataPath() . "/worlds/Test"; if(is_dir($dirPath)){ $objects = scandir($dirPath); foreach($objects as $object){ if($object != "." && $object != ".."){ if(filetype($dirPath . DIRECTORY_SEPARATOR . $object) == "dir"){ $this->deleteWorld($dirPath . DIRECTORY_SEPARATOR . $object); }else{ unlink($dirPath . DIRECTORY_SEPARATOR . $object); } } } reset($objects); rmdir($dirPath); } } The function wich I use for reset the world : PHP: public function resetWorld(){ $this->getServer()->unloadLevel($this->getServer()->getLevelByName("Test")); $this->deleteWorld(); $this->copyWorld(); $this->getServer()->loadLevel($this->getServer()->getLevelByName("Test")); }
Server::loadLevel expects a string. Server::getLevelByName returns a previously loaded Level, or null if the level wasn't loaded, which is your case. You've to pass the name of the level directly to Server::loadLevel.
Thank you !! But I have again the error (which crashing the server) : Code: "[Network] Stopped interface pocketmine\network\RakLibInterface due to Call to a member function getName() on null" "zend_mm_heap corrupted"
Can we see the server log? Fixing issues is awfully hard without context. Is it while stopping the server? Does it appear when the server is loading your plugin?
The error appears when the "resetWorld" function is called.... The world is unloading and after the error appears... Maybe when the world is loading ? (I am almost sure but how can I correct this error ?) Code: [36m21:52:19[36m | [m[37mPocketMine thread:INFO[36m > [m[37mUnloading level "Test"[m [36m21:52:19[36m | [m[37mPocketMine thread:INFO[36m > [m[37mPreparing level "Test"[m [36m21:52:19[36m | [m[31mPocketMine thread:CRITICAL[36m > [m[31m[Network] Stopped interface pocketmine\network\RakLibInterface due to Call to a member function getName() on null[m zend_mm_heap corrupted
Awfully strange that when calling world functions the network decides to break. Do you mess with network functions in your plugin?