Class ConfigBuilder<S extends Source,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.autoPermissionAssignMode(boolean modeToggle) Toggles the APA (Auto Permission Assign) mode, When enabled, it will automatically compute, set permissions automatically for everyCommandParameterin everyCommandUsageyou make without the need to explicitly set the permissions , the same goes on ROOT commands and even subcommands (since they are also treated asCommandParameter)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.contextFactory(ContextFactory<S> contextFactory) Sets the context factory for creating contexts used in command execution.<T> BcontextResolver(Type type, ContextResolver<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> BcontextResolverFactory(Type type, ContextResolverFactory<S, T> factory) Registers a context resolver factory for the specified type.defaultAttachmentMode(AttachmentMode attachmentMode) The default attachment mode.defaultSuggestionResolver(@NotNull SuggestionResolver<S> suggestionResolver) 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 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.namedSuggestionResolver(String name, SuggestionResolver<S> suggestionResolver) Registers a named suggestion resolver for providing autocomplete suggestions for command arguments or parameters.overlapOptionalParameterSuggestions(boolean overlap) Configures whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.<T> BparameterType(Type type, ParameterType<S, T> resolver) Registers a parameter type and its associated resolver for parsing command arguments.permissionAssigner(NodePermissionAssigner<S> permissionAssigner) Sets the permission assigner for automatic permission assignment.permissionChecker(PermissionChecker<S> permissionChecker) Sets a customPermissionCheckerto determine and resolve permissions for the command sender/source within the platform's configuration.permissionLoader(PermissionLoader<S> permissionLoader) Sets the permission loader for automatic permission assignment.placeholder(Placeholder<S> placeholder) Registers a placeholder with the configuration.Sets the post-processing chain for the configuration.postProcessor(CommandPostProcessor<S> postProcessor) Adds aCommandPostProcessorto the chain of execution that processes the command context after the resolving of arguments into values.Configures the pre-processing chain for command processing.preProcessor(CommandPreProcessor<S> preProcessor) Adds a command pre-processor to the configuration.returnResolver(Type type, ReturnResolver<S, ?> returnResolver) Registers aReturnResolversetDefaultSuggestionResolver(SuggestionResolver<S> resolver) Sets the default suggestion resolver to be used when no specific resolver is defined for a parameter or command context.<R> BsourceResolver(Type type, SourceResolver<S, R> sourceResolver) Registers aSourceResolverfor a specific type to resolve command sources.throwableResolver(Class<T> exception, ThrowableResolver<T, S> handler) Registers a throwable resolver for a specific exception type.usageVerifier(UsageVerifier<S> usageVerifier) Sets the usage verifier for the configuration.
-
Field Details
-
config
-
-
Constructor Details
-
ConfigBuilder
protected ConfigBuilder()
-
-
Method Details
-
commandPrefix
Sets the command prefix for the command processing chain.- Parameters:
cmdPrefix- the prefix string to be used before commands- Returns:
- the updated instance of the ConfigBuilder to allow for method chaining
-
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
-
autoPermissionAssignMode
Toggles the APA (Auto Permission Assign) mode, When enabled, it will automatically compute, set permissions automatically for everyCommandParameterin everyCommandUsageyou make without the need to explicitly set the permissions , the same goes on ROOT commands and even subcommands (since they are also treated asCommandParameter)- Parameters:
modeToggle- toggles the auto permission assign mode- Returns:
- the current
ConfigBuilderinstance for method chaining and further configuration
-
permissionLoader
Sets the permission loader for automatic permission assignment.This method configures the
PermissionLoaderthat will be used to load and resolve permissions for command parameters when Auto Permission Assign (APA) mode is active. The permission loader is responsible for determining what permissions should be applied to individual command nodes based on the command structure and configuration.Prerequisite: This method can only be called when APA mode is enabled via the configuration. APA mode must be activated before setting up permission loading components to ensure proper initialization order and prevent configuration conflicts.
The permission loader works in conjunction with the
NodePermissionAssignerto provide a complete automatic permission assignment system. The loader determines which permissions to assign, while the assigner handles how those permissions are applied to the parameter nodes.- Parameters:
permissionLoader- the permission loader to use for loading permissions, must not be null- Returns:
- this builder instance for method chaining, never null
- Throws:
IllegalStateException- if Auto Permission Assign (APA) mode is not enabledNullPointerException- ifpermissionLoaderis null- Since:
- 1.0
- See Also:
-
permissionAssigner
Sets the permission assigner for automatic permission assignment.This method configures the
NodePermissionAssignerthat will be used to assign permissions to command parameter nodes when Auto Permission Assign (APA) mode is active. The permission assigner defines the strategy for how permissions loaded by thePermissionLoaderare actually applied to individualParameterNodeinstances.Prerequisite: This method can only be called when APA mode is enabled via the configuration. APA mode must be activated before setting up permission assignment components to ensure proper initialization order and prevent configuration conflicts.
The permission assigner works in conjunction with the
PermissionLoaderto provide a complete automatic permission assignment system. The loader determines which permissions to assign, while the assigner handles how those permissions are applied to the parameter nodes.If no custom assigner is provided, the system will use the default assigner available via
NodePermissionAssigner.defaultAssigner().- Parameters:
permissionAssigner- the permission assigner to use for assigning permissions to parameter nodes, must not be null- Returns:
- this builder instance for method chaining, never null
- Throws:
IllegalStateException- if Auto Permission Assign (APA) mode is not enabledNullPointerException- ifpermissionAssigneris null- See Also:
-
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
-
usageVerifier
Sets the usage verifier for the configuration.- Parameters:
usageVerifier- theUsageVerifierinstance to validate command usages- Returns:
- the current
ConfigBuilderinstance for fluent 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 Command.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:
// Command 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:
-
setDefaultSuggestionResolver
Sets the default suggestion resolver to be used when no specific resolver is defined for a parameter or command context. This resolver acts as a fallback mechanism for tab completion suggestions.The default suggestion resolver is invoked when:
- A parameter has no specific
SuggestionResolverdefined - A command argument requires suggestions but no custom logic exists
- Fallback suggestions are needed during error recovery
Example usage:
builder.setDefaultSuggestionResolver((source, context, input) -> { // Provide generic suggestions like player names, common values, etc. return Arrays.asList("player1", "player2", "default_value"); });Note: Setting this to
nullwill disable default suggestions, potentially leaving some parameters without tab completion support.- Parameters:
resolver- the default suggestion resolver implementation, ornullto disable default suggestions- Returns:
- this builder instance for method chaining
- See Also:
- A parameter has no specific
-
throwableResolver
public <T extends Throwable> B throwableResolver(Class<T> exception, ThrowableResolver<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- TheThrowableResolverimplementation responsible for handling the specified throwable type.- Returns:
- The current instance of
ConfigBuilder, allowing method chaining for further configuration.
-
preProcessor
Adds a command pre-processor to the configuration. A command pre-processor is executed before resolving command arguments into values.- Parameters:
preProcessor- theCommandPreProcessorto be added to the chain of execution- Returns:
- the current
ConfigBuilderinstance for method chaining
-
postProcessor
Adds aCommandPostProcessorto the chain of execution that processes the command context after the resolving of arguments into values.- Parameters:
postProcessor- the post-processor to be added to the execution chain; it processes the command context after argument resolution- Returns:
- the current
ConfigBuilderinstance for chaining additional configurations
-
preProcessingChain
Configures the pre-processing chain for command processing. This chain defines a series ofCommandPreProcessorinstances that will execute before resolving the arguments into values.- Parameters:
chain- the pre-processing chain to set, which consists of multipleCommandPreProcessorhandlers- Returns:
- the current
ConfigBuilderinstance for method chaining
-
postProcessingChain
Sets the post-processing chain for the configuration.- Parameters:
chain- theCommandProcessingChainofCommandPostProcessorinstances to be set as the post-processing chain- Returns:
- the
ConfigBuilderinstance for method chaining
-
contextResolverFactory
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
-
contextResolver
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
-
parameterType
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.
-
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.
-
namedSuggestionResolver
Registers a named suggestion resolver for providing autocomplete suggestions for command arguments or parameters.- Parameters:
name- the unique name to identify the suggestion resolversuggestionResolver- the suggestion resolver to be registered- Returns:
- the current instance of
ConfigBuilderfor method chaining
-
defaultSuggestionResolver
Sets the default suggestion resolver for providing autocomplete suggestions for command arguments or parameters in the configuration.- Parameters:
suggestionResolver- theSuggestionResolverimplementation to be used as the default resolver for suggestions- Returns:
- the current
ConfigBuilderinstance for method chaining
-
sourceResolver
Registers aSourceResolverfor 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 resolvedsourceResolver- 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.
-
globalDefaultUsageBuilder
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- theCommandUsage.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.
-
defaultAttachmentMode
The default attachment mode.- Parameters:
attachmentMode- the default attachment mode- Returns:
- the default value.
-
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:
-
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
-