Add .self and .other permissions for gameplay-altering commands (#5470)

I'm not quite sure this is the best way to enable such functionality, but it's already used for some other stuff, so I'm not too worried for now.

This allows the following commands to have their usage limited to self or others:
- /effect
- /enchant
- /gamemode
- /give
- /spawnpoint
- /teleport
- /title

I envision this being useful for creative mode servers, and test servers such as test.pmmp.io.
This commit is contained in:
Dylan T
2022-12-24 17:22:18 +00:00
committed by GitHub
parent 3d038b28ff
commit 567bd8abb5
13 changed files with 149 additions and 132 deletions

View File

@@ -35,10 +35,18 @@ final class DefaultPermissionNames{
public const COMMAND_DIFFICULTY = "pocketmine.command.difficulty";
public const COMMAND_DUMPMEMORY = "pocketmine.command.dumpmemory";
public const COMMAND_EFFECT = "pocketmine.command.effect";
public const COMMAND_EFFECT_OTHER = "pocketmine.command.effect.other";
public const COMMAND_EFFECT_SELF = "pocketmine.command.effect.self";
public const COMMAND_ENCHANT = "pocketmine.command.enchant";
public const COMMAND_ENCHANT_OTHER = "pocketmine.command.enchant.other";
public const COMMAND_ENCHANT_SELF = "pocketmine.command.enchant.self";
public const COMMAND_GAMEMODE = "pocketmine.command.gamemode";
public const COMMAND_GAMEMODE_OTHER = "pocketmine.command.gamemode.other";
public const COMMAND_GAMEMODE_SELF = "pocketmine.command.gamemode.self";
public const COMMAND_GC = "pocketmine.command.gc";
public const COMMAND_GIVE = "pocketmine.command.give";
public const COMMAND_GIVE_OTHER = "pocketmine.command.give.other";
public const COMMAND_GIVE_SELF = "pocketmine.command.give.self";
public const COMMAND_HELP = "pocketmine.command.help";
public const COMMAND_KICK = "pocketmine.command.kick";
public const COMMAND_KILL_OTHER = "pocketmine.command.kill.other";
@@ -56,9 +64,13 @@ final class DefaultPermissionNames{
public const COMMAND_SEED = "pocketmine.command.seed";
public const COMMAND_SETWORLDSPAWN = "pocketmine.command.setworldspawn";
public const COMMAND_SPAWNPOINT = "pocketmine.command.spawnpoint";
public const COMMAND_SPAWNPOINT_OTHER = "pocketmine.command.spawnpoint.other";
public const COMMAND_SPAWNPOINT_SELF = "pocketmine.command.spawnpoint.self";
public const COMMAND_STATUS = "pocketmine.command.status";
public const COMMAND_STOP = "pocketmine.command.stop";
public const COMMAND_TELEPORT = "pocketmine.command.teleport";
public const COMMAND_TELEPORT_OTHER = "pocketmine.command.teleport.other";
public const COMMAND_TELEPORT_SELF = "pocketmine.command.teleport.self";
public const COMMAND_TELL = "pocketmine.command.tell";
public const COMMAND_TIME_ADD = "pocketmine.command.time.add";
public const COMMAND_TIME_QUERY = "pocketmine.command.time.query";
@@ -67,6 +79,8 @@ final class DefaultPermissionNames{
public const COMMAND_TIME_STOP = "pocketmine.command.time.stop";
public const COMMAND_TIMINGS = "pocketmine.command.timings";
public const COMMAND_TITLE = "pocketmine.command.title";
public const COMMAND_TITLE_OTHER = "pocketmine.command.title.other";
public const COMMAND_TITLE_SELF = "pocketmine.command.title.self";
public const COMMAND_TRANSFERSERVER = "pocketmine.command.transferserver";
public const COMMAND_UNBAN_IP = "pocketmine.command.unban.ip";
public const COMMAND_UNBAN_PLAYER = "pocketmine.command.unban.player";

View File

@@ -44,6 +44,12 @@ abstract class DefaultPermissions{
return PermissionManager::getInstance()->getPermission($candidate->getName());
}
private static function registerDeprecatedPermission(string $name) : Permission{
$permission = new Permission($name, "Deprecated, kept for backwards compatibility only");
PermissionManager::getInstance()->addPermission($permission);
return $permission;
}
public static function registerCorePermissions() : void{
$consoleRoot = self::registerPermission(new Permission(self::ROOT_CONSOLE, "Grants all console permissions"));
$operatorRoot = self::registerPermission(new Permission(self::ROOT_OPERATOR, "Grants all operator permissions"), [$consoleRoot]);
@@ -59,11 +65,25 @@ abstract class DefaultPermissions{
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_DEFAULTGAMEMODE, "Allows the user to change the default gamemode"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_DIFFICULTY, "Allows the user to change the game difficulty"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_DUMPMEMORY, "Allows the user to dump memory contents"), [$consoleRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_EFFECT, "Allows the user to give/take potion effects"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_ENCHANT, "Allows the user to enchant items"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GAMEMODE, "Allows the user to change the gamemode of players"), [$operatorRoot]);
$effectRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_EFFECT);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_EFFECT_OTHER, "Allows the user to modify effects of other players"), [$operatorRoot, $effectRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_EFFECT_SELF, "Allows the user to modify their own effects"), [$operatorRoot, $effectRoot]);
$enchantRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_ENCHANT);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_ENCHANT_OTHER, "Allows the user to enchant the held items of other players"), [$operatorRoot, $enchantRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_ENCHANT_SELF, "Allows the user to enchant their own held item"), [$operatorRoot, $enchantRoot]);
$gameModeRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_GAMEMODE);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GAMEMODE_OTHER, "Allows the user to change the game mode of other players"), [$operatorRoot, $gameModeRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GAMEMODE_SELF, "Allows the user to change their own game mode"), [$operatorRoot, $gameModeRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GC, "Allows the user to fire garbage collection tasks"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GIVE, "Allows the user to give items to players"), [$operatorRoot]);
$giveRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_GIVE);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GIVE_OTHER, "Allows the user to give items to other players"), [$operatorRoot, $giveRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GIVE_SELF, "Allows the user to give items to themselves"), [$operatorRoot, $giveRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_HELP, "Allows the user to view the help menu"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_KICK, "Allows the user to kick players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_KILL_OTHER, "Allows the user to kill other players"), [$operatorRoot]);
@@ -80,10 +100,18 @@ abstract class DefaultPermissions{
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SAY, "Allows the user to talk as the console"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SEED, "Allows the user to view the seed of the world"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SETWORLDSPAWN, "Allows the user to change the world spawn"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SPAWNPOINT, "Allows the user to change player's spawnpoint"), [$operatorRoot]);
$spawnpointRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_SPAWNPOINT);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SPAWNPOINT_OTHER, "Allows the user to change the respawn point of other players"), [$operatorRoot, $spawnpointRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SPAWNPOINT_SELF, "Allows the user to change their own respawn point"), [$operatorRoot, $spawnpointRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_STATUS, "Allows the user to view the server performance"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_STOP, "Allows the user to stop the server"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TELEPORT, "Allows the user to teleport players"), [$operatorRoot]);
$teleportRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_TELEPORT);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TELEPORT_OTHER, "Allows the user to teleport other players"), [$operatorRoot, $teleportRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TELEPORT_SELF, "Allows the user to teleport themselves"), [$operatorRoot, $teleportRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TELL, "Allows the user to privately message another player"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIME_ADD, "Allows the user to fast-forward time"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIME_QUERY, "Allows the user query the time"), [$operatorRoot]);
@@ -91,7 +119,11 @@ abstract class DefaultPermissions{
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIME_START, "Allows the user to restart the time"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIME_STOP, "Allows the user to stop the time"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIMINGS, "Allows the user to record timings to analyse server performance"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TITLE, "Allows the user to send a title to the specified player"), [$operatorRoot]);
$titleRoot = self::registerDeprecatedPermission(DefaultPermissionNames::COMMAND_TITLE);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TITLE_OTHER, "Allows the user to send a title to the specified player"), [$operatorRoot, $titleRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TITLE_SELF, "Allows the user to send a title to themselves"), [$operatorRoot, $titleRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TRANSFERSERVER, "Allows the user to transfer self to another server"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_UNBAN_IP, "Allows the user to unban IP addresses"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_UNBAN_PLAYER, "Allows the user to unban players"), [$operatorRoot]);