Load later plugins with custom loader, fixes API

This commit is contained in:
Shoghi Cervantes 2014-08-16 00:30:37 +02:00
parent 9e74169d74
commit 918024e466
2 changed files with 11 additions and 10 deletions

View File

@ -52,7 +52,7 @@ class PharPluginLoader implements PluginLoader{
*/
public function loadPlugin($file){
if(($description = $this->getPluginDescription($file)) instanceof PluginDescription){
MainLogger::getLogger()->info("Loading " . $description->getFullName());
$this->server->getLogger()->info("Loading " . $description->getFullName());
$dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName();
if(file_exists($dataFolder) and !is_dir($dataFolder)){
throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
@ -120,11 +120,11 @@ class PharPluginLoader implements PluginLoader{
*/
public function enablePlugin(Plugin $plugin){
if($plugin instanceof PluginBase and !$plugin->isEnabled()){
MainLogger::getLogger()->info("Enabling " . $plugin->getDescription()->getFullName());
$this->server->getLogger()->info("Enabling " . $plugin->getDescription()->getFullName());
$plugin->setEnabled(true);
Server::getInstance()->getPluginManager()->callEvent(new PluginEnableEvent($plugin));
$this->server->getPluginManager()->callEvent(new PluginEnableEvent($plugin));
}
}
@ -133,9 +133,9 @@ class PharPluginLoader implements PluginLoader{
*/
public function disablePlugin(Plugin $plugin){
if($plugin instanceof PluginBase and $plugin->isEnabled()){
MainLogger::getLogger()->info("Disabling " . $plugin->getDescription()->getFullName());
$this->server->getLogger()->info("Disabling " . $plugin->getDescription()->getFullName());
Server::getInstance()->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
$this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
$plugin->setEnabled(false);
}

View File

@ -136,12 +136,13 @@ class PluginManager{
}
/**
* @param string $path
* @param string $path
* @param PluginLoader[] $loaders
*
* @return Plugin
*/
public function loadPlugin($path){
foreach($this->fileAssociations as $loader){
public function loadPlugin($path, $loaders = null){
foreach(($loaders === null ? $this->fileAssociations : $loaders) as $loader){
if(preg_match($loader->getPluginFilters(), basename($path)) > 0){
$description = $loader->getPluginDescription($path);
if($description instanceof PluginDescription){
@ -285,7 +286,7 @@ class PluginManager{
if(!isset($dependencies[$name]) and !isset($softDependencies[$name])){
unset($plugins[$name]);
$missingDependency = false;
if($plugin = $this->loadPlugin($file) and $plugin instanceof Plugin){
if($plugin = $this->loadPlugin($file, $loaders) and $plugin instanceof Plugin){
$loadedPlugins[$name] = $plugin;
}else{
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
@ -299,7 +300,7 @@ class PluginManager{
unset($softDependencies[$name]);
unset($plugins[$name]);
$missingDependency = false;
if($plugin = $this->loadPlugin($file) and $plugin instanceof Plugin){
if($plugin = $this->loadPlugin($file, $loaders) and $plugin instanceof Plugin){
$loadedPlugins[$name] = $plugin;
}else{
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");