Consoled is a CraftBukkit plugin which makes adding commands easy.
- Import the jar archive.
- Write [
commands.yml
] and embed it. - Write your own command executors.
- Register your command executors.
You can specify usages, permissions for commands.
All properties are optional.
Property | Description |
---|---|
_usage |
Displayed when the command fails. (executor returns false) Can inherit from the parent. |
_perm |
Represents the permission required to execute the command. |
_permMessage |
Displayed when the command fails due to the lack of permission. Can inherit from the parent. |
Others | Other properties are regarded as subcommands. |
foo:
_usage: /foo [bar/baz]
_permMessage: "&cYou don't have enough permission."
bar:
_usage: /foo bar [number]
_perm: foo.bar
baz:
_usage: /foo baz <name>
_perm: foo.baz
Annotation @CommandFor(command)
can be used to delegate execution of the command to the method. For subcommands use .
.
Attached methods should return boolean
(true
for success, false
for failure) and receive CommandContext
as the first argument.
Annotation @Optional
can be used to mark the parameter as an optional argument. It should not be primitive.
public class ExampleExecutor {
@CommandFor("foo.bar")
public boolean executeBar(CommandContext ctx, int number) {
// omitted
}
@CommandFor("foo.baz")
public boolean executeBaz(CommandContext ctx, @Optional String name) {
// omitted
}
}
Consoled uses Services API to provide its functions.
Following code gets a CommandService
instance to register commands to.
var registration = Bukkit.getServiceManager().getRegistration(CommandService.class);
CommandService service = registration.getProvider();
Then you can register all commands in your plugin.yml
and executors with:
ExamplePlugin plugin;
ExampleExecutor executor;
service.register(plugin);
service.registerExecutor(plugin, executor);
gradlew jar
./gradlew jar
You can find consoled-version.jar
in build/libs
.
Consoled welcomes all contributions! Feel free to contribute with PRs after enough tests done.