Package arc.util

Class CommandHandler

java.lang.Object
arc.util.CommandHandler

public class CommandHandler extends Object
Parses command syntax.
  • Field Details

    • prefix

      public String prefix
  • Constructor Details

    • CommandHandler

      public CommandHandler(String prefix)
      Creates a command handler with a specific command prefix.
  • Method Details

    • setPrefix

      public void setPrefix(String prefix)
    • getPrefix

      public String getPrefix()
    • handleMessage

      public CommandHandler.CommandResponse handleMessage(String message)
      Handles a message with no additional parameters.
    • handleMessage

      public CommandHandler.CommandResponse handleMessage(String message, Object params)
      Handles a message with optional extra parameters. Runs the command if successful.
      Returns:
      a response detailing whether or not the command was handled, and what went wrong, if applicable.
    • removeCommand

      public void removeCommand(String text)
    • register

      public <T> CommandHandler.Command register(String text, String description, CommandHandler.CommandRunner<T> runner)
      Register a command which handles a zero-sized list of arguments and one parameter.
    • register

      public <T> CommandHandler.Command register(String text, String params, String description, CommandHandler.CommandRunner<T> runner)
      Register a command which handles a list of arguments and one handler-specific parameter.
      argeter syntax is as follows:
      <mandatory-arg-1> <mandatory-arg-2> ... <mandatory-arg-n> [optional-arg-1] [optional-arg-2]
      Angle brackets indicate mandatory arguments. Square brackets to indicate optional arguments.
      All mandatory arguments must come before optional arguments. Arg names must not have spaces in them.
      You may also use the ... syntax after the arg name to designate that everything after it will not be split into extra arguments. There may only be one such argument, and it must be at the end. For example, the syntax <arg1&gt [arg2...] will require a first argument, and then take any text after that and put it in the second argument, optionally.
    • register

      public CommandHandler.Command register(String text, String description, Cons<String[]> runner)
    • register

      public CommandHandler.Command register(String text, String params, String description, Cons<String[]> runner)
    • getCommandList

      public Seq<CommandHandler.Command> getCommandList()