Class ConfigBuilder<S extends CommandSource,I extends Imperat<S>,B extends ConfigBuilder<S,I,B>>

java.lang.Object
studio.mevera.imperat.ConfigBuilder<S,I,B>
Type Parameters:
S - the source type representing the entity or origin of the command (e.g., a user or a system)
I - the implementation type that extends Imperat

public abstract class ConfigBuilder<S extends CommandSource,I extends Imperat<S>,B extends ConfigBuilder<S,I,B>> extends Object
A generic abstract builder class for configuring instances of ImperatConfig and creating implementations of the Imperat interface. The builder pattern is utilized to allow fine-grained configuration of various components needed within the command processing system.
  • Field Details

  • Constructor Details

    • ConfigBuilder

      protected ConfigBuilder()
  • Method Details

    • eventBus

      public B eventBus(EventBus bus)
      Sets the event bus to be used for handling events within the configuration.
      Parameters:
      bus - the EventBus instance to be set in the configuration
      Returns:
      the current instance of ConfigBuilder for method chaining
    • commandPrefix

      public B commandPrefix(String cmdPrefix)
      Sets the command prefix for the command processing chain.
      Parameters:
      cmdPrefix - the prefix string to be used before root commands
      Returns:
      the updated instance of the ConfigBuilder to allow for method chaining
    • throwablePrinter

      public B throwablePrinter(ThrowablePrinter printer)
      Sets the ThrowablePrinter used to print unhandled exceptions.
      Parameters:
      printer - the printer to use
      Returns:
      the current builder instance for chaining
    • response

      public B response(Response response)
    • response

      public B response(ResponseKey key, Supplier<String> contentSupplier, String... placeholders)
    • globalCoordinator

      public B globalCoordinator(CommandCoordinator<S> commandCoordinator)
    • permissionChecker

      public B permissionChecker(PermissionChecker<S> permissionChecker)
      Sets a custom PermissionChecker to determine and resolve permissions for the command sender/source within the platform's configuration.
      Parameters:
      permissionChecker - the PermissionChecker implementation used to handle permission checks for commands
      Returns:
      the current ConfigBuilder instance for method chaining and further configuration
    • helpCoordinator

      public B helpCoordinator(HelpCoordinator<S> coordinator)
      Sets the HelpCoordinator that coordinates all the core-components of the new help API, to create a coordinator call HelpCoordinator.create()
      Parameters:
      coordinator - the coordinator
      Returns:
      the current instance of ConfigBuilder for method chaining
      Since:
      2.0.0
    • contextFactory

      public B contextFactory(ContextFactory<S> contextFactory)
      Sets the context factory for creating contexts used in command execution.
      Parameters:
      contextFactory - the context factory to be used for generating contexts
      Returns:
      the current instance of ConfigBuilder for method chaining
    • returnResolver

      public B returnResolver(Type type, ReturnResolver<S,?> returnResolver)
      Registers a ReturnResolver
      Parameters:
      type - the type of value to return using the return resolver
      returnResolver - the return resolving instance.
      Returns:
      the current ConfigBuilder instance for fluent chaining
    • dependencyResolver

      public B dependencyResolver(Type type, DependencySupplier resolver)
      Registers a dependency resolver for a specific type and returns the current ConfigBuilder instance.
      Parameters:
      type - the target type for which the dependency resolver is being registered
      resolver - the dependency resolver to associate with the specified type
      Returns:
      the current instance of ConfigBuilder for method chaining
    • annotationReplacer

      public <A extends Annotation> B annotationReplacer(Class<A> annotationType, AnnotationReplacer<A> replacer)
      Registers a custom annotation replacer for the specified annotation type. This allows for dynamic transformation or substitution of annotations during command processing, enabling advanced annotation-based command customization.

      Annotation replacers are particularly useful for:

      • Converting legacy annotation formats to newer ones
      • Applying conditional annotation logic based on runtime context
      • Implementing annotation inheritance or composition patterns
      • Providing backwards compatibility for deprecated annotations

      Example usage:

      
       builder.annotationReplacer(LegacyCommand.class, (annotation, context) -> {
           return RootCommand.builder()
               .name(annotation.value())
               .permission(annotation.permission())
               .build();
       });
       
      Type Parameters:
      A - the type of annotation to be replaced by the AnnotationReplacer
      Parameters:
      annotationType - the class object representing the annotation type to register a replacer for, must not be null
      replacer - the annotation replacer implementation that will handle transformations for the specified annotation type, must not be null
      Returns:
      this builder instance for method chaining
      Throws:
      IllegalArgumentException - if annotationType or replacer is null
      See Also:
    • overlapOptionalParameterSuggestions

      public B overlapOptionalParameterSuggestions(boolean overlap)
      Configures whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level. This is a builder method that provides a fluent interface for the underlying configuration setting.

      This setting affects the behavior of tab completion suggestions without modifying the underlying command structure. The command tree and parameter validation remain unchanged regardless of this setting.

      Examples:

      
       // RootCommand structure: /command [count] [extra]
       //                              \[extra]
      
       // When enabled (true):
       /command <TAB> → shows: [count], [extra]
      
       // When disabled (false):
       /command <TAB> → shows: [count] (first optional only)
       

      Default behavior: The default value depends on the framework configuration, but typically defaults to false for simpler user experience.

      Parameters:
      overlap - true to allow multiple optional parameter suggestions, false to limit to one optional parameter suggestion at a time
      Returns:
      this builder instance for method chaining
      See Also:
    • exceptionHandler

      public <T extends Throwable> B exceptionHandler(Class<T> exception, CommandExceptionHandler<T,S> handler)
      Registers a throwable resolver for a specific exception type. This method allows customizing the handling behavior for specific types of exceptions during application execution.
      Type Parameters:
      T - The type of the throwable.
      Parameters:
      exception - The class object representing the type of the throwable for which the resolver will be configured.
      handler - The CommandExceptionHandler implementation responsible for handling the specified throwable type.
      Returns:
      The current instance of ConfigBuilder, allowing method chaining for further configuration.
    • contextArgumentProviderFactory

      public <T> B contextArgumentProviderFactory(Type type, ContextArgumentProviderFactory<S,T> factory)
      Registers a context resolver factory for the specified type. This method allows configuring a factory responsible for creating a context resolver for the given type during the command processing.
      Type Parameters:
      T - the type the resolver factory handles
      Parameters:
      type - the specific type for which the resolver factory is being set
      factory - the context resolver factory to be registered
      Returns:
      this ConfigBuilder instance for method chaining
    • contextArgumentProvider

      public <T> B contextArgumentProvider(Type type, ContextArgumentProvider<S,T> resolver)
      Registers a context resolver for a specified type, allowing you to resolve a default value from the context for that type.
      Type Parameters:
      T - the type of value being resolved from the context
      Parameters:
      type - the class type of the value to be resolved
      resolver - the context resolver responsible for providing the default value when required
      Returns:
      the updated instance of ConfigBuilder, enabling fluent configuration
    • argType

      public <T> B argType(Type type, ArgumentType<S,T> resolver)
      Registers a parameter type and its associated resolver for parsing command arguments.
      Type Parameters:
      T - The type of the parameter being registered.
      Parameters:
      type - The class representing the type of the parameter being resolved.
      resolver - The resolver to handle parsing for the specified parameter type.
      Returns:
      The current instance of ConfigBuilder, allowing method chaining.
    • argTypeHandler

      public B argTypeHandler(ArgumentTypeHandler<S> handler)
      Registers an ArgumentTypeHandler to the configuration, allowing for custom handling of argument types during command processing. This method enables the addition of custom logic for resolving and managing argument types based on the provided handler implementation.
      Parameters:
      handler - the ArgumentTypeHandler instance that defines custom handling logic for argument types
      Returns:
      the current instance of ConfigBuilder for method chaining and further configuration
    • applyOnConfig

      public B applyOnConfig(@NotNull @NotNull Consumer<ImperatConfig<S>> configConsumer)
      Applies a consumer function to the current configuration, allowing modifications to be performed directly on the ImperatConfig instance.
      Parameters:
      configConsumer - a Consumer that takes the ImperatConfig<S> to apply changes. The provided consumer may modify the configuration as needed.
      Returns:
      the current B instance for fluent method chaining.
    • defaultSuggestionProvider

      public B defaultSuggestionProvider(@NotNull @NotNull SuggestionProvider<S> suggestionProvider)
      Sets the default suggestion resolver for providing autocomplete suggestions for command arguments or parameters in the configuration.
      Parameters:
      suggestionProvider - the SuggestionProvider implementation to be used as the default resolver for suggestions
      Returns:
      the current ConfigBuilder instance for method chaining
    • sourceProvider

      public <R> B sourceProvider(Type type, SourceProvider<S,R> sourceProvider)
      Registers a SourceProvider for a specific type to resolve command sources.
      Type Parameters:
      R - the resulting type resolved by the source resolver
      Parameters:
      type - the type of the source to be resolved
      sourceProvider - the source resolver instance that converts the source
      Returns:
      the current ConfigBuilder instance for method chaining
    • placeholder

      public B placeholder(Placeholder placeholder)
      Registers a placeholder with the configuration.
      Parameters:
      placeholder - the placeholder to be registered, containing the unique identifier and the dynamic resolver logic that defines how it behaves.
      Returns:
      the current ConfigBuilder instance for chaining further configuration.
    • globalDefaultPathwayBuilder

      public B globalDefaultPathwayBuilder(CommandPathway.Builder<S> usage)
      Sets the global default usage builder that will be used for all commands that do not have their own specific usage builder configured.

      The usage builder is responsible for constructing the usage/syntax data structure that defines how a command should be used, including its arguments, parameters, and expected format. This global default will be applied to all commands registered through this builder unless they explicitly override it with their own usage configuration.

      This method follows the builder pattern and returns the current builder instance to allow for method chaining.

      Parameters:
      usage - the CommandPathway.Builder to use as the global default for building command usage/syntax data. Must not be null.
      Returns:
      this builder instance for method chaining
      Throws:
      NullPointerException - if usage is null
      Since:
      1.0.0
      See Also:
    • handleMiddleOptionalArgSkipping

      public B handleMiddleOptionalArgSkipping(boolean toggle)
      Parameters:
      toggle - the toggle for this option
      Returns:
      whether this option is enabled or not.
    • instanceFactory

      public B instanceFactory(InstanceFactory<S> instanceFactory)
      Sets the instance factory used for creating instances of classes during command processing and dependency resolution.
      Parameters:
      instanceFactory - the InstanceFactory implementation to be used for instantiating classes. Must not be null.
      Returns:
      this builder instance for method chaining
      Throws:
      NullPointerException - if instanceFactory is null
      See Also:
    • visit

      public <T> B visit(Function<ImperatConfig<S>,T> function, Consumer<T> consumer)
    • build

      @NotNull public abstract I build()
      Builds and returns the final configuration object based on the provided settings and definitions within the builder. This method finalizes the configuration and ensures all dependencies are properly resolved before returning the result.
      Returns:
      the fully constructed and finalized instance of type I