Permissions

How to use the permission system


This part is only relevant for server commands and dedicated servers. For client commands there are no permissions required at all, you can use them all the time without any operators rights. In singleplayer, the ability whether commands can be used or can't be used is determined only by the world setting "cheats" (whether the "cheats" are enabled/disabled). If cheats are disabled, you can enable them using the "cheats" command which can ALWAYS be used, cheats don't have to be enabled for this command (everything else would be quite useless...). This section deals only with a dedicated server so if you don't need that you can skip this section.

Minecraft has a very basic and simple permissions system which allows to assign a permission level to every player who is an operator. Unfortunately minecraft itself does not provide any access to this system. If you make a player an operator, the player's permission level will be set to "op-permission-level" which is defined in "server.properties". This is the maximum permission level that exists, by default it is 4. So why not making it possible to assign a custom permission level to each player and each command to be able to make it possible to have a better control of the access to commands? MoreCommands introduces two things to do that: A "permission" command and a modified "op" command. The new syntax of the "op" command is:

/op <PLAYER> [PERM_LEVEL]

As you can see, there is an additional optional parameter "PERM_LEVEL". This parameter has to be the desired permission level for the player. If the permission level is not specified, the default permission level will be used which is "op-permission-level" and therefore the highest permission level too. Of course, you need the highest permission level (op-permission-level) to use this command otherwise you could give yourself a higher permission level...
There's another way to set a player's permission level, but this can't be done ingame and requires a server restart and the player has already to be an operator. If all this is given, you can change the permission level in the "ops.json" file. It contains a list of operators, each of them has a "level" property which you can simply change to the desired level. This however, as already said, requires a restart of the server to take effect and the player must already be an operator to be in the list.

Now comes the important part: the "permission" command which allows you to set the permission level which is required for a command. Unfortunately it is only possible to set the permission levels for commands added by MoreCommands since those of minecraft's commands are hardcoded (Actually it would be possible to change that using bytecode transformations, this would probably work without any problem for minecraft's commands but it could cause issues for commands added by other mods so it's safer not to do that). The syntax of this command is:

/permission <setaction <COMMAND> <ACTION> <LEVEL>|setbase <COMMAND> <LEVEL>>
/permission <getaction <COMMAND> <ACTION>|getbase <COMMAND>>
/permission <resetaction <COMMAND> <ACTION>|resetbase <COMMAND>|resetall <COMMAND>>

As you can see, the permission command allows you to set a base permission level which is the basic permission level which will be used for the entire command.
Additionally this command allows you to set action permission levels which simply means that specific actions for some commands can have their own permission level. This way you can restrict the usage of a command to single "actions" (e.g. for the /chatchannel command, you can allow players to join and leave chat channels but not to create/destroy/update chat channels). An "action" is defined to be the first parameter of a command (e.g. "join", "create", etc. are the first possible arguments for the "/chatchannel" command).
Also you can print the permission level for a command to the chat console using the getaction and the getbase parameter.
At last you can reset the permission levels to their default values using the resetaction, resetbase and resetall parameters. The first two reset either a specifc ation or base, the latter resets both.
Using the "permission" command requires the highest permission level (op-permission-level) otherwise you could lower the permission level to be able to execute it although you're not allowed to. The permission level that is set via this command will always be greater or equal to zero but never be greater than "op-permission-level". If it is higer, it will use "op-permission-level".
This command additionally saves the permission level that is required for a command into a file called "permissions.cfg". It is a simple properties file which maps the command name to the permission levels. The different permission levels (base level and action levels) must be written into ONE single line. Base permission levels are written as a single number while action permission levels start with the action name followed by a colon and the the level for that action. Different permission levels (base level and each action level) are separated by a comma. This is an example:

examplecommand=4,action1:2,action2:0
chatchannel=4,join:1,leave:3,create:0
	
As you can see this file uses simple "COMMAND_NAME=PERM_LEVELS" properties so you can simply add your own permission levels. This file is the equivalence to "ops.json". As it is the case for "ops.json", it is also the case for this file to require a restart of the server if you want changes in this file to take effect, so using the command is much easier.

The combination of the modified "op" command and the "permission" command allows you to set permissions for commands relatively easy. There is however a problem caused by minecraft: Players who are not an operator can only use the following commands: "seed" (if in singleplayer), "tell", "me", "trigger", "help" and commands added by MoreCommands which have the permission level 0. This is because minecraft does only check the permission level if the player is an operator. Commands can override this behaviour and this is why MoreCommands allows players to execute commands having permission level 0 although not being an operator. This behaviour applies only for permission level 0, all other permission levels will trigger minecrafts default behaviour to check whether the player can use the command. For minecraft's own commands which require permission level 0 (luckily there is none except for the ones named above) or commands added by other mods which don't override the default behaviour, I recommend to use the modified "op" command to allow players to use such commands (use "/op <PLAYER> 0"). Otherwise they aren't able to use totally harmless commands (at least commands requiring permission level 0 should be harmless).