Class CommandFactory
Object
CommandFactory
The factory that creates commands based on the string entered by the user.
- Author:
- maartenl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
The definition of a user command. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addUserCommand
(int aCommandId, String aCommand, String aMethodName, Long aRoom) Add a user command to the structure.static void
Clears the map containing all user-defined commands.static NormalCommand
static NormalCommand
static List
<NormalCommand> getCommand
(String aCommand) Returns the commands to be used, based on the first word in the command entered by the user.static List
<CommandFactory.UserCommandInfo> getUserCommands
(User user, String aCommand, BiConsumer<String, Throwable> errorConsumer) Returns all matching user commands.static boolean
Returns if the map of user commands is empty.
-
Constructor Details
-
CommandFactory
public CommandFactory()
-
-
Method Details
-
getBogusCommand
-
getAdminCommand
-
getCommand
Returns the commands to be used, based on the first word in the command entered by the user.- Parameters:
aCommand
- String containing the command entered by the user.- Returns:
- List containing the commands that fit the description. The
commands that are contained are in the following order:
- special commands retrieved from the database
- normal commands
- bogus command (the ultimate failover, "I don't understand that.".)
All commands are newly created.
-
getUserCommands
public static List<CommandFactory.UserCommandInfo> getUserCommands(User user, String aCommand, BiConsumer<String, Throwable> errorConsumer) Returns all matching user commands.
There are a few requirements
- commands must match
- either the user defined command is valid for all rooms OR
- room defined in the user defined commands euqals the room the user is in
- Parameters:
user
- the user, used to get the room.aCommand
- the string containing the command issued by the user- Returns:
- a list of possibly valid user defined commands.
-
noUserCommands
public static boolean noUserCommands()Returns if the map of user commands is empty.- Returns:
- true if usercommands is empty.
-
clearUserCommandStructure
public static void clearUserCommandStructure()Clears the map containing all user-defined commands. It will be reloaded automatically from the database, upon executing the first command. -
addUserCommand
Add a user command to the structure.- Parameters:
aCommandId
- the id of the commandaCommand
- the commandaMethodName
- the method nameaRoom
- the room, optional, may be null in which case the command is valid for all rooms.
-