mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 11:26:37 +00:00
Server: Error on unknown generators when generating new worlds from config, instead of silently using DEFAULT
this is consistent with the behaviour of loading worlds.
This commit is contained in:
parent
7b6632941d
commit
fa93a8d78f
@ -106,7 +106,6 @@ use pocketmine\world\format\io\WorldProviderManager;
|
|||||||
use pocketmine\world\format\io\WritableWorldProviderManagerEntry;
|
use pocketmine\world\format\io\WritableWorldProviderManagerEntry;
|
||||||
use pocketmine\world\generator\Generator;
|
use pocketmine\world\generator\Generator;
|
||||||
use pocketmine\world\generator\GeneratorManager;
|
use pocketmine\world\generator\GeneratorManager;
|
||||||
use pocketmine\world\generator\normal\Normal;
|
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use pocketmine\world\WorldCreationOptions;
|
use pocketmine\world\WorldCreationOptions;
|
||||||
use pocketmine\world\WorldManager;
|
use pocketmine\world\WorldManager;
|
||||||
@ -968,6 +967,17 @@ class Server{
|
|||||||
$this->pluginManager->loadPlugins($this->pluginPath);
|
$this->pluginManager->loadPlugins($this->pluginPath);
|
||||||
$this->enablePlugins(PluginEnableOrder::STARTUP());
|
$this->enablePlugins(PluginEnableOrder::STARTUP());
|
||||||
|
|
||||||
|
$getGenerator = function(string $generatorName, string $worldName) : ?string{
|
||||||
|
$generatorClass = GeneratorManager::getInstance()->getGenerator($generatorName);
|
||||||
|
if($generatorClass === null){
|
||||||
|
$this->logger->error($this->language->translate(KnownTranslationFactory::pocketmine_level_generationError(
|
||||||
|
$worldName,
|
||||||
|
KnownTranslationFactory::pocketmine_level_unknownGenerator($generatorName)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
return $generatorClass;
|
||||||
|
};
|
||||||
|
|
||||||
foreach((array) $this->configGroup->getProperty("worlds", []) as $name => $options){
|
foreach((array) $this->configGroup->getProperty("worlds", []) as $name => $options){
|
||||||
if($options === null){
|
if($options === null){
|
||||||
$options = [];
|
$options = [];
|
||||||
@ -980,7 +990,11 @@ class Server{
|
|||||||
|
|
||||||
if(isset($options["generator"])){
|
if(isset($options["generator"])){
|
||||||
$generatorOptions = explode(":", $options["generator"]);
|
$generatorOptions = explode(":", $options["generator"]);
|
||||||
$creationOptions->setGeneratorClass(GeneratorManager::getInstance()->getGenerator(array_shift($generatorOptions)) ?? Normal::class);
|
$generatorClass = $getGenerator(array_shift($generatorOptions), $name);
|
||||||
|
if($generatorClass === null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$creationOptions->setGeneratorClass($generatorClass);
|
||||||
if(count($generatorOptions) > 0){
|
if(count($generatorOptions) > 0){
|
||||||
$creationOptions->setGeneratorOptions(implode(":", $generatorOptions));
|
$creationOptions->setGeneratorOptions(implode(":", $generatorOptions));
|
||||||
}
|
}
|
||||||
@ -1010,14 +1024,17 @@ class Server{
|
|||||||
$this->configGroup->setConfigString("level-name", "world");
|
$this->configGroup->setConfigString("level-name", "world");
|
||||||
}
|
}
|
||||||
if(!$this->worldManager->loadWorld($default, true)){
|
if(!$this->worldManager->loadWorld($default, true)){
|
||||||
$creationOptions = WorldCreationOptions::create()
|
$generatorClass = $getGenerator($this->configGroup->getConfigString("level-type"), $default);
|
||||||
->setGeneratorClass(GeneratorManager::getInstance()->getGenerator($this->configGroup->getConfigString("level-type")) ?? Normal::class)
|
if($generatorClass !== null){
|
||||||
->setGeneratorOptions($this->configGroup->getConfigString("generator-settings"));
|
$creationOptions = WorldCreationOptions::create()
|
||||||
$convertedSeed = Generator::convertSeed($this->configGroup->getConfigString("level-seed"));
|
->setGeneratorClass($generatorClass)
|
||||||
if($convertedSeed !== null){
|
->setGeneratorOptions($this->configGroup->getConfigString("generator-settings"));
|
||||||
$creationOptions->setSeed($convertedSeed);
|
$convertedSeed = Generator::convertSeed($this->configGroup->getConfigString("level-seed"));
|
||||||
|
if($convertedSeed !== null){
|
||||||
|
$creationOptions->setSeed($convertedSeed);
|
||||||
|
}
|
||||||
|
$this->worldManager->generateWorld($default, $creationOptions);
|
||||||
}
|
}
|
||||||
$this->worldManager->generateWorld($default, $creationOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$world = $this->worldManager->getWorldByName($default);
|
$world = $this->worldManager->getWorldByName($default);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user