PluginManager: Make declaration of duplicate permissions a load error

This commit is contained in:
Dylan K. Taylor 2021-11-06 17:05:37 +00:00
parent d9d37f7fa6
commit 6b316dc29a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 27 additions and 11 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.3.0", "pocketmine/errorhandler": "^0.3.0",
"pocketmine/locale-data": "^1.0.3", "pocketmine/locale-data": "^1.1.4",
"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": "e36db7fb94bd79034dcc599c3029a621", "content-hash": "6de5c66b7a0f693fd30c701b0d0db3d1",
"packages": [ "packages": [
{ {
"name": "adhocore/json-comment", "name": "adhocore/json-comment",
@ -533,16 +533,16 @@
}, },
{ {
"name": "pocketmine/locale-data", "name": "pocketmine/locale-data",
"version": "1.0.3", "version": "1.1.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/Language.git", "url": "https://github.com/pmmp/Language.git",
"reference": "7342b4eb593036c739e7f0c0ed95299ada69ff19" "reference": "549f27f593b200d8b11ca05ffcd5a73e02a0d9fb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/Language/zipball/7342b4eb593036c739e7f0c0ed95299ada69ff19", "url": "https://api.github.com/repos/pmmp/Language/zipball/549f27f593b200d8b11ca05ffcd5a73e02a0d9fb",
"reference": "7342b4eb593036c739e7f0c0ed95299ada69ff19", "reference": "549f27f593b200d8b11ca05ffcd5a73e02a0d9fb",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@ -550,9 +550,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/1.0.3" "source": "https://github.com/pmmp/Language/tree/1.1.4"
}, },
"time": "2021-11-06T00:27:03+00:00" "time": "2021-11-06T17:02:22+00:00"
}, },
{ {
"name": "pocketmine/log", "name": "pocketmine/log",

View File

@ -1724,6 +1724,12 @@ final class KnownTranslationFactory{
]); ]);
} }
public static function pocketmine_plugin_duplicatePermissionError(Translatable|string $permissionName) : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_DUPLICATEPERMISSIONERROR, [
"permissionName" => $permissionName,
]);
}
public static function pocketmine_plugin_emptyExtensionVersionConstraint(Translatable|string $constraintIndex, Translatable|string $extensionName) : Translatable{ public static function pocketmine_plugin_emptyExtensionVersionConstraint(Translatable|string $constraintIndex, Translatable|string $extensionName) : Translatable{
return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_EMPTYEXTENSIONVERSIONCONSTRAINT, [ return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_EMPTYEXTENSIONVERSIONCONSTRAINT, [
"constraintIndex" => $constraintIndex, "constraintIndex" => $constraintIndex,

View File

@ -361,6 +361,7 @@ final class KnownTranslationKeys{
public const POCKETMINE_PLUGIN_DISALLOWEDBYBLACKLIST = "pocketmine.plugin.disallowedByBlacklist"; public const POCKETMINE_PLUGIN_DISALLOWEDBYBLACKLIST = "pocketmine.plugin.disallowedByBlacklist";
public const POCKETMINE_PLUGIN_DISALLOWEDBYWHITELIST = "pocketmine.plugin.disallowedByWhitelist"; public const POCKETMINE_PLUGIN_DISALLOWEDBYWHITELIST = "pocketmine.plugin.disallowedByWhitelist";
public const POCKETMINE_PLUGIN_DUPLICATEERROR = "pocketmine.plugin.duplicateError"; public const POCKETMINE_PLUGIN_DUPLICATEERROR = "pocketmine.plugin.duplicateError";
public const POCKETMINE_PLUGIN_DUPLICATEPERMISSIONERROR = "pocketmine.plugin.duplicatePermissionError";
public const POCKETMINE_PLUGIN_EMPTYEXTENSIONVERSIONCONSTRAINT = "pocketmine.plugin.emptyExtensionVersionConstraint"; public const POCKETMINE_PLUGIN_EMPTYEXTENSIONVERSIONCONSTRAINT = "pocketmine.plugin.emptyExtensionVersionConstraint";
public const POCKETMINE_PLUGIN_ENABLE = "pocketmine.plugin.enable"; public const POCKETMINE_PLUGIN_ENABLE = "pocketmine.plugin.enable";
public const POCKETMINE_PLUGIN_EXTENSIONNOTLOADED = "pocketmine.plugin.extensionNotLoaded"; public const POCKETMINE_PLUGIN_EXTENSIONNOTLOADED = "pocketmine.plugin.extensionNotLoaded";

View File

@ -168,13 +168,22 @@ class PluginManager{
} }
$permManager = PermissionManager::getInstance(); $permManager = PermissionManager::getInstance();
foreach($description->getPermissions() as $permsGroup){
foreach($permsGroup as $perm){
if($permManager->getPermission($perm->getName()) !== null){
$this->server->getLogger()->error($language->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
$description->getName(),
KnownTranslationFactory::pocketmine_plugin_duplicatePermissionError($perm->getName())
)));
return null;
}
}
}
$opRoot = $permManager->getPermission(DefaultPermissions::ROOT_OPERATOR); $opRoot = $permManager->getPermission(DefaultPermissions::ROOT_OPERATOR);
$everyoneRoot = $permManager->getPermission(DefaultPermissions::ROOT_USER); $everyoneRoot = $permManager->getPermission(DefaultPermissions::ROOT_USER);
foreach($description->getPermissions() as $default => $perms){ foreach($description->getPermissions() as $default => $perms){
foreach($perms as $perm){ foreach($perms as $perm){
if(!$permManager->addPermission($perm)){ $permManager->addPermission($perm);
continue; //TODO: this should be reported as an error and prevent the plugin from loading
}
switch($default){ switch($default){
case PermissionParser::DEFAULT_TRUE: case PermissionParser::DEFAULT_TRUE:
$everyoneRoot->addChild($perm->getName(), true); $everyoneRoot->addChild($perm->getName(), true);