Skip to content

Command Framework

NJDaeger edited this page Jul 5, 2018 · 2 revisions

Overview

The provided Command Framework is a complex system designed around the builder pattern. The framework can be extended using the various classes that make up the base framework. The system uses generics to allow altering the inputs and outputs of various methods, which also allows us to create custom methods in things such as the command builder class. In addition to the extensibility, we also tie the framework with i18n capabilities and methods to quickly send messages in the desired language.

The CommandContext

The CommandContext class is the base argument of any command method. It in itself is an abstract class which is to be extended for custom use. You do not have to extend this class to make use of it, though. We have provided default extensions for all the command classes. The DefaultCContext is the default command context class for general use in other plugins. It doesn't add any additional features to the standard CommandContext.

The TabContext

The TabContext class is the base argument of any tab completion method. It is also an abstract class which is to be extended for custom use. Like the CommandContext, we have also provided a default extension for regular use. The DefaultTContext is the default tab context class for general use in other plugins.

Example usage of both the TabContext and the CommandContext default extensions

package com.example;

import com.example.ExamplePlugin;
import com.coalesce.core.command.defaults.DefaultCContext;

public class ExampleCommand {
    
    private final ExamplePlugin plugin;

    public ExampleCommand(ExamplePlugin plugin) {
        this.plugin = plugin;

        //Commands are registered here. (Process will be shown in a later example)

    }

    private void exampleCommand(DefaultCContext context) {
        if (context.isLength(1)) {
            context.send("Hello, " + context.argAt(0) + "!");
        } else context.send("Hello!");
    }

    private void exampleCompletion(DefaultTContext context) {
        context.playerCompletion(0);
    }

}

Clone this wiki locally