From 62465fa6769307a27ea75b9106a76467ff1d33b4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 19 Jul 2023 18:05:30 +0100 Subject: [PATCH] Integrate FolderPluginLoader the motivation for this is described in #5917 a new version of DevTools will be required, as the current version will cause the server to abort during startup with this change due to duplicated plugin loading. --- src/Server.php | 2 + src/plugin/FolderPluginLoader.php | 72 +++++++++++++++++++++++++++++++ tests/travis.sh | 2 - 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/plugin/FolderPluginLoader.php diff --git a/src/Server.php b/src/Server.php index f604c93d7..5573f63b1 100644 --- a/src/Server.php +++ b/src/Server.php @@ -79,6 +79,7 @@ use pocketmine\player\PlayerDataLoadException; use pocketmine\player\PlayerDataProvider; use pocketmine\player\PlayerDataSaveException; use pocketmine\player\PlayerInfo; +use pocketmine\plugin\FolderPluginLoader; use pocketmine\plugin\PharPluginLoader; use pocketmine\plugin\Plugin; use pocketmine\plugin\PluginEnableOrder; @@ -988,6 +989,7 @@ class Server{ $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool("plugins.legacy-data-dir", true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); $this->pluginManager->registerInterface(new ScriptPluginLoader()); + $this->pluginManager->registerInterface(new FolderPluginLoader($this->autoloader)); $providerManager = new WorldProviderManager(); if( diff --git a/src/plugin/FolderPluginLoader.php b/src/plugin/FolderPluginLoader.php new file mode 100644 index 000000000..9250a4e15 --- /dev/null +++ b/src/plugin/FolderPluginLoader.php @@ -0,0 +1,72 @@ +getPluginDescription($file); + if($description !== null){ + $this->loader->addPath($description->getSrcNamespacePrefix(), "$file/src"); + } + } + + /** + * Gets the PluginDescription from the file + */ + public function getPluginDescription(string $file) : ?PluginDescription{ + $pluginYmlPath = Path::join($file, "plugin.yml"); + if(is_dir($file) && file_exists($pluginYmlPath)){ + try{ + $yaml = Filesystem::fileGetContents($pluginYmlPath); + }catch(\RuntimeException){ + //TODO: this ought to be logged + return null; + } + return new PluginDescription($yaml); + } + + return null; + } + + public function getAccessProtocol() : string{ + return ""; + } +} diff --git a/tests/travis.sh b/tests/travis.sh index 094f65905..316c9f200 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -19,8 +19,6 @@ rm PocketMine-MP.phar 2> /dev/null mkdir "$DATA_DIR" mkdir "$PLUGINS_DIR" -cd tests/plugins/DevTools -php -dphar.readonly=0 ./src/ConsoleScript.php --make ./ --relative ./ --out "$PLUGINS_DIR/DevTools.phar" cd ../../.. composer make-server