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->pluginManager = new PluginManager($this, $this->commandMap);
$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\\FolderPluginLoader");
$this->pluginManager->loadPlugins($this->pluginPath);
//TODO: update checking (async)

View File

@ -171,73 +171,67 @@ class PluginManager{
$loadedPlugins = array();
$dependencies = array();
$softDependencies = array();
foreach(new \IteratorIterator(new \DirectoryIterator($directory)) as $file){
if($file === "." or $file === ".."){
continue;
}
$file = $directory . $file;
foreach($this->fileAssociations as $loader){
if(preg_match($loader->getPluginFilters(), basename($file)) > 0){
$description = $loader->getPluginDescription($file);
if($description instanceof PluginDescription){
$name = $description->getName();
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
console("[ERROR] Could not load plugin '" . $name . "': restricted name");
foreach($this->fileAssociations as $loader){
foreach(new \RegexIterator(new \DirectoryIterator($directory), $loader->getPluginFilters()) as $file){
if($file === "." or $file === ".."){
continue;
}
$file = $directory . $file;
$description = $loader->getPluginDescription($file);
if($description instanceof PluginDescription){
$name = $description->getName();
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
console("[ERROR] Could not load plugin '" . $name . "': restricted name");
continue;
}elseif(strpos($name, " ") !== false){
console("[WARNING] Plugin '" . $name . "' uses spaces in its name, this is discouraged");
}
if(isset($plugins[$name])){
console("[ERROR] Could not load duplicate plugin '" . $name . "': plugin exists");
continue;
}
$compatible = false;
//Check multiple dependencies
foreach($description->getCompatibleApis() as $version){
//Format: majorVersion.minorVersion.patch
$version = array_map("intval", explode(".", $version));
$apiVersion = array_map("intval", explode(".", $this->server->getApiVersion()));
//Completely different API version
if($version[0] !== $apiVersion[0]){
continue;
}elseif(strpos($name, " ") !== false){
console("[WARNING] Plugin '" . $name . "' uses spaces in its name, this is discouraged");
}
if(isset($plugins[$name])){
console("[ERROR] Could not load duplicate plugin '" . $name . "': plugin exists");
//If the plugin requires new API features, being backwards compatible
if($version[1] > $apiVersion[1]){
continue;
}
$compatible = false;
//Check multiple dependencies
foreach($description->getCompatibleApis() as $version){
//Format: majorVersion.minorVersion.patch
$version = array_map("intval", explode(".", $version));
$apiVersion = array_map("intval", explode(".", $this->server->getApiVersion()));
//Completely different API version
if($version[0] !== $apiVersion[0]){
continue;
}
//If the plugin requires new API features, being backwards compatible
if($version[1] > $apiVersion[1]){
continue;
}
$compatible = true;
break;
}
if($compatible === false){
console("[ERROR] Could not load plugin '" . $name . "': API version not compatible");
continue;
}
$plugins[$name] = $file;
$softDependencies[$name] = (array) $description->getSoftDepend();
$dependencies[$name] = (array) $description->getDepend();
foreach($description->getLoadBefore() as $before){
if(isset($softDependencies[$before])){
$softDependencies[$before][] = $name;
}else{
$softDependencies[$before] = array($name);
}
}
$compatible = true;
break;
}
if($compatible === false){
console("[ERROR] Could not load plugin '" . $name . "': API version not compatible");
continue;
}
$plugins[$name] = $file;
$softDependencies[$name] = (array) $description->getSoftDepend();
$dependencies[$name] = (array) $description->getDepend();
foreach($description->getLoadBefore() as $before){
if(isset($softDependencies[$before])){
$softDependencies[$before][] = $name;
}else{
$softDependencies[$before] = array($name);
}
}
}
}
}
while(count($plugins) > 0){
$missingDependency = true;
foreach($plugins as $name => $file){