java.lang.Object
com.adventure.commands.CommandParser
Class responsible for parsing and instantiating commands.
-
Method Summary
Modifier and TypeMethodDescriptionargsFromCommand
(String key) It gives a list of all the possible arguments for a command given its namevoid
Disable command.Disables all commands.void
Enables command.void
Enables all commands.void
Enables all commands in the list.getCommandMetadata
(String key) Returns command description.Returns available commands.Obtains current context.static CommandParser
Returns CommandParser instance.parseCommand
(String command) Parses a command.void
registerCommand
(String key, Class<? extends Command> commandClass) Registers a new command.void
registerCommand
(String key, Class<? extends Command> commandClass, String description) Registers a new command.void
setContext
(ApplicationContext context) Sets the active context.unregisterCommand
(String key) Unregisters a command.
-
Method Details
-
getInstance
Returns CommandParser instance.- Returns:
- CommandParser instance.
-
parseCommand
Parses a command.- Parameters:
command
- Command to parse.- Returns:
- The instance of the correct command, null otherwise.
-
registerCommand
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
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
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
Unregisters a command.- Parameters:
key
- Command name to unregister.- Returns:
- The unregistered command class if the command had been previously registered, null otherwise.
-
setContext
Sets the active context. This context will be injected inside commands.- Parameters:
context
- Active context.
-
enableAll
public void enableAll()Enables all commands. -
enableAll
Enables all commands in the list. -
disableAll
Disables all commands.- Returns:
- The commands that were enabled.
-
enable
Enables command.- Parameters:
key
- Command to enable.
-
disable
Disable command.- Parameters:
key
- Command to disable.
-
getContext
Obtains current context.- Returns:
- Current context.
-
getCommands
Returns available commands.- Returns:
- Command keys list.
-
getCommandMetadata
Returns command description.- Parameters:
key
- Command name.- Returns:
- Command description.
-