Added setting to select the default level format

This commit is contained in:
Shoghi Cervantes 2014-07-29 18:54:40 +02:00
parent e9311f5ceb
commit afe44e6c6f
6 changed files with 27 additions and 2 deletions

View File

@ -1052,7 +1052,9 @@ class Server{
}
}
$provider = "pocketmine\\level\\format\\anvil\\Anvil";
if(($provider = LevelProviderManager::getProviderByName($this->getProperty("level-settings.default-format", "mcregion"))) === null){
$provider = "pocketmine\\level\\format\\mcregion\\McRegion";
}
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
@ -1500,6 +1502,7 @@ class Server{
$this->generationManager = new GenerationRequestManager($this);
LevelProviderManager::addProvider($this, "pocketmine\\level\\format\\anvil\\Anvil");
LevelProviderManager::addProvider($this, "pocketmine\\level\\format\\mcregion\\McRegion");
Generator::addGenerator("pocketmine\\level\\generator\\Flat", "flat");

View File

@ -32,6 +32,13 @@ interface LevelProvider{
*/
public function __construct(Level $level, $path);
/**
* Returns the full provider name, like "anvil" or "mcregion", will be used to find the correct format.
*
* @return string
*/
public static function getProviderName();
/** @return string */
public function getPath();

View File

@ -36,7 +36,7 @@ abstract class LevelProviderManager{
if(!is_subclass_of($class, "pocketmine\\level\\format\\LevelProvider")){
throw new \Exception("Class is not a subclass of LevelProvider");
}
self::$providers[strtolower($class)] = $class;
self::$providers[strtolower($class::getProviderName())] = $class;
}
/**
@ -56,4 +56,9 @@ abstract class LevelProviderManager{
return null;
}
public static function getProviderByName($name){
$name = trim(strtolower($name));
return isset(self::$providers[$name]) ? self::$providers[$name] : null;
}
}

View File

@ -42,6 +42,9 @@ class Anvil extends BaseLevelProvider{
/** @var Chunk[] */
protected $chunks = [];
public static function getProviderName(){
return "anvil";
}
public static function isValid($path){
$isValid = (file_exists($path . "/level.dat") and is_dir($path . "/region/"));

View File

@ -41,6 +41,9 @@ class McRegion extends BaseLevelProvider{
/** @var Chunk[] */
protected $chunks = [];
public static function getProviderName(){
return "mcregion";
}
public static function isValid($path){
$isValid = (file_exists($path . "/level.dat") and is_dir($path . "/region/"));

View File

@ -18,6 +18,10 @@ debug:
#Enables /status
commands: false
level-settings:
default-format: mcregion #The default format that levels will use when created
convert-format: false #If true, converts from a format that is not the default to the default format on load
chunk-sending:
per-tick: 4
compression-level: 9