Class BaseImperat<S extends Source>

java.lang.Object
studio.mevera.imperat.BaseImperat<S>
All Implemented Interfaces:
AnnotationInjector<S>, CommandRegistrar<S>, Imperat<S>, SourceWrapper<S>

public abstract class BaseImperat<S extends Source> extends Object implements Imperat<S>
  • Field Details

  • Constructor Details

    • BaseImperat

      protected BaseImperat(@NotNull @NotNull ImperatConfig<S> config)
  • Method Details

    • config

      @NotNull public @NotNull ImperatConfig<S> config()
      The config for imperat
      Specified by:
      config in interface Imperat<S extends Source>
      Returns:
      the config holding all variables.
    • canBeSender

      public boolean canBeSender(Type type)
      Checks whether the valueType can be a command sender
      Specified by:
      canBeSender in interface SourceWrapper<S extends Source>
      Parameters:
      type - the valueType
      Returns:
      whether the valueType can be a command sender
    • registerCommand

      public void registerCommand(Command<S> command)
      Registering a command into the dispatcher
      Specified by:
      registerCommand in interface CommandRegistrar<S extends Source>
      Parameters:
      command - the command to register
    • registerCommand

      public void registerCommand(Class<?> commandClass)
      Registers a command class built by the annotations using a parser
      Specified by:
      registerCommand in interface CommandRegistrar<S extends Source>
      Parameters:
      commandClass - the annotated command instance to parse
    • registerCommand

      public void registerCommand(Object commandInstance)
      Description copied from interface: CommandRegistrar
      Registers a command instance built by the annotations using a parser
      Specified by:
      registerCommand in interface CommandRegistrar<S extends Source>
      Parameters:
      commandInstance - the annotated command instance to parse
    • unregisterCommand

      public void unregisterCommand(String name)
      Unregisters a command from the internal registry
      Specified by:
      unregisterCommand in interface CommandRegistrar<S extends Source>
      Parameters:
      name - the name of the command to unregister
    • unregisterAllCommands

      public void unregisterAllCommands()
      Unregisters all commands from the internal registry
      Specified by:
      unregisterAllCommands in interface CommandRegistrar<S extends Source>
    • getCommand

      @Nullable public @Nullable Command<S> getCommand(String name)
      Specified by:
      getCommand in interface CommandRegistrar<S extends Source>
      Parameters:
      name - the name/alias of the command
      Returns:
      fetches Command with specific name/alias
    • setAnnotationParser

      public void setAnnotationParser(AnnotationParser<S> parser)
      Changes the instance of AnnotationParser
      Specified by:
      setAnnotationParser in interface AnnotationInjector<S extends Source>
      Parameters:
      parser - the parser
    • registerAnnotations

      @SafeVarargs public final void registerAnnotations(Class<? extends Annotation>... type)
      Registers a valueType of annotations so that it can be detected by AnnotationReader , it's useful as it allows that valueType of annotation to be recognized as a true Imperat-related annotation to be used in something like checking if a CommandParameter is annotated and checks for the annotations it has.
      Specified by:
      registerAnnotations in interface AnnotationInjector<S extends Source>
      Parameters:
      type - the valueType of annotation
    • registerAnnotationReplacer

      public <A extends Annotation> void registerAnnotationReplacer(Class<A> type, AnnotationReplacer<A> replacer)
      Specified by:
      registerAnnotationReplacer in interface AnnotationInjector<S extends Source>
      Type Parameters:
      A - the valueType of annotation to replace
      Parameters:
      type - the valueType to replace the annotation by
      replacer - the replacer
    • getSubCommand

      @Nullable public @Nullable Command<S> getSubCommand(String owningCommand, String name)
      Specified by:
      getSubCommand in interface CommandRegistrar<S extends Source>
      Parameters:
      owningCommand - the command owning this sub-command
      name - the name of the subcommand you're looking for
      Returns:
      the subcommand of a command
    • executeUsage

      protected ExecutionResult<S> executeUsage(Command<S> command, S source, Context<S> context, CommandUsage<S> usage, CommandPathSearch<S> dispatch) throws ImperatException
      Throws:
      ImperatException
    • execute

      @NotNull public @NotNull ExecutionResult<S> execute(@NotNull @NotNull Context<S> context)
      Description copied from interface: Imperat
      Dispatches and executes a command using Context only
      Specified by:
      execute in interface Imperat<S extends Source>
      Parameters:
      context - the context
      Returns:
      the usage match setResult
    • execute

      @NotNull public @NotNull ExecutionResult<S> execute(@NotNull S source, @NotNull @NotNull Command<S> command, @NotNull @NotNull String commandName, String[] rawInput)
      Description copied from interface: Imperat
      Dispatches and executes a command with certain raw arguments using Command
      Specified by:
      execute in interface Imperat<S extends Source>
      Parameters:
      source - the sender/executor of this command
      command - the command object to execute
      rawInput - the command's args input
      Returns:
      the usage match setResult
    • execute

      @NotNull public @NotNull ExecutionResult<S> execute(@NotNull S source, @NotNull @NotNull String commandName, String[] rawInput)
      Description copied from interface: Imperat
      Dispatches and executes a command with certain raw arguments
      Specified by:
      execute in interface Imperat<S extends Source>
      Parameters:
      source - the sender/executor of this command
      commandName - the name of the command to execute
      rawInput - the command's args input
      Returns:
      the usage match setResult
    • execute

      @NotNull public @NotNull ExecutionResult<S> execute(@NotNull S sender, @NotNull @NotNull String commandName, @NotNull @NotNull String rawArgsOneLine)
      Description copied from interface: Imperat
      Dispatches and executes a command with certain raw arguments
      Specified by:
      execute in interface Imperat<S extends Source>
      Parameters:
      sender - the sender/executor of this command
      commandName - the name of the command to execute
      rawArgsOneLine - the command's args input on ONE LINE
      Returns:
      the usage match setResult
    • execute

      @NotNull public @NotNull ExecutionResult<S> execute(@NotNull S sender, @NotNull @NotNull String line)
      Description copied from interface: Imperat
      Dispatches the full command-line
      Specified by:
      execute in interface Imperat<S extends Source>
      Parameters:
      sender - the source/sender of the command
      line - the command line to dispatch
      Returns:
      the usage match setResult
    • autoComplete

      public CompletableFuture<List<String>> autoComplete(@NotNull S source, @NotNull @NotNull String fullCommandLine)
      Specified by:
      autoComplete in interface Imperat<S extends Source>
      Parameters:
      source - the sender writing the command
      fullCommandLine - the full command line
      Returns:
      the suggestions at the current position
    • getRegisteredCommands

      public Collection<? extends Command<S>> getRegisteredCommands()
      Gets all registered commands
      Specified by:
      getRegisteredCommands in interface CommandRegistrar<S extends Source>
      Returns:
      the registered commands
    • getAnnotationParser

      @NotNull public @NotNull AnnotationParser<S> getAnnotationParser()
      Description copied from interface: AnnotationInjector
      Fetches the annotation parser
      Specified by:
      getAnnotationParser in interface AnnotationInjector<S extends Source>
      Returns:
      the annotation parser instance.
      See Also:
    • debug

      public void debug(boolean treeVisualizing)
      Description copied from interface: Imperat
      Debugs all registered commands and their usages.
      Specified by:
      debug in interface Imperat<S extends Source>
      Parameters:
      treeVisualizing - whether to display them in the form of tree