mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Load later plugins with custom loader, fixes API
This commit is contained in:
parent
9e74169d74
commit
918024e466
@ -52,7 +52,7 @@ class PharPluginLoader implements PluginLoader{
|
|||||||
*/
|
*/
|
||||||
public function loadPlugin($file){
|
public function loadPlugin($file){
|
||||||
if(($description = $this->getPluginDescription($file)) instanceof PluginDescription){
|
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();
|
$dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName();
|
||||||
if(file_exists($dataFolder) and !is_dir($dataFolder)){
|
if(file_exists($dataFolder) and !is_dir($dataFolder)){
|
||||||
throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
|
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){
|
public function enablePlugin(Plugin $plugin){
|
||||||
if($plugin instanceof PluginBase and !$plugin->isEnabled()){
|
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);
|
$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){
|
public function disablePlugin(Plugin $plugin){
|
||||||
if($plugin instanceof PluginBase and $plugin->isEnabled()){
|
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);
|
$plugin->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
@ -137,11 +137,12 @@ class PluginManager{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
* @param PluginLoader[] $loaders
|
||||||
*
|
*
|
||||||
* @return Plugin
|
* @return Plugin
|
||||||
*/
|
*/
|
||||||
public function loadPlugin($path){
|
public function loadPlugin($path, $loaders = null){
|
||||||
foreach($this->fileAssociations as $loader){
|
foreach(($loaders === null ? $this->fileAssociations : $loaders) as $loader){
|
||||||
if(preg_match($loader->getPluginFilters(), basename($path)) > 0){
|
if(preg_match($loader->getPluginFilters(), basename($path)) > 0){
|
||||||
$description = $loader->getPluginDescription($path);
|
$description = $loader->getPluginDescription($path);
|
||||||
if($description instanceof PluginDescription){
|
if($description instanceof PluginDescription){
|
||||||
@ -285,7 +286,7 @@ class PluginManager{
|
|||||||
if(!isset($dependencies[$name]) and !isset($softDependencies[$name])){
|
if(!isset($dependencies[$name]) and !isset($softDependencies[$name])){
|
||||||
unset($plugins[$name]);
|
unset($plugins[$name]);
|
||||||
$missingDependency = false;
|
$missingDependency = false;
|
||||||
if($plugin = $this->loadPlugin($file) and $plugin instanceof Plugin){
|
if($plugin = $this->loadPlugin($file, $loaders) and $plugin instanceof Plugin){
|
||||||
$loadedPlugins[$name] = $plugin;
|
$loadedPlugins[$name] = $plugin;
|
||||||
}else{
|
}else{
|
||||||
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
|
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
|
||||||
@ -299,7 +300,7 @@ class PluginManager{
|
|||||||
unset($softDependencies[$name]);
|
unset($softDependencies[$name]);
|
||||||
unset($plugins[$name]);
|
unset($plugins[$name]);
|
||||||
$missingDependency = false;
|
$missingDependency = false;
|
||||||
if($plugin = $this->loadPlugin($file) and $plugin instanceof Plugin){
|
if($plugin = $this->loadPlugin($file, $loaders) and $plugin instanceof Plugin){
|
||||||
$loadedPlugins[$name] = $plugin;
|
$loadedPlugins[$name] = $plugin;
|
||||||
}else{
|
}else{
|
||||||
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
|
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user