PluginManager: account for possible abstract main classes

idk why anyone does this, but it shouldn't cause a core crash ...
This commit is contained in:
Dylan K. Taylor 2022-04-01 23:42:37 +01:00
parent d7e6b01216
commit ac3a6033b9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 21 additions and 8 deletions

View File

@ -41,7 +41,7 @@
"pocketmine/classloader": "^0.2.0", "pocketmine/classloader": "^0.2.0",
"pocketmine/color": "^0.2.0", "pocketmine/color": "^0.2.0",
"pocketmine/errorhandler": "^0.6.0", "pocketmine/errorhandler": "^0.6.0",
"pocketmine/locale-data": "~2.4.2", "pocketmine/locale-data": "~2.5.0",
"pocketmine/log": "^0.4.0", "pocketmine/log": "^0.4.0",
"pocketmine/log-pthreads": "^0.4.0", "pocketmine/log-pthreads": "^0.4.0",
"pocketmine/math": "^0.4.0", "pocketmine/math": "^0.4.0",

14
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "2cece7458e6a61819972819606ac531e", "content-hash": "2cadf5ed5a03fee920e46f4cfe5f819c",
"packages": [ "packages": [
{ {
"name": "adhocore/json-comment", "name": "adhocore/json-comment",
@ -536,16 +536,16 @@
}, },
{ {
"name": "pocketmine/locale-data", "name": "pocketmine/locale-data",
"version": "2.4.3", "version": "2.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/Language.git", "url": "https://github.com/pmmp/Language.git",
"reference": "4d0b081f1a79407e087968ea76aaf330db6ea2b5" "reference": "df6fc7f2b48850b306c60466a11f7a27bb8fe1de"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/Language/zipball/4d0b081f1a79407e087968ea76aaf330db6ea2b5", "url": "https://api.github.com/repos/pmmp/Language/zipball/df6fc7f2b48850b306c60466a11f7a27bb8fe1de",
"reference": "4d0b081f1a79407e087968ea76aaf330db6ea2b5", "reference": "df6fc7f2b48850b306c60466a11f7a27bb8fe1de",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@ -553,9 +553,9 @@
"description": "Language resources used by PocketMine-MP", "description": "Language resources used by PocketMine-MP",
"support": { "support": {
"issues": "https://github.com/pmmp/Language/issues", "issues": "https://github.com/pmmp/Language/issues",
"source": "https://github.com/pmmp/Language/tree/2.4.3" "source": "https://github.com/pmmp/Language/tree/2.5.0"
}, },
"time": "2022-01-25T23:18:24+00:00" "time": "2022-04-01T22:36:58+00:00"
}, },
{ {
"name": "pocketmine/log", "name": "pocketmine/log",

View File

@ -1829,6 +1829,10 @@ final class KnownTranslationFactory{
]); ]);
} }
public static function pocketmine_plugin_mainClassAbstract() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_MAINCLASSABSTRACT, []);
}
public static function pocketmine_plugin_mainClassNotFound() : Translatable{ public static function pocketmine_plugin_mainClassNotFound() : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_MAINCLASSNOTFOUND, []); return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_MAINCLASSNOTFOUND, []);
} }

View File

@ -379,6 +379,7 @@ final class KnownTranslationKeys{
public const POCKETMINE_PLUGIN_INVALIDMANIFEST = "pocketmine.plugin.invalidManifest"; public const POCKETMINE_PLUGIN_INVALIDMANIFEST = "pocketmine.plugin.invalidManifest";
public const POCKETMINE_PLUGIN_LOAD = "pocketmine.plugin.load"; public const POCKETMINE_PLUGIN_LOAD = "pocketmine.plugin.load";
public const POCKETMINE_PLUGIN_LOADERROR = "pocketmine.plugin.loadError"; public const POCKETMINE_PLUGIN_LOADERROR = "pocketmine.plugin.loadError";
public const POCKETMINE_PLUGIN_MAINCLASSABSTRACT = "pocketmine.plugin.mainClassAbstract";
public const POCKETMINE_PLUGIN_MAINCLASSNOTFOUND = "pocketmine.plugin.mainClassNotFound"; public const POCKETMINE_PLUGIN_MAINCLASSNOTFOUND = "pocketmine.plugin.mainClassNotFound";
public const POCKETMINE_PLUGIN_MAINCLASSWRONGTYPE = "pocketmine.plugin.mainClassWrongType"; public const POCKETMINE_PLUGIN_MAINCLASSWRONGTYPE = "pocketmine.plugin.mainClassWrongType";
public const POCKETMINE_PLUGIN_RESTRICTEDNAME = "pocketmine.plugin.restrictedName"; public const POCKETMINE_PLUGIN_RESTRICTEDNAME = "pocketmine.plugin.restrictedName";

View File

@ -166,6 +166,14 @@ class PluginManager{
))); )));
return null; return null;
} }
$reflect = new \ReflectionClass($mainClass); //this shouldn't throw; we already checked that it exists
if(!$reflect->isInstantiable()){
$this->server->getLogger()->error($language->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
$description->getName(),
KnownTranslationFactory::pocketmine_plugin_mainClassAbstract()
)));
return null;
}
$permManager = PermissionManager::getInstance(); $permManager = PermissionManager::getInstance();
foreach($description->getPermissions() as $permsGroup){ foreach($description->getPermissions() as $permsGroup){