Interface CommandProvider


public interface CommandProvider
The CommandProvider allows access to the command execution and handling of a node. All node commands must be registered here in order to use them in the console or using the api, see execute(CommandSource, String).

Commands are registered on a per-class basis therefore every class should only contain one root command. With this one "root command" is meant that all commands in one class must start with a prefix that all have in common. The reason for this is that there is no other way to properly parse and register the commands than this one.

Note: Commands that have a requiredSender in their Command annotation set are only executable using the console or the api.

Since:
4.0
See Also:
  • Command
  • CommandInfo
  • Method Details

    • suggest

      Resolves the next correct command suggestions that would result in a successful command execution, while only suggesting commands that the source is allowed to execute.
      Parameters:
      source - the commandSource for the suggestions. Mostly for permission checks.
      input - the command chain that suggestions are needed for.
      Returns:
      the suggestions for the current command chain.
      Throws:
      NullPointerException - if separator or input is null.
    • execute

      Executes a command with the given command source and sends all responses to the given source.

      Note: The command is executed asynchronously in a cached thread pool. If synchronous execution is necessary, then you should consider blocking for the command execution.

      Parameters:
      source - the command source that is used to execute the command.
      input - the commandline that is executed.
      Returns:
      a task wrapping the command execution.
      Throws:
      NullPointerException - if source or input is null.
    • register

      void register(@NonNull @NonNull Class<?> commandClass)
      Registers a command on a per-class basis. All methods annotated with Command are parsed into a command and only one common CommandInfo.

      This method takes a class instead of an instance and creates the instance using our dependency injection framework. Make sure that the given class supports the instantiation using dependency injection.

      Parameters:
      commandClass - the class to instantiate and register the commands for afterwards.
      Throws:
      NullPointerException - if object is null.
    • register

      void register(@NonNull @NonNull Object command)
      Registers a command on a per-class basis. All methods annotated with Command are parsed into a command and only one common CommandInfo.
      Parameters:
      command - the instance of the class to register all commands for.
      Throws:
      NullPointerException - if object is null.
    • unregister

      void unregister(@NonNull @NonNull String name)
      Unregisters the command with the given name or alias.
      Parameters:
      name - the name or alias of the command to unregister.
      Throws:
      NullPointerException - if the given name is null.
    • unregister

      void unregister(@NonNull @NonNull ClassLoader classLoader)
      Unregisters every command that was registered by the given classloader.
      Parameters:
      classLoader - the classloader that was used to register the command.
      Throws:
      NullPointerException - if classLoader is null.
    • command

      @Nullable @Nullable eu.cloudnetservice.driver.command.CommandInfo command(@NonNull @NonNull String name)
      Looks for a registered command with the given root name or alias.
      Parameters:
      name - the command root name or an alias of the root
      Returns:
      the command with the given name - null if no command was found with the given name / alias
      Throws:
      NullPointerException - if name is null.
    • commands

      @NonNull @UnmodifiableView @NonNull Collection<eu.cloudnetservice.driver.command.CommandInfo> commands()
      Collects all previously registered commands that are registered in a node and returns them in an unmodifiable collection.
      Returns:
      all registered commands.