How can I load folder plugins without DevTools? When I use PluginManager::loadPlugin($path) it always returns NULL, although it returns the plugin resource when I use DevTools loadPlugin() function, but the problem is that the plugin doesn't get registeres and I don't know how, it never returns the plugin name when I do /plugins. So how can I load folder plugins or how can I register the plugin?
I tried everything, $plugin->setEnabled(true); $this->setEnabled($plugin); (with the DevTools source code)
Spoiler PHP: <?phpnamespace Loader;use pocketmine\plugin\PluginBase;use pocketmine\plugin\PluginLoadOrder;use pocketmine\event\plugin\PluginDisableEvent;use pocketmine\event\plugin\PluginEnableEvent;use pocketmine\plugin\Plugin;use pocketmine\plugin\PluginDescription;use pocketmine\plugin\PluginLoader;use pocketmine\Server;use pocketmine\utils\MainLogger;use pocketmine\utils\TextFormat;class Main extends PluginBase{public function onEnable(){$this->getServer()->getLogger()->info("Enabling Loader");$plugin = $this->loadPlugin($this->getServer()->getDataPath()."TestPlugin");$this->enablePlugin($plugin);var_dump($plugin);}public function enablePlugin(Plugin $plugin){ if($plugin instanceof PluginBase and !$plugin->isEnabled()){ $this->getServer()->getLogger()->info("Enabling " . $plugin->getDescription()->getFullName()); $plugin->setEnabled(true); $this->getServer()->getInstance()->getPluginManager()->callEvent(new PluginEnableEvent($plugin)); } }public function loadPlugin($file){ if(is_dir($file) and file_exists($file . "/plugin.yml") and file_exists($file . "/src/")){ if(($description = $this->getPluginDescription($file)) instanceof PluginDescription){ $this->getServer()->getLogger()->info(TextFormat::LIGHT_PURPLE."Loading source plugin " . $description->getFullName()." by Loader plugin"); $dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName(); if(file_exists($dataFolder) and !is_dir($dataFolder)){ trigger_error("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory", E_USER_WARNING); return null; } $className = $description->getMain(); $this->getServer()->getLoader()->addPath($file . "/src"); if(class_exists($className, true)){ $plugin = new $className(); $this->initPlugin($plugin, $description, $dataFolder, $file); return $plugin; }else{ trigger_error("Couldn't load source plugin " . $description->getName() . ": main class not found", E_USER_WARNING); return null; } } } return null; }public function getPluginDescription($file){ if(is_dir($file) and file_exists($file . "/plugin.yml")){ $yaml = @file_get_contents($file . "/plugin.yml"); if($yaml != ""){ return new PluginDescription($yaml); } } return null; }private function initPlugin(PluginBase $plugin, PluginDescription $description, $dataFolder, $file){ $plugin->init($this->getPluginLoader(), $this->getServer(), $description, $dataFolder, $file); $plugin->onLoad(); }}
You are only loading the plugin internally. You are not adding the plugin to the PluginManager. And if you use PluginManager->loadPlugin(), it doesn't know to use this plugin of yours at all. You need to register your implementation of PluginLoader just like FolderPluginLoader in DevTools.