From 5fac5c72816c6e1b137ca59b14e567a9116c2baa Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 20 Feb 2019 16:22:45 +0000 Subject: [PATCH] Move core permissions to default_permissions.yml this is one of the few things that is actually better suited to a YAML file than code closes #2594 --- resources/default_permissions.yml | 192 ++++++++++++++++++ .../permission/DefaultPermissions.php | 88 +------- 2 files changed, 198 insertions(+), 82 deletions(-) create mode 100644 resources/default_permissions.yml diff --git a/resources/default_permissions.yml b/resources/default_permissions.yml new file mode 100644 index 000000000..940c4da10 --- /dev/null +++ b/resources/default_permissions.yml @@ -0,0 +1,192 @@ +--- +pocketmine: + description: Allows using all PocketMine commands and utilities + default: op + children: + pocketmine.broadcast: + description: Allows the user to receive all broadcast messages + default: op + children: + pocketmine.broadcast.admin: + description: Allows the user to receive administrative broadcasts + default: op + pocketmine.broadcast.user: + description: Allows the user to receive user broadcasts + default: "true" + pocketmine.command: + description: Allows using all PocketMine commands + default: op + children: + pocketmine.command.ban: + description: Allows the user to ban people + default: op + children: + pocketmine.command.ban.ip: + description: Allows the user to ban IP addresses + default: op + pocketmine.command.ban.player: + description: Allows the user to ban players + default: op + pocketmine.command.defaultgamemode: + description: Allows the user to change the default gamemode + default: op + pocketmine.command.dumpmemory: + description: Allows the user to dump memory contents + default: "false" + pocketmine.command.effect: + description: Allows the user to give/take potion effects + default: op + pocketmine.command.enchant: + description: Allows the user to enchant items + default: op + pocketmine.command.gamemode: + description: Allows the user to change the gamemode of players + default: op + pocketmine.command.gc: + description: Allows the user to fire garbage collection tasks + default: op + pocketmine.command.give: + description: Allows the user to give items to players + default: op + pocketmine.command.help: + description: Allows the user to view the help menu + default: "true" + pocketmine.command.kick: + description: Allows the user to kick players + default: op + pocketmine.command.kill: + description: Allows the user to kill players + default: op + children: + pocketmine.command.kill.other: + description: Allows the user to kill other players + default: op + pocketmine.command.kill.self: + description: Allows the user to commit suicide + default: "true" + pocketmine.command.list: + description: Allows the user to list all online players + default: op + pocketmine.command.me: + description: Allows the user to perform a chat action + default: "true" + pocketmine.command.op: + description: Allows the user to change operators + default: op + children: + pocketmine.command.op.give: + description: Allows the user to give a player operator status + default: op + pocketmine.command.op.take: + description: Allows the user to take a player's operator status + default: op + pocketmine.command.particle: + description: Allows the user to create particle effects + default: op + pocketmine.command.plugins: + description: Allows the user to view the list of plugins + default: op + pocketmine.command.reload: + description: Allows the user to reload the server settings + default: op + pocketmine.command.save: + description: Allows the user to save the worlds + default: op + children: + pocketmine.command.save.disable: + description: Allows the user to disable automatic saving + default: op + pocketmine.command.save.enable: + description: Allows the user to enable automatic saving + default: op + pocketmine.command.save.perform: + description: Allows the user to perform a manual save + default: op + pocketmine.command.say: + description: Allows the user to talk as the console + default: op + pocketmine.command.seed: + description: Allows the user to view the seed of the world + default: op + pocketmine.command.setworldspawn: + description: Allows the user to change the world spawn + default: op + pocketmine.command.spawnpoint: + description: Allows the user to change player's spawnpoint + default: op + pocketmine.command.status: + description: Allows the user to view the server performance + default: op + pocketmine.command.stop: + description: Allows the user to stop the server + default: op + pocketmine.command.teleport: + description: Allows the user to teleport players + default: op + pocketmine.command.tell: + description: Allows the user to privately message another player + default: "true" + pocketmine.command.time: + description: Allows the user to alter the time + default: op + children: + pocketmine.command.time.add: + description: Allows the user to fast-forward time + default: op + pocketmine.command.time.query: + description: Allows the user query the time + default: op + pocketmine.command.time.set: + description: Allows the user to change the time + default: op + pocketmine.command.time.start: + description: Allows the user to restart the time + default: op + pocketmine.command.time.stop: + description: Allows the user to stop the time + default: op + pocketmine.command.timings: + description: Allows the user to records timings for all plugin events + default: op + pocketmine.command.title: + description: Allows the user to send a title to the specified player + default: op + pocketmine.command.transferserver: + description: Allows the user to transfer self to another server + default: op + pocketmine.command.unban: + description: Allows the user to unban people + default: op + children: + pocketmine.command.unban.ip: + description: Allows the user to unban IP addresses + default: op + pocketmine.command.unban.player: + description: Allows the user to unban players + default: op + pocketmine.command.version: + description: Allows the user to view the version of the server + default: "true" + pocketmine.command.whitelist: + description: Allows the user to modify the server whitelist + default: op + children: + pocketmine.command.whitelist.add: + description: Allows the user to add a player to the server whitelist + default: op + pocketmine.command.whitelist.disable: + description: Allows the user to disable the server whitelist + default: op + pocketmine.command.whitelist.enable: + description: Allows the user to enable the server whitelist + default: op + pocketmine.command.whitelist.list: + description: Allows the user to list all the players on the server whitelist + default: op + pocketmine.command.whitelist.reload: + description: Allows the user to reload the server whitelist + default: op + pocketmine.command.whitelist.remove: + description: Allows the user to remove a player to the server whitelist + default: op +... diff --git a/src/pocketmine/permission/DefaultPermissions.php b/src/pocketmine/permission/DefaultPermissions.php index 08a795de1..039b846c7 100644 --- a/src/pocketmine/permission/DefaultPermissions.php +++ b/src/pocketmine/permission/DefaultPermissions.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pocketmine\permission; +use function yaml_parse_file; + abstract class DefaultPermissions{ public const ROOT = "pocketmine"; @@ -44,87 +46,9 @@ abstract class DefaultPermissions{ } public static function registerCorePermissions(){ - $parent = self::registerPermission(new Permission(self::ROOT, "Allows using all PocketMine commands and utilities")); - - $broadcasts = self::registerPermission(new Permission(self::ROOT . ".broadcast", "Allows the user to receive all broadcast messages"), $parent); - self::registerPermission(new Permission(self::ROOT . ".broadcast.admin", "Allows the user to receive administrative broadcasts", Permission::DEFAULT_OP), $broadcasts); - self::registerPermission(new Permission(self::ROOT . ".broadcast.user", "Allows the user to receive user broadcasts", Permission::DEFAULT_TRUE), $broadcasts); - $broadcasts->recalculatePermissibles(); - - $commands = self::registerPermission(new Permission(self::ROOT . ".command", "Allows using all PocketMine commands"), $parent); - - $whitelist = self::registerPermission(new Permission(self::ROOT . ".command.whitelist", "Allows the user to modify the server whitelist", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.whitelist.add", "Allows the user to add a player to the server whitelist"), $whitelist); - self::registerPermission(new Permission(self::ROOT . ".command.whitelist.remove", "Allows the user to remove a player to the server whitelist"), $whitelist); - self::registerPermission(new Permission(self::ROOT . ".command.whitelist.reload", "Allows the user to reload the server whitelist"), $whitelist); - self::registerPermission(new Permission(self::ROOT . ".command.whitelist.enable", "Allows the user to enable the server whitelist"), $whitelist); - self::registerPermission(new Permission(self::ROOT . ".command.whitelist.disable", "Allows the user to disable the server whitelist"), $whitelist); - self::registerPermission(new Permission(self::ROOT . ".command.whitelist.list", "Allows the user to list all the players on the server whitelist"), $whitelist); - $whitelist->recalculatePermissibles(); - - $ban = self::registerPermission(new Permission(self::ROOT . ".command.ban", "Allows the user to ban people", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.ban.player", "Allows the user to ban players"), $ban); - self::registerPermission(new Permission(self::ROOT . ".command.ban.ip", "Allows the user to ban IP addresses"), $ban); - $ban->recalculatePermissibles(); - - $unban = self::registerPermission(new Permission(self::ROOT . ".command.unban", "Allows the user to unban people", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.unban.player", "Allows the user to unban players"), $unban); - self::registerPermission(new Permission(self::ROOT . ".command.unban.ip", "Allows the user to unban IP addresses"), $unban); - $unban->recalculatePermissibles(); - - $op = self::registerPermission(new Permission(self::ROOT . ".command.op", "Allows the user to change operators", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.op.give", "Allows the user to give a player operator status"), $op); - self::registerPermission(new Permission(self::ROOT . ".command.op.take", "Allows the user to take a player's operator status"), $op); - $op->recalculatePermissibles(); - - $save = self::registerPermission(new Permission(self::ROOT . ".command.save", "Allows the user to save the worlds", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.save.enable", "Allows the user to enable automatic saving"), $save); - self::registerPermission(new Permission(self::ROOT . ".command.save.disable", "Allows the user to disable automatic saving"), $save); - self::registerPermission(new Permission(self::ROOT . ".command.save.perform", "Allows the user to perform a manual save"), $save); - $save->recalculatePermissibles(); - - $time = self::registerPermission(new Permission(self::ROOT . ".command.time", "Allows the user to alter the time", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.time.add", "Allows the user to fast-forward time"), $time); - self::registerPermission(new Permission(self::ROOT . ".command.time.set", "Allows the user to change the time"), $time); - self::registerPermission(new Permission(self::ROOT . ".command.time.start", "Allows the user to restart the time"), $time); - self::registerPermission(new Permission(self::ROOT . ".command.time.stop", "Allows the user to stop the time"), $time); - self::registerPermission(new Permission(self::ROOT . ".command.time.query", "Allows the user query the time"), $time); - $time->recalculatePermissibles(); - - $kill = self::registerPermission(new Permission(self::ROOT . ".command.kill", "Allows the user to kill players", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.kill.self", "Allows the user to commit suicide", Permission::DEFAULT_TRUE), $kill); - self::registerPermission(new Permission(self::ROOT . ".command.kill.other", "Allows the user to kill other players"), $kill); - $kill->recalculatePermissibles(); - - self::registerPermission(new Permission(self::ROOT . ".command.me", "Allows the user to perform a chat action", Permission::DEFAULT_TRUE), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.tell", "Allows the user to privately message another player", Permission::DEFAULT_TRUE), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.say", "Allows the user to talk as the console", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.give", "Allows the user to give items to players", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.effect", "Allows the user to give/take potion effects", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.enchant", "Allows the user to enchant items", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.particle", "Allows the user to create particle effects", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.teleport", "Allows the user to teleport players", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.kick", "Allows the user to kick players", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.stop", "Allows the user to stop the server", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.list", "Allows the user to list all online players", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.help", "Allows the user to view the help menu", Permission::DEFAULT_TRUE), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.plugins", "Allows the user to view the list of plugins", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.reload", "Allows the user to reload the server settings", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.version", "Allows the user to view the version of the server", Permission::DEFAULT_TRUE), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.gamemode", "Allows the user to change the gamemode of players", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.defaultgamemode", "Allows the user to change the default gamemode", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.seed", "Allows the user to view the seed of the world", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.status", "Allows the user to view the server performance", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.gc", "Allows the user to fire garbage collection tasks", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.dumpmemory", "Allows the user to dump memory contents", Permission::DEFAULT_FALSE), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.timings", "Allows the user to records timings for all plugin events", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.spawnpoint", "Allows the user to change player's spawnpoint", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.setworldspawn", "Allows the user to change the world spawn", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.transferserver", "Allows the user to transfer self to another server", Permission::DEFAULT_OP), $commands); - self::registerPermission(new Permission(self::ROOT . ".command.title", "Allows the user to send a title to the specified player", Permission::DEFAULT_OP), $commands); - - $commands->recalculatePermissibles(); - - $parent->recalculatePermissibles(); + $manager = PermissionManager::getInstance(); + foreach(PermissionParser::loadPermissions(yaml_parse_file(\pocketmine\RESOURCE_PATH . 'default_permissions.yml')) as $permission){ + $manager->addPermission($permission); + } } }