Register your own command
The API provides a way to register your own commands. This can be done by using the SuperiorSkyblockAPI.registerCommand(<SuperiorCommand>) method.
In this tutorial, I will add a new command: /is near. It will return which islands are nearby, and in which direction.
First of all, I will create my custom SuperiorCommand class:
public final class NearCommand implements SuperiorCommand {
@Override
public List<String> getAliases() {
// A list of aliases. The first argument will be the label of the subcommand.
return Arrays.asList("near", "nearby");
}
@Override
public String getPermission() {
// The required permission for the command. If you don't want a specific permission, use "".
return "";
}
@Override
public String getUsage(Locale locale) {
// The usage of the command. Should only include the label & arguments of the command.
return "near";
}
@Override
public String getDescription(Locale locale) {
// The description of the command, which will be shown in /is help.
return "Locate nearby islands.";
}
@Override
public int getMinArgs() {
// Minimum arguments for the command, including the label.
return 1;
}
@Override
public int getMaxArgs() {
// Maximum arguments for the command, including the label.
return 1;
}
@Override
public boolean canBeExecutedByConsole() {
// Whether or not the command can be executed from Console.
return false;
}
@Override
public boolean displayCommand() {
// Whether or not the command would be displayed in the /is help list.
return true;
}
@Override
public void execute(SuperiorSkyblock plugin, CommandSender sender, String[] args) {
// TODO
}
@Override
public List<String> tabComplete(SuperiorSkyblock plugin, CommandSender sender, String[] args) {
// TODO
return new ArrayList<>();
}
}That's it. The only thing that is left is to execute your code under the execute code, and implement the tab-complete.
The execute() and tabComplete() methods contain 3 parameters:
plugin: The instance of the plugin.
sender: The command sender.
args: The arguments from the sender.
After filling my code, the final version of the command is the following:
The last thing to do is to call SuperiorSkyblockAPI.registerCommand(<SuperiorCommand>), and that's it! You registered your own command! This command will be supported in all tab completes, /is help and argument restrictions! You can also register the commands without calling the method above. You can extract the class into an external jar, and put it in the commands folder of SuperiorSkyblock2.
Last updated
Was this helpful?