Skip to content

Using Annotation Commands

Dawson edited this page May 29, 2019 · 2 revisions

Using annotations can be a much cleaner and efficient experience for developers working on large scale projects. This is a documentation on how to use Atlas's implementation.

Usage of Parameters

Parameters Example Arguments Usage
name() label.argument What the scanner will translate into the form it needs to be for players to run your commands. You can use periods (".") to indicate another argument or SPACE (" ") is required to run the command.
display() /label argument What will be displayed when CommandManager#runHelpMessage() method is called as a representation of how to use the command.
description() This is an example. What will be displayed when CommandManager#runHelpMessage() method is called to describe the use of the command.
usage() / argument The same thing as using the usage parameter in a plugin.yml. It is for Bukkit to parse the command for itself.
noPermissionMessage() &cNo permission. The message that is sent to the player when he/she does not have permission to the command. The example is the default message. You can also use '&' to represent the UTF color code character Minecraft uses.
playerOnly() true Set whether or not a command must be executed by a player or not.
consoleOnly() false Set whether or not a command must be executed by console or not.
permission() {"perm.one". "perm.two"} or just "perm.alone" Set the permission(s) required to execute this command.
tabCompletions() "label.argument" Define the tab completion values for easier execution of long commands.
aliases() {"label.alias", "alias"} or just {"alias"} Set different syntax definitions for the same command.

Example

Here I create a complete which can teleport players to myself as a player.

 @Command(name = "teleporthere", description = "Teleport a player to yourself", playerOnly = true, usage = "/<command> <player>", aliases = "tphere", permission = "command.teleport")
    public void onTpHereCommand(CommandAdapter command) {
        Player player = command.getPlayer();

        if(command.getArgs().length > 0) {
            Player target = Bukkit.getPlayer(command.getArgs()[0]);

            if(target != null) {
                target.teleport(player);
                target.sendMessage(Color.translate("&7You have been teleported to &f" + player.getName() + "&7."));
                player.sendMessage(Color.translate("&7You have teleported &f" + target.getName() + "&7to yourself."));
            } else player.sendMessage(Color.Red + "The player \"" + command.getArgs()[0] + "\" is not online or does not exist.");
        }
    }