From 5865f17c75e77cf8dcb892587e11df9102688896 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 1 Apr 2014 21:57:32 +0200 Subject: [PATCH] Faster plugin filter loading --- src/pocketmine/Server.php | 2 +- src/pocketmine/plugin/PluginManager.php | 106 +++++++++++------------- 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index b64eabfb9..6781f025b 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -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) diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 040b8460f..54e9c6ff3 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -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){