Lambda commands work very similar to how Lambda Event Listeners work. You must also call these in your plugin’s onEnable() method.
/* Calling /testcommand sends a message to the person who runs the command. */
Catalyst.commands()
.on("testcommand")
.perform(c -> c.getPlayer().sendMessage("This is a test debug command"));
You don’t have to mess with plugin.yml because your lambda commands get registered automatically.
You can also get the arguments of the command easily,
/* Calling /testcommand sends a message
to the person who runs the command, and if
the person typed anything after the command,
it will be stored in c.args */
Catalyst.commands()
.on("testcommand")
.perform(c -> {
if(c.args.length == 0) {
c.getPlayer().sendMessage("You ran /testcommand");
}
if(c.args.length == 1) {
c.getPlayer().sendMessage("You ran /testcommand with the first argument: " + c.args[0]);
}
});
You can easily check if the command was run by a real player.
Catalyst.commands()
.on("whoami")
.perform(c -> {
if(c.getPlayer() == null) {
c.getSender().sendMessage("You're the console :D");
} else {
c.getPlayer().sendMessage("You're a player :P");
}
});
Auto-completion is also supported by our lambda command framework.
Catalyst.commands()
.on("mycommand")
.perform(c -> {
c.getPlayer().sendMessage("You've just run the MyCommand!");
})
.autoComplete(c -> {
List<String> suggestions = new ArrayList<>();
suggestions.add("Option_1");
suggestions.add("Option_2");
return suggestions;
});