mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 02:21:46 +00:00
Fixed loading invalid plugins crashing the server
This commit is contained in:
parent
487ce00542
commit
25f5d409f1
@ -192,57 +192,61 @@ class PluginManager{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$file = $directory . $file;
|
$file = $directory . $file;
|
||||||
$description = $loader->getPluginDescription($file);
|
try{
|
||||||
if($description instanceof PluginDescription){
|
$description = $loader->getPluginDescription($file);
|
||||||
$name = $description->getName();
|
if($description instanceof PluginDescription){
|
||||||
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
$name = $description->getName();
|
||||||
$this->server->getLogger()->error("Could not load plugin '" . $name . "': restricted name");
|
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
||||||
continue;
|
$this->server->getLogger()->error("Could not load plugin '" . $name . "': restricted name");
|
||||||
}elseif(strpos($name, " ") !== false){
|
|
||||||
$this->server->getLogger()->warning("Plugin '" . $name . "' uses spaces in its name, this is discouraged");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($plugins[$name]) or $this->getPlugin($name) instanceof Plugin){
|
|
||||||
$this->server->getLogger()->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){
|
||||||
|
$this->server->getLogger()->warning("Plugin '" . $name . "' uses spaces in its name, this is discouraged");
|
||||||
}
|
}
|
||||||
//If the plugin requires new API features, being backwards compatible
|
|
||||||
if($version[1] > $apiVersion[1]){
|
if(isset($plugins[$name]) or $this->getPlugin($name) instanceof Plugin){
|
||||||
|
$this->server->getLogger()->error("Could not load duplicate plugin '" . $name . "': plugin exists");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$compatible = true;
|
$compatible = false;
|
||||||
break;
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
if($compatible === false){
|
$compatible = true;
|
||||||
$this->server->getLogger()->error("Could not load plugin '" . $name . "': API version not compatible");
|
break;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$plugins[$name] = $file;
|
if($compatible === false){
|
||||||
|
$this->server->getLogger()->error("Could not load plugin '" . $name . "': API version not compatible");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$softDependencies[$name] = (array) $description->getSoftDepend();
|
$plugins[$name] = $file;
|
||||||
$dependencies[$name] = (array) $description->getDepend();
|
|
||||||
|
|
||||||
foreach($description->getLoadBefore() as $before){
|
$softDependencies[$name] = (array) $description->getSoftDepend();
|
||||||
if(isset($softDependencies[$before])){
|
$dependencies[$name] = (array) $description->getDepend();
|
||||||
$softDependencies[$before][] = $name;
|
|
||||||
}else{
|
foreach($description->getLoadBefore() as $before){
|
||||||
$softDependencies[$before] = array($name);
|
if(isset($softDependencies[$before])){
|
||||||
|
$softDependencies[$before][] = $name;
|
||||||
|
}else{
|
||||||
|
$softDependencies[$before] = array($name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch(\Exception $e){
|
||||||
|
$this->server->getLogger()->error("Could not load '". $file ."' in folder '".$directory."': ".$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user