mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 15:35:52 +00:00
Inject WorldProviderManager to WorldManager's constructor, no longer singleton
This commit is contained in:
parent
437e4d75ab
commit
c93038f574
@ -932,7 +932,7 @@ class Server{
|
||||
$this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader));
|
||||
$this->pluginManager->registerInterface(new ScriptPluginLoader());
|
||||
|
||||
$providerManager = WorldProviderManager::getInstance();
|
||||
$providerManager = new WorldProviderManager();
|
||||
if(
|
||||
($format = $providerManager->getProviderByName($formatName = (string) $this->configGroup->getProperty("level-settings.default-format"))) !== null and
|
||||
is_a($format, WritableWorldProvider::class, true)
|
||||
@ -942,7 +942,7 @@ class Server{
|
||||
$this->logger->warning($this->language->translateString("pocketmine.level.badDefaultFormat", [$formatName]));
|
||||
}
|
||||
|
||||
$this->worldManager = new WorldManager($this, $this->dataPath . "/worlds");
|
||||
$this->worldManager = new WorldManager($this, $this->dataPath . "/worlds", $providerManager);
|
||||
$this->worldManager->setAutoSave($this->configGroup->getConfigBool("auto-save", $this->worldManager->getAutoSave()));
|
||||
$this->worldManager->setAutoSaveInterval((int) $this->configGroup->getProperty("ticks-per.autosave", 6000));
|
||||
|
||||
|
@ -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;
|
||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\format\io;
|
||||
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\world\format\io\leveldb\LevelDB;
|
||||
use pocketmine\world\format\io\region\Anvil;
|
||||
@ -33,8 +32,6 @@ use function strtolower;
|
||||
use function trim;
|
||||
|
||||
final class WorldProviderManager{
|
||||
use SingletonTrait;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @phpstan-var array<string, class-string<WorldProvider>>
|
||||
|
@ -28,7 +28,8 @@ use pocketmine\world\format\io\WritableWorldProvider;
|
||||
|
||||
require_once dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$writableFormats = array_filter(WorldProviderManager::getInstance()->getAvailableProviders(), function(string $class){
|
||||
$providerManager = new WorldProviderManager();
|
||||
$writableFormats = array_filter($providerManager->getAvailableProviders(), function(string $class){
|
||||
return is_a($class, WritableWorldProvider::class, true);
|
||||
});
|
||||
$requiredOpts = [
|
||||
@ -59,7 +60,7 @@ if((!@mkdir($backupPath, 0777, true) and !is_dir($backupPath)) or !is_writable($
|
||||
die("Backup file path " . $backupPath . " is not writable (permission error or doesn't exist), aborting");
|
||||
}
|
||||
|
||||
$oldProviderClasses = WorldProviderManager::getInstance()->getMatchingProviders($inputPath);
|
||||
$oldProviderClasses = $providerManager->getMatchingProviders($inputPath);
|
||||
if(count($oldProviderClasses) === 0){
|
||||
die("Unknown input world format");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user