mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Faster plugin filter loading
This commit is contained in:
parent
7e9304a0c9
commit
5865f17c75
@ -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)
|
||||||
|
@ -171,73 +171,67 @@ 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){
|
||||||
if($file === "." or $file === ".."){
|
foreach(new \RegexIterator(new \DirectoryIterator($directory), $loader->getPluginFilters()) as $file){
|
||||||
continue;
|
if($file === "." or $file === ".."){
|
||||||
}
|
continue;
|
||||||
$file = $directory . $file;
|
}
|
||||||
foreach($this->fileAssociations as $loader){
|
$file = $directory . $file;
|
||||||
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();
|
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
||||||
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
console("[ERROR] Could not load plugin '" . $name . "': restricted name");
|
||||||
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;
|
continue;
|
||||||
}elseif(strpos($name, " ") !== false){
|
|
||||||
console("[WARNING] Plugin '" . $name . "' uses spaces in its name, this is discouraged");
|
|
||||||
}
|
}
|
||||||
if(isset($plugins[$name])){
|
//If the plugin requires new API features, being backwards compatible
|
||||||
console("[ERROR] Could not load duplicate plugin '" . $name . "': plugin exists");
|
if($version[1] > $apiVersion[1]){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$compatible = false;
|
$compatible = true;
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
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){
|
while(count($plugins) > 0){
|
||||||
$missingDependency = true;
|
$missingDependency = true;
|
||||||
foreach($plugins as $name => $file){
|
foreach($plugins as $name => $file){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user