Skip to content

Annotation Commands

Dawson edited this page Feb 24, 2019 · 1 revision

Creating your First Annotation Command

Our command API provides many features for plugin developers to use. Here's how you can create these commands and use them in the real world.

What your main class should look like.

package cc.funkemunky.example;

import cc.funkemunky.api.Atlas;
import org.bukkit.plugin.java.JavaPlugin;

public class Example extends JavaPlugin {

    public void onEnable() {
        Atlas.getInstance().initializeScanner(getClass(), this, Atlas.getInstance().getCommandManager());
    }
}

Options

Name Description Usage
name() The name of command. @Command(name = "commandName")
display() The string displayed in a help page. @Command(display = "commandDisplay")
playerOnly() Declares command to be used by players only. @Command(playerOnly = true)
consoleOnly() Declares command to be used by console only. @Command(consoleOnly = true)
permission() The permission(s) required to use command. @Command(permission = {"perm1", "perm2"})
tabCompletions() Other arguments that can be tabbed in chat. @Command(tabCompletions = {"..tabMeThird", "tabMeFirst"})
description() The description of command. @Command(description = "This command can do that.")
usage() How to use command. @Command(usage = "/label <arg1> [arg2]")
noPermissionMessage() Custom no permission message. @Command(noPermissionMessage = "&c&lNo go bro.")
aliases() Other ways to run command. @Command(aliases = {"second.way", "thirdway"})

Initial Command Example

package cc.funkemunky.example.commands;

import cc.funkemunky.api.Atlas;
import cc.funkemunky.api.commands.ancmd.Command;
import cc.funkemunky.api.commands.ancmd.CommandAdapter;
import cc.funkemunky.api.utils.Init;

@Init(commands = true) //This is needed to signify to the class scanner we implemented in the main class that there are commands to register here.
public class ExampleCommand {

    //Runs the help message for the main commmand "/command".
    @Command(name = "command", description = "An example command.", permission = "cmd.perm", aliases = "aCommand")
    public void onCommand(CommandAdapter command) {
        Atlas.getInstance().getCommandManager().runHelpMessage(command, command.getSender(), Atlas.getInstance().getCommandManager().getDefaultScheme());
    }
}
  • You would need the permission command.permission to run this command.
  • You could run this command doing /command or /acommand.

Making a command with arguments.

package cc.funkemunky.example.commands;

import cc.funkemunky.api.Atlas;
import cc.funkemunky.api.commands.ancmd.Command;
import cc.funkemunky.api.commands.ancmd.CommandAdapter;
import cc.funkemunky.api.utils.Init;

@Init(commands = true) //This is needed to signify to the class scanner we implemented in the main class that there are commands to register here.
public class ExampleCommand {

    //Runs the help message for the main commmand "/command".
    @Command(name = "command", description = "An example command.", permission = "cmd.perm", aliases = "aCommand")
    public void onCommand(CommandAdapter command) {
        Atlas.getInstance().getCommandManager().runHelpMessage(command, command.getSender(), Atlas.getInstance().getCommandManager().getDefaultScheme());
    }

    //One of the arguments for "/command". Run as "/command arg1".
    @Command(name = "command.arg1", permission = "cmd.perm.arg1", description = "An argument of example command.")
    public void onCommandArg(CommandAdapter command) {
        command.getSender().sendMessage("You can an argument of the example command.");
    }
}

Example Help Message