Level generators can be set in server.properties

This commit is contained in:
Shoghi Cervantes 2014-09-12 01:05:32 +02:00
parent d298adabad
commit 83eb9f778a
3 changed files with 25 additions and 22 deletions

View File

@ -1061,12 +1061,8 @@ class Server{
if($generator !== null and class_exists($generator) and is_subclass_of($generator, "pocketmine\\level\\generator\\Generator")){ if($generator !== null and class_exists($generator) and is_subclass_of($generator, "pocketmine\\level\\generator\\Generator")){
$generator = new $generator($options); $generator = new $generator($options);
}else{ }else{
if(strtoupper($this->getLevelType()) == "FLAT"){ $options["preset"] = $this->getConfigString("generator-settings", "");
$generator = Generator::getGenerator("flat"); $generator = Generator::getGenerator($this->getLevelType());
$options["preset"] = $this->getConfigString("generator-settings", "");
}else{
$generator = Generator::getGenerator("normal");
}
} }
if(($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null){ if(($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null){
@ -2051,6 +2047,8 @@ class Server{
foreach($this->interfaces as $interface){ foreach($this->interfaces as $interface){
$interface->process(); $interface->process();
} }
Timings::$connectionTimer->stopTiming(); Timings::$connectionTimer->stopTiming();
Timings::$schedulerTimer->startTiming(); Timings::$schedulerTimer->startTiming();

View File

@ -44,14 +44,13 @@ class GenerationChunkManager implements ChunkManager{
protected $changes = []; protected $changes = [];
public function __construct(GenerationManager $manager, $levelID, $seed, $class, array $options){ public function __construct(GenerationManager $manager, $levelID, $seed, $class, array $options){
if(!is_subclass_of($class, "pocketmine\\level\\generator\\Generator")){ if(!class_exists($class, true) or !is_subclass_of($class, "pocketmine\\level\\generator\\Generator")){
throw new \Exception("Class is not a subclass of Generator"); throw new \Exception("Class $class does not exists or is not a subclass of Generator");
} }
$this->levelID = $levelID; $this->levelID = $levelID;
$this->seed = $seed; $this->seed = $seed;
$this->manager = $manager; $this->manager = $manager;
$this->generator = new $class($options); $this->generator = new $class($options);
$this->generator->init($this, new Random($seed)); $this->generator->init($this, new Random($seed));
} }
@ -116,9 +115,11 @@ class GenerationChunkManager implements ChunkManager{
} }
public function generateChunk($chunkX, $chunkZ){ public function generateChunk($chunkX, $chunkZ){
$this->getChunk($chunkX, $chunkZ); try{
$this->generator->generateChunk($chunkX, $chunkZ); $this->getChunk($chunkX, $chunkZ);
$this->setChunkGenerated($chunkX, $chunkZ); $this->generator->generateChunk($chunkX, $chunkZ);
$this->setChunkGenerated($chunkX, $chunkZ);
}catch(\Exception $e){}
} }
public function populateChunk($chunkX, $chunkZ){ public function populateChunk($chunkX, $chunkZ){

View File

@ -122,18 +122,22 @@ class GenerationManager{
$chunkX = $chunkZ = null; $chunkX = $chunkZ = null;
while($this->shutdown !== true){ while($this->shutdown !== true){
if(count($this->requestQueue) > 0){ try{
foreach($this->requestQueue as $levelID => $chunks){ if(count($this->requestQueue) > 0){
if(count($chunks) === 0){ foreach($this->requestQueue as $levelID => $chunks){
unset($this->requestQueue[$levelID]); if(count($chunks) === 0){
}else{ unset($this->requestQueue[$levelID]);
Level::getXZ($key = key($chunks), $chunkX, $chunkZ); }else{
unset($this->requestQueue[$levelID][$key]); Level::getXZ($key = key($chunks), $chunkX, $chunkZ);
$this->generateChunk($levelID, $chunkX, $chunkZ); unset($this->requestQueue[$levelID][$key]);
$this->generateChunk($levelID, $chunkX, $chunkZ);
}
} }
}else{
$this->readPacket();
} }
}else{ }catch(\Exception $e){
$this->readPacket(); $this->logger->warning("[Generator Thread] Exception: ".$e->getMessage() . " on file \"".$e->getFile()."\" line ".$e->getLine());
} }
} }
} }