Class ConfigBuilder<S extends CommandSource,I extends Imperat<S>,B extends 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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<A extends Annotation>
BannotationReplacer(Class<A> annotationType, AnnotationReplacer<A> replacer) Registers a custom annotation replacer for the specified annotation type.applyOnConfig(@NotNull Consumer<ImperatConfig<S>> configConsumer) Applies a consumer function to the current configuration, allowing modifications to be performed directly on theImperatConfiginstance.<T> BargType(Type type, ArgumentType<S, T> resolver) Registers a parameter type and its associated resolver for parsing command arguments.argTypeHandler(ArgumentTypeHandler<S> handler) Registers anArgumentTypeHandlerto the configuration, allowing for custom handling of argument types during command processing.abstract Ibuild()Builds and returns the final configuration object based on the provided settings and definitions within the builder.commandPrefix(String cmdPrefix) Sets the command prefix for the command processing chain.<T> BcontextArgumentProvider(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.<T> BcontextArgumentProviderFactory(Type type, ContextArgumentProviderFactory<S, T> factory) Registers a context resolver factory for the specified type.contextFactory(ContextFactory<S> contextFactory) Sets the context factory for creating contexts used in command execution.defaultSuggestionProvider(@NotNull SuggestionProvider<S> suggestionProvider) Sets the default suggestion resolver for providing autocomplete suggestions for command arguments or parameters in the configuration.dependencyResolver(Type type, DependencySupplier resolver) Registers a dependency resolver for a specific type and returns the currentConfigBuilderinstance.Sets the event bus to be used for handling events within the configuration.exceptionHandler(Class<T> exception, CommandExceptionHandler<T, S> handler) Registers a throwable resolver for a specific exception type.globalCoordinator(CommandCoordinator<S> commandCoordinator) Sets the global default usage builder that will be used for all commands that do not have their own specific usage builder configured.handleMiddleOptionalArgSkipping(boolean toggle) helpCoordinator(HelpCoordinator<S> coordinator) Sets theHelpCoordinatorthat coordinates all the core-components of the new help API, to create a coordinator callHelpCoordinator.create()instanceFactory(InstanceFactory<S> instanceFactory) Sets the instance factory used for creating instances of classes during command processing and dependency resolution.overlapOptionalParameterSuggestions(boolean overlap) Configures whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.permissionChecker(PermissionChecker<S> permissionChecker) Sets a customPermissionCheckerto determine and resolve permissions for the command sender/source within the platform's configuration.placeholder(Placeholder placeholder) Registers a placeholder with the configuration.response(ResponseKey key, Supplier<String> contentSupplier, String... placeholders) returnResolver(Type type, ReturnResolver<S, ?> returnResolver) Registers aReturnResolver<R> BsourceProvider(Type type, SourceProvider<S, R> sourceProvider) Registers aSourceProviderfor a specific type to resolve command sources.throwablePrinter(ThrowablePrinter printer) Sets theThrowablePrinterused to print unhandled exceptions.<T> Bvisit(Function<ImperatConfig<S>, T> function, Consumer<T> consumer)
-
Field Details
-
config
-
-
Constructor Details
-
ConfigBuilder
protected ConfigBuilder()
-
-
Method Details
-
eventBus
Sets the event bus to be used for handling events within the configuration.- Parameters:
bus- theEventBusinstance to be set in the configuration- Returns:
- the current instance of
ConfigBuilderfor method chaining
-
commandPrefix
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
Sets theThrowablePrinterused to print unhandled exceptions.- Parameters:
printer- the printer to use- Returns:
- the current builder instance for chaining
-
response
-
response
-
globalCoordinator
-
permissionChecker
Sets a customPermissionCheckerto determine and resolve permissions for the command sender/source within the platform's configuration.- Parameters:
permissionChecker- thePermissionCheckerimplementation used to handle permission checks for commands- Returns:
- the current
ConfigBuilderinstance for method chaining and further configuration
-
helpCoordinator
Sets theHelpCoordinatorthat coordinates all the core-components of the new help API, to create a coordinator callHelpCoordinator.create()- Parameters:
coordinator- the coordinator- Returns:
- the current instance of
ConfigBuilderfor method chaining - Since:
- 2.0.0
-
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
ConfigBuilderfor method chaining
-
returnResolver
Registers aReturnResolver- Parameters:
type- the type of value to return using the return resolverreturnResolver- the return resolving instance.- Returns:
- the current
ConfigBuilderinstance for fluent chaining
-
dependencyResolver
Registers a dependency resolver for a specific type and returns the currentConfigBuilderinstance.- Parameters:
type- the target type for which the dependency resolver is being registeredresolver- the dependency resolver to associate with the specified type- Returns:
- the current instance of
ConfigBuilderfor 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 theAnnotationReplacer- Parameters:
annotationType- the class object representing the annotation type to register a replacer for, must not benullreplacer- the annotation replacer implementation that will handle transformations for the specified annotation type, must not benull- Returns:
- this builder instance for method chaining
- Throws:
IllegalArgumentException- if annotationType or replacer isnull- See Also:
-
overlapOptionalParameterSuggestions
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
falsefor simpler user experience.- Parameters:
overlap-trueto allow multiple optional parameter suggestions,falseto 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- TheCommandExceptionHandlerimplementation responsible for handling the specified throwable type.- Returns:
- The current instance of
ConfigBuilder, allowing method chaining for further configuration.
-
contextArgumentProviderFactory
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 setfactory- the context resolver factory to be registered- Returns:
- this ConfigBuilder instance for method chaining
-
contextArgumentProvider
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 resolvedresolver- the context resolver responsible for providing the default value when required- Returns:
- the updated instance of
ConfigBuilder, enabling fluent configuration
-
argType
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
Registers anArgumentTypeHandlerto 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- theArgumentTypeHandlerinstance that defines custom handling logic for argument types- Returns:
- the current instance of
ConfigBuilderfor method chaining and further configuration
-
applyOnConfig
Applies a consumer function to the current configuration, allowing modifications to be performed directly on theImperatConfiginstance.- Parameters:
configConsumer- aConsumerthat takes theImperatConfig<S>to apply changes. The provided consumer may modify the configuration as needed.- Returns:
- the current
Binstance for fluent method chaining.
-
defaultSuggestionProvider
Sets the default suggestion resolver for providing autocomplete suggestions for command arguments or parameters in the configuration.- Parameters:
suggestionProvider- theSuggestionProviderimplementation to be used as the default resolver for suggestions- Returns:
- the current
ConfigBuilderinstance for method chaining
-
sourceProvider
Registers aSourceProviderfor 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 resolvedsourceProvider- the source resolver instance that converts the source- Returns:
- the current
ConfigBuilderinstance for method chaining
-
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
ConfigBuilderinstance for chaining further configuration.
-
globalDefaultPathwayBuilder
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- theCommandPathway.Builderto use as the global default for building command usage/syntax data. Must not benull.- Returns:
- this builder instance for method chaining
- Throws:
NullPointerException- ifusageisnull- Since:
- 1.0.0
- See Also:
-
handleMiddleOptionalArgSkipping
- Parameters:
toggle- the toggle for this option- Returns:
- whether this option is enabled or not.
-
instanceFactory
Sets the instance factory used for creating instances of classes during command processing and dependency resolution.- Parameters:
instanceFactory- theInstanceFactoryimplementation to be used for instantiating classes. Must not benull.- Returns:
- this builder instance for method chaining
- Throws:
NullPointerException- ifinstanceFactoryisnull- See Also:
-
visit
-
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
-