Level: __construct() now accepts a LevelProvider object instead of string, string

This is made possible by the removal of LevelProvider dependence on their Levels, and furthers the goal of #2024.
This commit is contained in:
Dylan K. Taylor
2018-05-01 18:43:11 +01:00
parent 53c35aaa1d
commit 2e7db552dc
2 changed files with 13 additions and 22 deletions

View File

@ -317,27 +317,18 @@ class Level implements ChunkManager, Metadatable{
/**
* Init the default level data
*
* @param Server $server
* @param string $name
* @param string $path
* @param string $provider Class that extends LevelProvider
*
* @throws \Exception
* @param Server $server
* @param string $name
* @param LevelProvider $provider
*/
public function __construct(Server $server, string $name, string $path, string $provider){
public function __construct(Server $server, string $name, LevelProvider $provider){
$this->blockStates = BlockFactory::getBlockStatesArray();
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
$this->server = $server;
$this->autoSave = $server->getAutoSave();
/** @var LevelProvider $provider */
if(is_subclass_of($provider, LevelProvider::class, true)){
$this->provider = new $provider($path);
}else{
throw new LevelException("Provider is not a subclass of LevelProvider");
}
$this->provider = $provider;
$this->displayName = $this->provider->getName();
$this->worldHeight = $this->provider->getWorldHeight();