Class CommandManager

java.lang.Object
de.gurkenlabs.litiengine.util.CommandManager
All Implemented Interfaces:
ILaunchable

public class CommandManager extends Object implements ILaunchable
Manages the binding and execution of commands. Implements the ILaunchable interface to provide start and terminate functionality.
  • Constructor Details

    • CommandManager

      public CommandManager()
      Constructs a new CommandManager. Initializes the commandConsumers map and the commandListener.
  • Method Details

    • bind

      public void bind(String command, Predicate<String[]> commandConsumer)
      Binds a command to a specific consumer. If the command is already bound, an IllegalArgumentException is thrown.
      Parameters:
      command - the command to bind
      commandConsumer - the consumer to bind to the command
      Throws:
      IllegalArgumentException - if the command is already bound
    • executeCommand

      public boolean executeCommand(String command)
      Executes a command by finding the corresponding consumer and passing the command arguments to it. If the command is null, empty, or not bound to any consumer, it returns false.
      Parameters:
      command - the command to execute
      Returns:
      true if the command was successfully executed, false otherwise
    • start

      public void start()
      Description copied from interface: ILaunchable
      Starts the operation of this instance.
      Specified by:
      start in interface ILaunchable
    • terminate

      public void terminate()
      Description copied from interface: ILaunchable
      Terminates the operation of this instance.
      Specified by:
      terminate in interface ILaunchable