Improving our greet command
In this page, we will make our greet more customizable and robust.
Last updated
Was this helpful?
In this page, we will make our greet more customizable and robust.
Last updated
Was this helpful?
Right now, our /greet command does not do much. Also, it has the following problems:
The command has no description that appears in /help
The command is executable by everyone
The welcome message is not customized
Also, we would like to make the command work with no arguments. If a target was not specified, we want to default to the command sender.
This can be easily set using the @Description
annotation
That's it! We can see the description appear in /help:
Setting a permission is equivalently simple. It can be set using the @CommandPermission
annotation, which is functionally equal to Bukkit's Permission
class.
It takes two parameters: value
, which is the permission node, and defaultAccess
, which defines who can access the command by default. This is set to PermissionDefault.OP
, and can be changed explicitly.
That's it! Now, only people with the test.plugin.greet
permission can use the command.
We would like to make our target
argument optional. If it is not specified, it should default to the sender.
This can be done using the @Default
annotation, which specifies a default value for the parameter.
Because this is very common in plugins (default Player
s to the sender), Lamp accepts special values for the Player
type: me
, @s
and self
. If these are supplied to a Player parameter, it will receive the sender as a value.
🎉 Good news, Kotlin users!
Lamp supports Kotlin's default arguments. You can use Kotlin's natural syntax for specifying the default parameters. The only caveat is that you need to explicitly mark these parameters with the
@Optional
annotation:
Seeing it in action: