Command System

View the Command System for CIYFLib.

We've created an easy yet advanced command system for both main and sub commands. In order to use the system you'll first need a base - we'll guide you on this below.

1. Registering a base.

In order to do this, we will need to create our CommandManager object, this takes an array of classes first (for your sub-commands), followed by your main command name and then your plugins instance.

CommandManager commandManager = new CommandManager(Arrays.asList(ASubCommand.class), "maincommand", this);

2. Setting your main command.

Once your base is created, you can set your main command like so - using your main command's class as the parameter.

commandManager.setMainCommand(YourMainCommand.class);

3. Configuring your command messages.

Finally, you can configure your locale like so, this could also take your configuration values here.

CommandManager.getLocale().setNoPermission("&cYou cannot do that..");
CommandManager.getLocale().setUnknownCommand("&7Unknown, try /guitest help.");
CommandManager.getLocale().setUsage("&7Please use &b{usage}&7.");
CommandManager.getLocale().setPlayerOnly("&cConsole isn't currently supported.");

4. Configuring your main command class.

When creating your commands, you can either use CommandSender meaning both console and players can use the command, otherwise specifying Player will make it a player-only command.

public class YourMainCommand {
    @Command(permission = "cialib.maincmd")
    public static void execute(final CommandSender sender, final YourPlugin plugin, final String[] args) {
        // Your code here.
    }
}

5. Configuring your sub command class.

Here you can provide your commands usage, various aliases and how many args are required (triggers your usage locale if not enough are specified).

public class ASubCommand {
    @Command(permission = "cialib.sub", usage = "say", aliases = {"say"}, requiredArgs = 1)
    public static void execute(final CommandSender sender, final CIAPlugin plugin, final String[] args) {
        String message = args[0];
        Bukkit.getServer().broadcastMessage(StringUtil.translate("&c[Broadcast] &7" + message));
    }
}

Last updated