All Downloads are FREE. Search and download functionalities are using the official Maven repository.

simple.client.action.HelpAction Maven / Gradle / Ivy

The newest version!
package simple.client.action;

import simple.client.SimpleUI;
import simple.common.NotificationType;

/**
 *
 * @author Javier A. Ortiz Bultron 
 */
public abstract class HelpAction implements SlashAction {

    private ActionRepository repo;
    private String[] lines;
    private SimpleUI ui;

    /**
     * Help action class
     * @param repo Repository containing the actions handled by this class
     * @param lines Additional lines of text to be displayed before the actual usage.
     *        Usually for usage with no parameters.
     * @param ui
     */
    public HelpAction(ActionRepository repo, String[] lines, SimpleUI ui) {
        this.repo = repo;
        this.lines = lines;
        this.ui = ui;
    }

    /**
     * Execute a chat command.
     * 
     * @param params
     *            The formal parameters.
     * @param remainder
     *            Line content after parameters.
     * 
     * @return true if was handled.
     */
    @SuppressWarnings("static-access")
    public boolean execute(String[] params, String remainder) {
        String command = params[1];
        boolean detailed = false;
        if (params.length == 3) {
            detailed = params[2].equals("-d");
        } else if (params.length == 2) {
            detailed = params[1].equals("-d");
        }
        if (lines != null && params.length == 1) {
            for (String line : lines) {
                ui.get().addEventLine(line, NotificationType.CLIENT);
            }
            repo.getHelpMessages(detailed);
        } else {
            repo.getHelp(command, detailed);
        }
        return true;
    }

    /**
     * Get the maximum number of formal parameters.
     *
     * @return The parameter count.
     */
    public int getMaximumParameters() {
        // /help 
        return 2;
    }

    /**
     * Get the minimum number of formal parameters.
     *
     * @return The parameter count.
     */
    public int getMinimumParameters() {
        //In case they just type /help
        return 1;
    }

    /**
     * Show usage for this command.
     *
     */
    @SuppressWarnings("static-access")
    public void usage(boolean detailed) {
        ui.get().addEventLine("- /help  -d" +
                (detailed ? "\t\tGet detailed help for the named command." : "") +
                "- /help " +
                (detailed ? "\t\tGet non-detailed help for the named command." : ""),
                NotificationType.CLIENT);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy