Commands

From SupaHam
Jump to: navigation, search

A command in Minecraft starts with a forward slash (/).

Example:
/seed

The seed command is a vanilla command, meaning it comes with Minecraft without any modifications.

Permissions

Some commands require permissions. If a player does not have the appropriate permissions for a command an error message is sent to the player. Vanilla commands that require permissions are acquired by becoming an Operator.

Though Minecraft server modifications such as Bukkit have a permissions implementation that allow you to apply permission nodes (String) to players, this allows for maximum flexibility.

Example:
Imagine a scenario where you, as a server admin, want to give a player permission to only mute other players, to help keep the chat clean. Without Bukkit this is not possible. You would have to give that player op status which gives them permission to all other commands on the server. You might not be able to trust someone with that many permissions, this is where Bukkit's SuperPerms implementation comes in. SuperPerms is a Bukkit implementation that allows for plugins to hook into Bukkit and check player permissions and with a permissions management plugin such as PermissionsEx you are able to manage player permissions and do much more.

A permission node is a String (text) usually seperated with fullstops/periods (.) instead of whitespaces.

Example:
"my.command.permission"

Arguments

There are commands such as /seed which are simple that tell you the seed of the current world you're in, but commands do much more than that. As a developer, you can implement commands with arguments to allow your users to insert their own values and the rest is done behind the scenes (in the code).

Example:
/tp [target player] <destination player>
/tp [target player] <x> <y> <z>

The example above is copied straight out of the vanilla Minecraft which allows you to teleport around the world. Now, you might get confused since you see square brackets ([]) and angle brackets (<>), those are the arguments. Any developer can implement their syntax just the way they want so don't base the following information on all plugins, though I (SupaHam) tend to make mine similar to how Minecraft and many Bukkit plugins do theirs. So with the tp command the square brackets are optional and the angle brackets are required. Usually between these brackets are a descriptive one/two words.

So, the tp command has the [target player] and the <destination player> argument for one of the usages. If you understood well then you should know that the [target player] is not required but the <destination player> is.

Example:
A. SupaHam executes /tp Steve

Minecraft then takes that 'Steve' argument and checks if it's valid
Case: Steve is online

  • Minecraft checks if Steve is online on the same server as SupaHam. If Steve is online, SupaHam will get teleported to him.

Case: Steve is offline

  • Minecraft outputs an error to the command sender saying 'Steve' is not a valid player.

B. SupaHam executes /tp Steve SupaHam

Notice the difference between command A and command B? Command B is making use of the optional argument ([target player]).

Minecraft then takes both 'Steve' and 'SupaHam' and check if they are both valid players, as shown with the cases above. If they are both valid Minecraft then teleports 'Steve' to 'SupaHam'.

Flags

A command flag is a hyphen (-) followed by a letter, these are optional. Command flags are pretty much options. Flags are not used with vanilla commands or many of the Bukkit plugins, though I make use of it when I feel it is necessary.

Example: WorldEdit's brush cylinder command syntax
/brush cyl [-h] <block> [radius] [height]
In this example, the command creates a cylinder brush out of the item in your hand with a block, but if you look closely at the optional arguments, you will see there is one that starts with a hyphen, that is a flag. In this case the h flag makes your brush create hollow cylinders.

As a developer, you might think "Wow, why waste so much time implementing such a complex system for my plugins?!", well here's some good news, there are frameworks already written for you to use! I personally prefer to use WorldEdit's command framework which can be found here, though this requires your plugin to depend on WorldEdit, while most Minecraft servers use WorldEdit it's still not very nice to force your users to install something they don't want to install, but... there is a fork of WorldEdit's command framework by the Overcast Network which can be found here. Unlike WorldEdit's version, you can easily shade this fork into your plugin, meaning you save up a lot of space and don't have to force your users to install WorldEdit.