Stop hardcoding permission names everywhere

using strings for permission names is nearly as shitty, but this is at least cross-referencable and statically analysable.
This commit is contained in:
Dylan K. Taylor 2021-06-26 19:14:51 +01:00
parent 0910054c41
commit bf7d69b69e
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
43 changed files with 267 additions and 115 deletions

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use function array_shift;
use function count;
@ -40,7 +41,7 @@ class BanCommand extends VanillaCommand{
"%pocketmine.command.ban.player.description",
"%commands.ban.usage"
);
$this->setPermission("pocketmine.command.ban.player");
$this->setPermission(DefaultPermissionNames::COMMAND_BAN_PLAYER);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use function array_shift;
use function count;
@ -41,7 +42,7 @@ class BanIpCommand extends VanillaCommand{
"%pocketmine.command.ban.ip.description",
"%commands.banip.usage"
);
$this->setPermission("pocketmine.command.ban.ip");
$this->setPermission(DefaultPermissionNames::COMMAND_BAN_IP);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\BanEntry;
use pocketmine\permission\DefaultPermissionNames;
use function array_map;
use function count;
use function implode;
@ -42,7 +43,7 @@ class BanListCommand extends VanillaCommand{
"%pocketmine.command.banlist.description",
"%commands.banlist.usage"
);
$this->setPermission("pocketmine.command.ban.list");
$this->setPermission(DefaultPermissionNames::COMMAND_BAN_LIST);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -29,10 +29,12 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\item\LegacyStringToItemParser;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function array_merge;
use function count;
use function implode;
class ClearCommand extends VanillaCommand{
@ -42,7 +44,7 @@ class ClearCommand extends VanillaCommand{
"%pocketmine.command.clear.description",
"%pocketmine.command.clear.usage"
);
$this->setPermission("pocketmine.command.clear.self;pocketmine.command.clear.other");
$this->setPermission(implode(";", [DefaultPermissionNames::COMMAND_CLEAR_SELF, DefaultPermissionNames::COMMAND_CLEAR_OTHER]));
}
public function execute(CommandSender $sender, string $commandLabel, array $args){
@ -61,12 +63,12 @@ class ClearCommand extends VanillaCommand{
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
return true;
}
if($target !== $sender && !$sender->hasPermission("pocketmine.command.clear.other")){
if($target !== $sender && !$sender->hasPermission(DefaultPermissionNames::COMMAND_CLEAR_OTHER)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
}
}elseif($sender instanceof Player){
if(!$sender->hasPermission("pocketmine.command.clear.self")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_CLEAR_SELF)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
}

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\GameMode;
use function count;
@ -37,7 +38,7 @@ class DefaultGamemodeCommand extends VanillaCommand{
"%pocketmine.command.defaultgamemode.description",
"%commands.defaultgamemode.usage"
);
$this->setPermission("pocketmine.command.defaultgamemode");
$this->setPermission(DefaultPermissionNames::COMMAND_DEFAULTGAMEMODE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function array_shift;
@ -40,7 +41,7 @@ class DeopCommand extends VanillaCommand{
"%pocketmine.command.deop.description",
"%commands.deop.usage"
);
$this->setPermission("pocketmine.command.op.take");
$this->setPermission(DefaultPermissionNames::COMMAND_OP_TAKE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\world\World;
use function count;
@ -38,7 +39,7 @@ class DifficultyCommand extends VanillaCommand{
"%pocketmine.command.difficulty.description",
"%commands.difficulty.usage"
);
$this->setPermission("pocketmine.command.difficulty");
$this->setPermission(DefaultPermissionNames::COMMAND_DIFFICULTY);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\permission\DefaultPermissionNames;
use function date;
class DumpMemoryCommand extends VanillaCommand{
@ -34,7 +35,7 @@ class DumpMemoryCommand extends VanillaCommand{
"Dumps the memory",
"/$name [path]"
);
$this->setPermission("pocketmine.command.dumpmemory");
$this->setPermission(DefaultPermissionNames::COMMAND_DUMPMEMORY);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -28,6 +28,7 @@ use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\Limits;
use pocketmine\utils\TextFormat;
use function count;
@ -41,7 +42,7 @@ class EffectCommand extends VanillaCommand{
"%pocketmine.command.effect.description",
"%commands.effect.usage"
);
$this->setPermission("pocketmine.command.effect");
$this->setPermission(DefaultPermissionNames::COMMAND_EFFECT);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -28,6 +28,7 @@ use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\TextFormat;
use function count;
@ -39,7 +40,7 @@ class EnchantCommand extends VanillaCommand{
"%pocketmine.command.enchant.description",
"%commands.enchant.usage"
);
$this->setPermission("pocketmine.command.enchant");
$this->setPermission(DefaultPermissionNames::COMMAND_ENCHANT);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\GameMode;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
@ -40,7 +41,7 @@ class GamemodeCommand extends VanillaCommand{
"%pocketmine.command.gamemode.description",
"%commands.gamemode.usage"
);
$this->setPermission("pocketmine.command.gamemode");
$this->setPermission(DefaultPermissionNames::COMMAND_GAMEMODE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\TextFormat;
use function count;
use function memory_get_usage;
@ -38,7 +39,7 @@ class GarbageCollectorCommand extends VanillaCommand{
"%pocketmine.command.gc.description",
"%pocketmine.command.gc.usage"
);
$this->setPermission("pocketmine.command.gc");
$this->setPermission(DefaultPermissionNames::COMMAND_GC);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -30,6 +30,7 @@ use pocketmine\item\LegacyStringToItemParser;
use pocketmine\lang\TranslationContainer;
use pocketmine\nbt\JsonNbtParser;
use pocketmine\nbt\NbtDataException;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\TextFormat;
use function array_slice;
use function count;
@ -43,7 +44,7 @@ class GiveCommand extends VanillaCommand{
"%pocketmine.command.give.description",
"%pocketmine.command.give.usage"
);
$this->setPermission("pocketmine.command.give");
$this->setPermission(DefaultPermissionNames::COMMAND_GIVE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\TextFormat;
use function array_chunk;
use function array_pop;
@ -48,7 +49,7 @@ class HelpCommand extends VanillaCommand{
"%commands.help.usage",
["?"]
);
$this->setPermission("pocketmine.command.help");
$this->setPermission(DefaultPermissionNames::COMMAND_HELP);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function array_shift;
@ -42,7 +43,7 @@ class KickCommand extends VanillaCommand{
"%pocketmine.command.kick.description",
"%commands.kick.usage"
);
$this->setPermission("pocketmine.command.kick");
$this->setPermission(DefaultPermissionNames::COMMAND_KICK);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -28,9 +28,11 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function count;
use function implode;
class KillCommand extends VanillaCommand{
@ -41,7 +43,7 @@ class KillCommand extends VanillaCommand{
"%pocketmine.command.kill.usage",
["suicide"]
);
$this->setPermission("pocketmine.command.kill.self;pocketmine.command.kill.other");
$this->setPermission(implode(";", [DefaultPermissionNames::COMMAND_KILL_SELF, DefaultPermissionNames::COMMAND_KILL_OTHER]));
}
public function execute(CommandSender $sender, string $commandLabel, array $args){
@ -54,7 +56,7 @@ class KillCommand extends VanillaCommand{
}
if(count($args) === 1){
if(!$sender->hasPermission("pocketmine.command.kill.other")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_KILL_OTHER)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
@ -73,7 +75,7 @@ class KillCommand extends VanillaCommand{
}
if($sender instanceof Player){
if(!$sender->hasPermission("pocketmine.command.kill.self")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_KILL_SELF)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use function array_filter;
use function array_map;
@ -41,7 +42,7 @@ class ListCommand extends VanillaCommand{
"%pocketmine.command.list.description",
"%command.players.usage"
);
$this->setPermission("pocketmine.command.list");
$this->setPermission(DefaultPermissionNames::COMMAND_LIST);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function count;
@ -39,7 +40,7 @@ class MeCommand extends VanillaCommand{
"%pocketmine.command.me.description",
"%commands.me.usage"
);
$this->setPermission("pocketmine.command.me");
$this->setPermission(DefaultPermissionNames::COMMAND_ME);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function array_shift;
@ -40,7 +41,7 @@ class OpCommand extends VanillaCommand{
"%pocketmine.command.op.description",
"%commands.op.usage"
);
$this->setPermission("pocketmine.command.op.give");
$this->setPermission(DefaultPermissionNames::COMMAND_OP_GIVE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use function count;
class PardonCommand extends VanillaCommand{
@ -38,7 +39,7 @@ class PardonCommand extends VanillaCommand{
"%commands.unban.usage",
["unban"]
);
$this->setPermission("pocketmine.command.unban.player");
$this->setPermission(DefaultPermissionNames::COMMAND_UNBAN_PLAYER);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use function count;
use function preg_match;
@ -39,7 +40,7 @@ class PardonIpCommand extends VanillaCommand{
"%commands.unbanip.usage",
["unban-ip"]
);
$this->setPermission("pocketmine.command.unban.ip");
$this->setPermission(DefaultPermissionNames::COMMAND_UNBAN_IP);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -31,6 +31,7 @@ use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\lang\TranslationContainer;
use pocketmine\math\Vector3;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\Random;
use pocketmine\utils\TextFormat;
@ -80,7 +81,7 @@ class ParticleCommand extends VanillaCommand{
"%pocketmine.command.particle.description",
"%pocketmine.command.particle.usage"
);
$this->setPermission("pocketmine.command.particle");
$this->setPermission(DefaultPermissionNames::COMMAND_PARTICLE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat;
use function array_map;
@ -42,7 +43,7 @@ class PluginsCommand extends VanillaCommand{
"%pocketmine.command.plugins.usage",
["pl"]
);
$this->setPermission("pocketmine.command.plugins");
$this->setPermission(DefaultPermissionNames::COMMAND_PLUGINS);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use function microtime;
use function round;
@ -37,7 +38,7 @@ class SaveCommand extends VanillaCommand{
"%pocketmine.command.save.description",
"%commands.save.usage"
);
$this->setPermission("pocketmine.command.save.perform");
$this->setPermission(DefaultPermissionNames::COMMAND_SAVE_PERFORM);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
class SaveOffCommand extends VanillaCommand{
@ -35,7 +36,7 @@ class SaveOffCommand extends VanillaCommand{
"%pocketmine.command.saveoff.description",
"%commands.save-off.usage"
);
$this->setPermission("pocketmine.command.save.disable");
$this->setPermission(DefaultPermissionNames::COMMAND_SAVE_DISABLE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
class SaveOnCommand extends VanillaCommand{
@ -35,7 +36,7 @@ class SaveOnCommand extends VanillaCommand{
"%pocketmine.command.saveon.description",
"%commands.save-on.usage"
);
$this->setPermission("pocketmine.command.save.enable");
$this->setPermission(DefaultPermissionNames::COMMAND_SAVE_ENABLE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function count;
@ -40,7 +41,7 @@ class SayCommand extends VanillaCommand{
"%pocketmine.command.say.description",
"%commands.say.usage"
);
$this->setPermission("pocketmine.command.say");
$this->setPermission(DefaultPermissionNames::COMMAND_SAY);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
class SeedCommand extends VanillaCommand{
@ -35,7 +36,7 @@ class SeedCommand extends VanillaCommand{
"%pocketmine.command.seed.description",
"%commands.seed.usage"
);
$this->setPermission("pocketmine.command.seed");
$this->setPermission(DefaultPermissionNames::COMMAND_SEED);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -28,6 +28,7 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\math\Vector3;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function count;
@ -41,7 +42,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
"%pocketmine.command.setworldspawn.description",
"%commands.setworldspawn.usage"
);
$this->setPermission("pocketmine.command.setworldspawn");
$this->setPermission(DefaultPermissionNames::COMMAND_SETWORLDSPAWN);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use pocketmine\world\Position;
@ -42,7 +43,7 @@ class SpawnpointCommand extends VanillaCommand{
"%pocketmine.command.spawnpoint.description",
"%commands.spawnpoint.usage"
);
$this->setPermission("pocketmine.command.spawnpoint");
$this->setPermission(DefaultPermissionNames::COMMAND_SPAWNPOINT);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\Process;
use pocketmine\utils\TextFormat;
use function count;
@ -40,7 +41,7 @@ class StatusCommand extends VanillaCommand{
"%pocketmine.command.status.description",
"%pocketmine.command.status.usage"
);
$this->setPermission("pocketmine.command.status");
$this->setPermission(DefaultPermissionNames::COMMAND_STATUS);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
class StopCommand extends VanillaCommand{
@ -35,7 +36,7 @@ class StopCommand extends VanillaCommand{
"%pocketmine.command.stop.description",
"%commands.stop.usage"
);
$this->setPermission("pocketmine.command.stop");
$this->setPermission(DefaultPermissionNames::COMMAND_STOP);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -28,6 +28,7 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\entity\Location;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\TextFormat;
@ -44,7 +45,7 @@ class TeleportCommand extends VanillaCommand{
"%commands.tp.usage",
["teleport"]
);
$this->setPermission("pocketmine.command.teleport");
$this->setPermission(DefaultPermissionNames::COMMAND_TELEPORT);
}
private function findPlayer(CommandSender $sender, string $playerName) : ?Player{

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use function array_shift;
@ -42,7 +43,7 @@ class TellCommand extends VanillaCommand{
"%commands.message.usage",
["w", "msg"]
);
$this->setPermission("pocketmine.command.tell");
$this->setPermission(DefaultPermissionNames::COMMAND_TELL);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,10 +27,12 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use pocketmine\world\World;
use function count;
use function implode;
class TimeCommand extends VanillaCommand{
@ -40,16 +42,25 @@ class TimeCommand extends VanillaCommand{
"%pocketmine.command.time.description",
"%pocketmine.command.time.usage"
);
$this->setPermission("pocketmine.command.time.add;pocketmine.command.time.set;pocketmine.command.time.start;pocketmine.command.time.stop");
$this->setPermission(implode(";", [
DefaultPermissionNames::COMMAND_TIME_ADD,
DefaultPermissionNames::COMMAND_TIME_SET,
DefaultPermissionNames::COMMAND_TIME_START,
DefaultPermissionNames::COMMAND_TIME_STOP,
DefaultPermissionNames::COMMAND_TIME_QUERY
]));
}
public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){
return true;
}
if(count($args) < 1){
throw new InvalidCommandSyntaxException();
}
if($args[0] === "start"){
if(!$sender->hasPermission("pocketmine.command.time.start")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_TIME_START)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
@ -60,7 +71,7 @@ class TimeCommand extends VanillaCommand{
Command::broadcastCommandMessage($sender, "Restarted the time");
return true;
}elseif($args[0] === "stop"){
if(!$sender->hasPermission("pocketmine.command.time.stop")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_TIME_STOP)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
@ -71,7 +82,7 @@ class TimeCommand extends VanillaCommand{
Command::broadcastCommandMessage($sender, "Stopped the time");
return true;
}elseif($args[0] === "query"){
if(!$sender->hasPermission("pocketmine.command.time.query")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_TIME_QUERY)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
@ -90,7 +101,7 @@ class TimeCommand extends VanillaCommand{
}
if($args[0] === "set"){
if(!$sender->hasPermission("pocketmine.command.time.set")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_TIME_SET)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;
@ -125,7 +136,7 @@ class TimeCommand extends VanillaCommand{
}
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.set", [$value]));
}elseif($args[0] === "add"){
if(!$sender->hasPermission("pocketmine.command.time.add")){
if(!$sender->hasPermission(DefaultPermissionNames::COMMAND_TIME_ADD)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;

View File

@ -27,6 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\scheduler\BulkCurlTask;
use pocketmine\scheduler\BulkCurlTaskOperation;
@ -60,7 +61,7 @@ class TimingsCommand extends VanillaCommand{
"%pocketmine.command.timings.description",
"%pocketmine.command.timings.usage"
);
$this->setPermission("pocketmine.command.timings");
$this->setPermission(DefaultPermissionNames::COMMAND_TIMINGS);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use function array_slice;
use function count;
use function implode;
@ -38,7 +39,7 @@ class TitleCommand extends VanillaCommand{
"%pocketmine.command.title.description",
"%commands.title.usage"
);
$this->setPermission("pocketmine.command.title");
$this->setPermission(DefaultPermissionNames::COMMAND_TITLE);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use function count;
@ -36,7 +37,7 @@ class TransferServerCommand extends VanillaCommand{
"%pocketmine.command.transferserver.description",
"%pocketmine.command.transferserver.usage"
);
$this->setPermission("pocketmine.command.transferserver");
$this->setPermission(DefaultPermissionNames::COMMAND_TRANSFERSERVER);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,6 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat;
use function count;
@ -42,7 +43,7 @@ class VersionCommand extends VanillaCommand{
"%pocketmine.command.version.usage",
["ver", "about"]
);
$this->setPermission("pocketmine.command.version");
$this->setPermission(DefaultPermissionNames::COMMAND_VERSION);
}
public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -27,7 +27,9 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\TextFormat;
use function count;
use function implode;
@ -43,7 +45,14 @@ class WhitelistCommand extends VanillaCommand{
"%pocketmine.command.whitelist.description",
"%commands.whitelist.usage"
);
$this->setPermission("pocketmine.command.whitelist.reload;pocketmine.command.whitelist.enable;pocketmine.command.whitelist.disable;pocketmine.command.whitelist.list;pocketmine.command.whitelist.add;pocketmine.command.whitelist.remove");
$this->setPermission(implode(";", [
DefaultPermissionNames::COMMAND_WHITELIST_RELOAD,
DefaultPermissionNames::COMMAND_WHITELIST_ENABLE,
DefaultPermissionNames::COMMAND_WHITELIST_DISABLE,
DefaultPermissionNames::COMMAND_WHITELIST_LIST,
DefaultPermissionNames::COMMAND_WHITELIST_ADD,
DefaultPermissionNames::COMMAND_WHITELIST_REMOVE
]));
}
public function execute(CommandSender $sender, string $commandLabel, array $args){
@ -115,11 +124,18 @@ class WhitelistCommand extends VanillaCommand{
}
private function badPerm(CommandSender $sender, string $subcommand) : bool{
static $map = [
"on" => "enable",
"off" => "disable"
];
if(!$sender->hasPermission("pocketmine.command.whitelist." . ($map[$subcommand] ?? $subcommand))){
$permission = [
"reload" => DefaultPermissionNames::COMMAND_WHITELIST_RELOAD,
"on" => DefaultPermissionNames::COMMAND_WHITELIST_ENABLE,
"off" => DefaultPermissionNames::COMMAND_WHITELIST_DISABLE,
"list" => DefaultPermissionNames::COMMAND_WHITELIST_LIST,
"add" => DefaultPermissionNames::COMMAND_WHITELIST_ADD,
"remove" => DefaultPermissionNames::COMMAND_WHITELIST_REMOVE
][$subcommand] ?? null;
if($permission === null){
throw new AssumptionFailedError("Unknown subcommand $subcommand");
}
if(!$sender->hasPermission($permission)){
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;

View File

@ -0,0 +1,83 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\permission;
final class DefaultPermissionNames{
public const BROADCAST_ADMIN = "pocketmine.broadcast.admin";
public const BROADCAST_USER = "pocketmine.broadcast.user";
public const COMMAND_BAN_IP = "pocketmine.command.ban.ip";
public const COMMAND_BAN_LIST = "pocketmine.command.ban.list";
public const COMMAND_BAN_PLAYER = "pocketmine.command.ban.player";
public const COMMAND_CLEAR_OTHER = "pocketmine.command.clear.other";
public const COMMAND_CLEAR_SELF = "pocketmine.command.clear.self";
public const COMMAND_DEFAULTGAMEMODE = "pocketmine.command.defaultgamemode";
public const COMMAND_DIFFICULTY = "pocketmine.command.difficulty";
public const COMMAND_DUMPMEMORY = "pocketmine.command.dumpmemory";
public const COMMAND_EFFECT = "pocketmine.command.effect";
public const COMMAND_ENCHANT = "pocketmine.command.enchant";
public const COMMAND_GAMEMODE = "pocketmine.command.gamemode";
public const COMMAND_GC = "pocketmine.command.gc";
public const COMMAND_GIVE = "pocketmine.command.give";
public const COMMAND_HELP = "pocketmine.command.help";
public const COMMAND_KICK = "pocketmine.command.kick";
public const COMMAND_KILL_OTHER = "pocketmine.command.kill.other";
public const COMMAND_KILL_SELF = "pocketmine.command.kill.self";
public const COMMAND_LIST = "pocketmine.command.list";
public const COMMAND_ME = "pocketmine.command.me";
public const COMMAND_OP_GIVE = "pocketmine.command.op.give";
public const COMMAND_OP_TAKE = "pocketmine.command.op.take";
public const COMMAND_PARTICLE = "pocketmine.command.particle";
public const COMMAND_PLUGINS = "pocketmine.command.plugins";
public const COMMAND_SAVE_DISABLE = "pocketmine.command.save.disable";
public const COMMAND_SAVE_ENABLE = "pocketmine.command.save.enable";
public const COMMAND_SAVE_PERFORM = "pocketmine.command.save.perform";
public const COMMAND_SAY = "pocketmine.command.say";
public const COMMAND_SEED = "pocketmine.command.seed";
public const COMMAND_SETWORLDSPAWN = "pocketmine.command.setworldspawn";
public const COMMAND_SPAWNPOINT = "pocketmine.command.spawnpoint";
public const COMMAND_STATUS = "pocketmine.command.status";
public const COMMAND_STOP = "pocketmine.command.stop";
public const COMMAND_TELEPORT = "pocketmine.command.teleport";
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";
public const COMMAND_TIME_SET = "pocketmine.command.time.set";
public const COMMAND_TIME_START = "pocketmine.command.time.start";
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_TRANSFERSERVER = "pocketmine.command.transferserver";
public const COMMAND_UNBAN_IP = "pocketmine.command.unban.ip";
public const COMMAND_UNBAN_PLAYER = "pocketmine.command.unban.player";
public const COMMAND_VERSION = "pocketmine.command.version";
public const COMMAND_WHITELIST_ADD = "pocketmine.command.whitelist.add";
public const COMMAND_WHITELIST_DISABLE = "pocketmine.command.whitelist.disable";
public const COMMAND_WHITELIST_ENABLE = "pocketmine.command.whitelist.enable";
public const COMMAND_WHITELIST_LIST = "pocketmine.command.whitelist.list";
public const COMMAND_WHITELIST_RELOAD = "pocketmine.command.whitelist.reload";
public const COMMAND_WHITELIST_REMOVE = "pocketmine.command.whitelist.remove";
public const GROUP_CONSOLE = "pocketmine.group.console";
public const GROUP_OPERATOR = "pocketmine.group.operator";
public const GROUP_USER = "pocketmine.group.user";
}

View File

@ -24,11 +24,9 @@ declare(strict_types=1);
namespace pocketmine\permission;
abstract class DefaultPermissions{
public const ROOT = "pocketmine";
public const ROOT_CONSOLE = "pocketmine.group.console";
public const ROOT_OPERATOR = "pocketmine.group.operator";
public const ROOT_USER = "pocketmine.group.user";
public const ROOT_CONSOLE = DefaultPermissionNames::GROUP_CONSOLE;
public const ROOT_OPERATOR = DefaultPermissionNames::GROUP_OPERATOR;
public const ROOT_USER = DefaultPermissionNames::GROUP_USER;
/**
* @param Permission[] $grantedBy
@ -51,67 +49,67 @@ abstract class DefaultPermissions{
$operatorRoot = self::registerPermission(new Permission(self::ROOT_OPERATOR, "Grants all operator permissions"), [$consoleRoot]);
$everyoneRoot = self::registerPermission(new Permission(self::ROOT_USER, "Grants all non-sensitive permissions that everyone gets by default"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".broadcast.admin", "Allows the user to receive administrative broadcasts"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".broadcast.user", "Allows the user to receive user broadcasts"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::BROADCAST_ADMIN, "Allows the user to receive administrative broadcasts"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::BROADCAST_USER, "Allows the user to receive user broadcasts"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.whitelist.add", "Allows the user to add a player to the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.whitelist.remove", "Allows the user to remove a player from the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.whitelist.reload", "Allows the user to reload the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.whitelist.enable", "Allows the user to enable the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.whitelist.disable", "Allows the user to disable the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.whitelist.list", "Allows the user to list all players on the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_WHITELIST_ADD, "Allows the user to add a player to the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_WHITELIST_REMOVE, "Allows the user to remove a player from the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_WHITELIST_RELOAD, "Allows the user to reload the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_WHITELIST_ENABLE, "Allows the user to enable the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_WHITELIST_DISABLE, "Allows the user to disable the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_WHITELIST_LIST, "Allows the user to list all players on the server whitelist"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.ban.player", "Allows the user to ban players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.ban.ip", "Allows the user to ban IP addresses"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.ban.list", "Allows the user to list banned players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_BAN_PLAYER, "Allows the user to ban players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_BAN_IP, "Allows the user to ban IP addresses"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_BAN_LIST, "Allows the user to list banned players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.unban.player", "Allows the user to unban players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".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]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_UNBAN_IP, "Allows the user to unban IP addresses"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.op.give", "Allows the user to give a player operator status"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.op.take", "Allows the user to take a player's operator status"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_OP_GIVE, "Allows the user to give a player operator status"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_OP_TAKE, "Allows the user to take a player's operator status"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.save.enable", "Allows the user to enable automatic saving"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.save.disable", "Allows the user to disable automatic saving"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.save.perform", "Allows the user to perform a manual save"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SAVE_ENABLE, "Allows the user to enable automatic saving"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SAVE_DISABLE, "Allows the user to disable automatic saving"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SAVE_PERFORM, "Allows the user to perform a manual save"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.time.add", "Allows the user to fast-forward time"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.time.set", "Allows the user to change the time"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.time.start", "Allows the user to restart the time"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.time.stop", "Allows the user to stop the time"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.time.query", "Allows the user query the time"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIME_ADD, "Allows the user to fast-forward time"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIME_SET, "Allows the user to change the time"), [$operatorRoot]);
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_TIME_QUERY, "Allows the user query the time"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.kill.self", "Allows the user to commit suicide"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.kill.other", "Allows the user to kill other players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_KILL_SELF, "Allows the user to commit suicide"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_KILL_OTHER, "Allows the user to kill other players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.clear.self", "Allows the user to clear their own inventory"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.clear.other", "Allows the user to clear inventory of other players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_CLEAR_SELF, "Allows the user to clear their own inventory"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_CLEAR_OTHER, "Allows the user to clear inventory of other players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.me", "Allows the user to perform a chat action"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.tell", "Allows the user to privately message another player"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.say", "Allows the user to talk as the console"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.give", "Allows the user to give items to players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.effect", "Allows the user to give/take potion effects"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.enchant", "Allows the user to enchant items"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.particle", "Allows the user to create particle effects"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.teleport", "Allows the user to teleport players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.kick", "Allows the user to kick players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.stop", "Allows the user to stop the server"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.list", "Allows the user to list all online players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.help", "Allows the user to view the help menu"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.plugins", "Allows the user to view the list of plugins"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.version", "Allows the user to view the version of the server"), [$everyoneRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.gamemode", "Allows the user to change the gamemode of players"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.defaultgamemode", "Allows the user to change the default gamemode"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.seed", "Allows the user to view the seed of the world"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.status", "Allows the user to view the server performance"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.gc", "Allows the user to fire garbage collection tasks"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.dumpmemory", "Allows the user to dump memory contents"), [$consoleRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.timings", "Allows the user to records timings for all plugin events"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.spawnpoint", "Allows the user to change player's spawnpoint"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.setworldspawn", "Allows the user to change the world spawn"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.transferserver", "Allows the user to transfer self to another server"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.title", "Allows the user to send a title to the specified player"), [$operatorRoot]);
self::registerPermission(new Permission(self::ROOT . ".command.difficulty", "Allows the user to change the game difficulty"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_ME, "Allows the user to perform a chat action"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TELL, "Allows the user to privately message another player"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SAY, "Allows the user to talk as the console"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GIVE, "Allows the user to give items to players"), [$operatorRoot]);
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_PARTICLE, "Allows the user to create particle effects"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TELEPORT, "Allows the user to teleport players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_KICK, "Allows the user to kick players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_STOP, "Allows the user to stop the server"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_LIST, "Allows the user to list all online players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_HELP, "Allows the user to view the help menu"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_PLUGINS, "Allows the user to view the list of plugins"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_VERSION, "Allows the user to view the version of the server"), [$everyoneRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GAMEMODE, "Allows the user to change the gamemode of players"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_DEFAULTGAMEMODE, "Allows the user to change the default gamemode"), [$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_STATUS, "Allows the user to view the server performance"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_GC, "Allows the user to fire garbage collection tasks"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_DUMPMEMORY, "Allows the user to dump memory contents"), [$consoleRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TIMINGS, "Allows the user to records timings for all plugin events"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SPAWNPOINT, "Allows the user to change player's spawnpoint"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_SETWORLDSPAWN, "Allows the user to change the world spawn"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TRANSFERSERVER, "Allows the user to transfer self to another server"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_TITLE, "Allows the user to send a title to the specified player"), [$operatorRoot]);
self::registerPermission(new Permission(DefaultPermissionNames::COMMAND_DIFFICULTY, "Allows the user to change the game difficulty"), [$operatorRoot]);
}
}

View File

@ -92,6 +92,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\entity\PlayerMetadataFlags;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\permission\DefaultPermissions;
use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissibleDelegateTrait;
@ -768,8 +769,11 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
}
private function recheckBroadcastPermissions() : void{
foreach([Server::BROADCAST_CHANNEL_USERS, Server::BROADCAST_CHANNEL_ADMINISTRATIVE] as $channel){
if($this->hasPermission($channel)){
foreach([
DefaultPermissionNames::BROADCAST_ADMIN => Server::BROADCAST_CHANNEL_ADMINISTRATIVE,
DefaultPermissionNames::BROADCAST_USER => Server::BROADCAST_CHANNEL_USERS
] as $permission => $channel){
if($this->hasPermission($permission)){
$this->server->subscribeToBroadcastChannel($channel, $this);
}else{
$this->server->unsubscribeFromBroadcastChannel($channel, $this);
@ -807,7 +811,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->spawnToAll();
if($this->server->getUpdater()->hasUpdate() and $this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE) and $this->server->getConfigGroup()->getPropertyBool("auto-updater.on-update.warn-ops", true)){
if($this->server->getUpdater()->hasUpdate() and $this->hasPermission(DefaultPermissionNames::BROADCAST_ADMIN) and $this->server->getConfigGroup()->getPropertyBool("auto-updater.on-update.warn-ops", true)){
$this->server->getUpdater()->showPlayerUpdate($this);
}