mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-10 15:59:39 +00:00
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.
This commit is contained in:
parent
aac5944396
commit
62465fa676
@ -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(
|
||||
|
72
src/plugin/FolderPluginLoader.php
Normal file
72
src/plugin/FolderPluginLoader.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
use pocketmine\thread\ThreadSafeClassLoader;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function file_exists;
|
||||
use function is_dir;
|
||||
|
||||
class FolderPluginLoader implements PluginLoader{
|
||||
public function __construct(
|
||||
private readonly ThreadSafeClassLoader $loader
|
||||
){}
|
||||
|
||||
public function canLoadPlugin(string $path) : bool{
|
||||
return is_dir($path) && file_exists(Path::join($path, "plugin.yml")) && file_exists(Path::join($path, "src"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the plugin contained in $file
|
||||
*/
|
||||
public function loadPlugin(string $file) : void{
|
||||
$description = $this->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 "";
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user