Faster plugin filter loading

This commit is contained in:
Shoghi Cervantes 2014-04-01 21:57:32 +02:00
parent 7e9304a0c9
commit 5865f17c75
2 changed files with 51 additions and 57 deletions

View File

@ -954,8 +954,8 @@ class Server{
$this->commandMap = new SimpleCommandMap($this); $this->commandMap = new SimpleCommandMap($this);
$this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager = new PluginManager($this, $this->commandMap);
$this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
$this->pluginManager->registerInterface("pocketmine\\plugin\\FolderPluginLoader");
$this->pluginManager->registerInterface("pocketmine\\plugin\\PharPluginLoader"); $this->pluginManager->registerInterface("pocketmine\\plugin\\PharPluginLoader");
$this->pluginManager->registerInterface("pocketmine\\plugin\\FolderPluginLoader");
$this->pluginManager->loadPlugins($this->pluginPath); $this->pluginManager->loadPlugins($this->pluginPath);
//TODO: update checking (async) //TODO: update checking (async)

View File

@ -171,13 +171,12 @@ class PluginManager{
$loadedPlugins = array(); $loadedPlugins = array();
$dependencies = array(); $dependencies = array();
$softDependencies = array(); $softDependencies = array();
foreach(new \IteratorIterator(new \DirectoryIterator($directory)) as $file){ foreach($this->fileAssociations as $loader){
foreach(new \RegexIterator(new \DirectoryIterator($directory), $loader->getPluginFilters()) as $file){
if($file === "." or $file === ".."){ if($file === "." or $file === ".."){
continue; continue;
} }
$file = $directory . $file; $file = $directory . $file;
foreach($this->fileAssociations as $loader){
if(preg_match($loader->getPluginFilters(), basename($file)) > 0){
$description = $loader->getPluginDescription($file); $description = $loader->getPluginDescription($file);
if($description instanceof PluginDescription){ if($description instanceof PluginDescription){
$name = $description->getName(); $name = $description->getName();
@ -193,18 +192,15 @@ class PluginManager{
} }
$compatible = false; $compatible = false;
//Check multiple dependencies //Check multiple dependencies
foreach($description->getCompatibleApis() as $version){ foreach($description->getCompatibleApis() as $version){
//Format: majorVersion.minorVersion.patch //Format: majorVersion.minorVersion.patch
$version = array_map("intval", explode(".", $version)); $version = array_map("intval", explode(".", $version));
$apiVersion = array_map("intval", explode(".", $this->server->getApiVersion())); $apiVersion = array_map("intval", explode(".", $this->server->getApiVersion()));
//Completely different API version //Completely different API version
if($version[0] !== $apiVersion[0]){ if($version[0] !== $apiVersion[0]){
continue; continue;
} }
//If the plugin requires new API features, being backwards compatible //If the plugin requires new API features, being backwards compatible
if($version[1] > $apiVersion[1]){ if($version[1] > $apiVersion[1]){
continue; continue;
@ -231,12 +227,10 @@ class PluginManager{
$softDependencies[$before] = array($name); $softDependencies[$before] = array($name);
} }
} }
}
}
}
break;
}
}
}
}
while(count($plugins) > 0){ while(count($plugins) > 0){
$missingDependency = true; $missingDependency = true;