Class CommandParser

java.lang.Object
com.adventure.commands.CommandParser

public class CommandParser extends Object
Class responsible for parsing and instantiating commands.
  • Method Details

    • getInstance

      public static CommandParser getInstance()
      Returns CommandParser instance.
      Returns:
      CommandParser instance.
    • parseCommand

      public Command parseCommand(String command)
      Parses a command.
      Parameters:
      command - Command to parse.
      Returns:
      The instance of the correct command, null otherwise.
    • registerCommand

      public void registerCommand(String key, Class<? extends Command> commandClass)
      Registers a new command.
      Parameters:
      key - Command name. If a command with the same name is already registered, then is replaced.
      commandClass - Command class used to instantiate the concrete object.
    • registerCommand

      public void registerCommand(String key, Class<? extends Command> commandClass, String description)
      Registers a new command.
      Parameters:
      key - Command name. If a command with the same name is already registered, then is replaced.
      commandClass - Command class used to instantiate the concrete object.
      description - Command description.
    • argsFromCommand

      public List<String> argsFromCommand(String key)
      It gives a list of all the possible arguments for a command given its name
      Parameters:
      key - String name of the command
      Returns:
      ArrayList of Strings with all the possible arguments for this command
    • unregisterCommand

      public Class<? extends Command> unregisterCommand(String key)
      Unregisters a command.
      Parameters:
      key - Command name to unregister.
      Returns:
      The unregistered command class if the command had been previously registered, null otherwise.
    • setContext

      public void setContext(ApplicationContext context)
      Sets the active context. This context will be injected inside commands.
      Parameters:
      context - Active context.
    • enableAll

      public void enableAll()
      Enables all commands.
    • enableAll

      public void enableAll(List<String> commands)
      Enables all commands in the list.
    • disableAll

      public List<String> disableAll()
      Disables all commands.
      Returns:
      The commands that were enabled.
    • enable

      public void enable(String key)
      Enables command.
      Parameters:
      key - Command to enable.
    • disable

      public void disable(String key)
      Disable command.
      Parameters:
      key - Command to disable.
    • getContext

      public ApplicationContext getContext()
      Obtains current context.
      Returns:
      Current context.
    • getCommands

      public List<String> getCommands()
      Returns available commands.
      Returns:
      Command keys list.
    • getCommandMetadata

      public CommandMetadata getCommandMetadata(String key)
      Returns command description.
      Parameters:
      key - Command name.
      Returns:
      Command description.