mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Inject WorldProviderManager to WorldManager's constructor, no longer singleton
This commit is contained in:
@@ -56,6 +56,9 @@ class WorldManager{
|
||||
/** @var string */
|
||||
private $dataPath;
|
||||
|
||||
/** @var WorldProviderManager */
|
||||
private $providerManager;
|
||||
|
||||
/** @var World[] */
|
||||
private $worlds = [];
|
||||
/** @var World|null */
|
||||
@@ -72,9 +75,10 @@ class WorldManager{
|
||||
/** @var int */
|
||||
private $autoSaveTicker = 0;
|
||||
|
||||
public function __construct(Server $server, string $dataPath){
|
||||
public function __construct(Server $server, string $dataPath, WorldProviderManager $providerManager){
|
||||
$this->server = $server;
|
||||
$this->dataPath = $dataPath;
|
||||
$this->providerManager = $providerManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +183,7 @@ class WorldManager{
|
||||
|
||||
$path = $this->getWorldPath($name);
|
||||
|
||||
$providers = WorldProviderManager::getInstance()->getMatchingProviders($path);
|
||||
$providers = $this->providerManager->getMatchingProviders($path);
|
||||
if(count($providers) !== 1){
|
||||
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.level.loadError", [
|
||||
$name,
|
||||
@@ -216,7 +220,7 @@ class WorldManager{
|
||||
}
|
||||
$this->server->getLogger()->notice("Upgrading world \"$name\" to new format. This may take a while.");
|
||||
|
||||
$converter = new FormatConverter($provider, WorldProviderManager::getInstance()->getDefault(), $this->server->getDataPath() . "world_conversion_backups", $this->server->getLogger());
|
||||
$converter = new FormatConverter($provider, $this->providerManager->getDefault(), $this->server->getDataPath() . "world_conversion_backups", $this->server->getLogger());
|
||||
$provider = $converter->execute();
|
||||
|
||||
$this->server->getLogger()->notice("Upgraded world \"$name\" to new format successfully. Backed up pre-conversion world at " . $converter->getBackupPath());
|
||||
@@ -251,7 +255,7 @@ class WorldManager{
|
||||
|
||||
Utils::testValidInstance($generator, Generator::class);
|
||||
|
||||
$providerClass = WorldProviderManager::getInstance()->getDefault();
|
||||
$providerClass = $this->providerManager->getDefault();
|
||||
|
||||
$path = $this->getWorldPath($name);
|
||||
/** @var WritableWorldProvider $providerClass */
|
||||
@@ -307,7 +311,7 @@ class WorldManager{
|
||||
}
|
||||
$path = $this->getWorldPath($name);
|
||||
if(!($this->getWorldByName($name) instanceof World)){
|
||||
return count(WorldProviderManager::getInstance()->getMatchingProviders($path)) > 0;
|
||||
return count($this->providerManager->getMatchingProviders($path)) > 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user