Server: Changed logic of isLevelGenerated() to prevent astonishing behaviour

Previously to this, a level would be considered "not generated" if no level providers registered as valid for that directory. This caused astonishing behaviour when the user's world has, for example, a mixture of .mca and .mcr region files - the world would instead get _re-generated_ according to the default level format, which might or might not load the existing regions depending on the format used for generation. This behaviour is utterly absurd.

This changes the behaviour of the generated check to check for a non-empty directory in the given path. Non-empty directories without recognized world files in them are now considered to have an unknown format.
This commit is contained in:
Dylan K. Taylor 2018-03-12 10:24:59 +00:00
parent d478661961
commit 8a0414f306

View File

@ -1003,7 +1003,7 @@ class Server{
$provider = LevelProviderManager::getProvider($path);
if($provider === null){
$this->logger->error($this->getLanguage()->translateString("pocketmine.level.loadError", [$name, "Unknown provider"]));
$this->logger->error($this->getLanguage()->translateString("pocketmine.level.loadError", [$name, "Cannot identify format of world"]));
return false;
}
@ -1117,10 +1117,9 @@ class Server{
}
$path = $this->getDataPath() . "worlds/" . $name . "/";
if(!($this->getLevelByName($name) instanceof Level)){
if(LevelProviderManager::getProvider($path) === null){
return false;
}
return is_dir($path) and !empty(array_filter(scandir($path, SCANDIR_SORT_NONE), function($v){
return $v !== ".." and $v !== ".";
}));
}
return true;