Interface ImperatConfig<S extends CommandSource>
- Type Parameters:
S- The type of the source object used by the configuration, which implements theCommandSourceinterface.
- All Superinterfaces:
BaseThrowableHandler<S>,ResolverRegistrar<S>,ThrowableHandler<S>
ImperatConfig interface defines the core configuration and interaction points
for a command processing system. It provides methods for registering handlers,
resolving dependencies, and managing the execution context. This interface enables
integration of custom resolvers, context factories, permission management, and
placeholder handling.
Implementations of this interface are responsible for providing these required functionalities and may enforce strict validation and processing rules based on the specified configurations.
-
Method Summary
Modifier and TypeMethodDescription<A extends Annotation>
voidapplyAnnotationReplacers(Imperat<S> imperat) Apply annotation replacers.@Nullable ArgumentType<S,?> getArgumentType(Type resolvingValueType) FetchesArgumentTypefor a certain value<T> @Nullable ContextArgumentProvider<S,T> getContextArgumentProvider(Type resolvingContextType) FetchesContextArgumentProviderfor a certain valueTypedefault <T> ContextArgumentProvider<S,T> getContextArgumentProvider(Argument<S> Argument) Fetches theContextArgumentProvidersuitable for theArgument<T> @Nullable ContextArgumentProviderFactory<S,T> getContextArgumentProviderFactory(Type resolvingContextType) <T> @Nullable ContextArgumentProvider<S,T> getContextArgumentProviderFor(@NotNull ParameterElement element) Fetches the context resolver forParameterElementof a method@Nullable Object@NotNull HelpCoordinator<S>The factory for creating instances of types to be dependency injected.getPlaceHolder(String id) The id/format of this placeholder, must be unique and lowercase@NotNull ThrowablePrinterbooleanWhether to handle the skipping of consecutive optional argument during execution For example if you have `/test [a] [b]` where parameter 'a' is of type String and parameter 'b' is of type Integer.default booleanhasArgumentType(Type type) booleanhasContextResolver(Type type) Checks whether the valueType has a registered context-resolverbooleandefault booleanhasSourceResolver(Type wrap) booleanDetermines whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.<A extends Annotation>
voidregisterAnnotationReplacer(Class<A> type, AnnotationReplacer<A> replacer) Registers annotation replacervoidregisterDependencyResolver(Type type, DependencySupplier resolver) Registers the dependency to the type@NotNull StringreplacePlaceholders(String input) Replaces the placeholders of input by theirPlaceholderResolver@NotNull String[]replacePlaceholders(String[] array) Replaces the placeholders on each string of the array, modifying the input array content.<T> TresolveDependency(Type type) Resolves dependency of certain typevoidsetCommandPrefix(String cmdPrefix) voidsetContextFactory(ContextFactory<S> contextFactory) sets the context factoryContextFactoryfor the contextsvoidsetCoroutineScope(@NotNull Object scope) <T extends Throwable>
voidsetErrorHandler(Class<T> exception, CommandExceptionHandler<T, S> handler) Registers a newCommandExceptionHandlerfor the specified valueType of throwable.voidsetEventBus(EventBus eventBus) voidsetGlobalCommandCoordinator(CommandCoordinator<S> commandCoordinator) voidsetGlobalDefaultPathway(CommandPathway.Builder<S> globalDefaultUsage) Sets the usual default usage if the user doesn't set the default-usage for aCommandvoidsetHandleExecutionConsecutiveOptionalArgumentsSkip(boolean toggle) Refer tohandleExecutionMiddleOptionalSkipping()to know about this option.voidsetHelpCoordinator(@NotNull HelpCoordinator<S> coordinator) Sets the coordinator for displaying of a help.voidsetInstanceFactory(InstanceFactory<S> factory) Sets the instance factory for creating instances of types to be dependency injected.voidsetOptionalParameterSuggestionOverlap(boolean enabled) Sets whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.voidsetPermissionResolver(PermissionChecker<S> permissionChecker) Sets the permission resolver for the platformvoidsetThrowablePrinter(@NotNull ThrowablePrinter printer) Sets the printer used for unhandled throwables.Methods inherited from interface studio.mevera.imperat.BaseThrowableHandler
handleExecutionErrorMethods inherited from interface studio.mevera.imperat.ResolverRegistrar
getArgumentTypeRegistry, getDefaultSuggestionResolver, getParameterSuggestionResolver, getResponseRegistry, getReturnResolver, getSourceProviderFor, getSuggestionProviderForType, registerArgType, registerArgTypeHandler, registerContextArgumentProvider, registerContextArgumentProviderFactory, registerPlaceholder, registerReturnResolver, registerReturnResolver, registerSourceProvider, registerSourceProvider, setDefaultSuggestionProviderMethods inherited from interface studio.mevera.imperat.ThrowableHandler
getErrorHandlerFor
-
Method Details
-
commandPrefix
String commandPrefix()- Returns:
- The command prefix
-
setCommandPrefix
-
getThrowablePrinter
- Returns:
- the printer used for unhandled throwables
-
setThrowablePrinter
Sets the printer used for unhandled throwables.- Parameters:
printer- the throwable printer to use
-
getArgumentType
FetchesArgumentTypefor a certain value- Parameters:
resolvingValueType- the value that the resolver ends providing it from the context- Returns:
- the value resolver of a certain valueType
-
hasArgumentType
-
registerAnnotationReplacer
<A extends Annotation> void registerAnnotationReplacer(Class<A> type, AnnotationReplacer<A> replacer) Registers annotation replacer- Type Parameters:
A- the type of annotation to replace by theAnnotationReplacer- Parameters:
type- the type of annotation to registerreplacer- the replacer for this annotation
-
applyAnnotationReplacers
Apply annotation replacers.- Type Parameters:
A- A type variable used internally- Parameters:
imperat- the imperat instance
-
isOptionalParameterSuggestionOverlappingEnabled
boolean isOptionalParameterSuggestionOverlappingEnabled()Determines whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.When enabled (
true), all available optional parameters will be included in tab completion suggestions, allowing users to see all possible optional arguments they can provide at the current position.When disabled (
false), only the first optional parameter (typically based on priority or registration order) will be suggested, preventing overwhelming users with too many optional choices and reducing ambiguity in command completion.This setting does not affect:
- Required parameters - they are always suggested
- RootCommand structure - the actual command tree remains unchanged
- Parameter validation - all parameters remain functionally available
- Returns:
trueif multiple optional parameters can overlap in suggestions,falseif only one optional parameter should be suggested at a time- See Also:
-
setOptionalParameterSuggestionOverlap
void setOptionalParameterSuggestionOverlap(boolean enabled) Sets whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.This is a configuration setting that 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)- Parameters:
enabled-trueto allow multiple optional parameter suggestions,falseto limit to one optional parameter suggestion- See Also:
-
handleExecutionMiddleOptionalSkipping
boolean handleExecutionMiddleOptionalSkipping()Whether to handle the skipping of consecutive optional argument during execution For example if you have `/test [a] [b]` where parameter 'a' is of type String and parameter 'b' is of type Integer. if you enter `/test 1` while this option is enabled, it would handle this and assign the parameter 'b' to the value that suits its type. with no respect for the order of optional arguments.
Else if the option is disabled, then Imperat's
OptionalArgumentHandlerwill respect the order of the optional arguments, and will resolve the arguments in order.- Returns:
- Whether to handle the skipping of consecutive optional argument DURING EXECUTION.
-
setHandleExecutionConsecutiveOptionalArgumentsSkip
void setHandleExecutionConsecutiveOptionalArgumentsSkip(boolean toggle) Refer tohandleExecutionMiddleOptionalSkipping()to know about this option.- Parameters:
toggle- whether to toggle the handling of middle optional skipping
-
hasContextResolver
Checks whether the valueType has a registered context-resolver- Parameters:
type- the valueType- Returns:
- whether the valueType has a context-resolver
-
getContextArgumentProvider
@Nullable <T> @Nullable ContextArgumentProvider<S,T> getContextArgumentProvider(Type resolvingContextType) FetchesContextArgumentProviderfor a certain valueType- Type Parameters:
T- the valueType of class- Parameters:
resolvingContextType- the valueType for this resolver- Returns:
- the context resolver
-
getContextArgumentProviderFor
@Nullable <T> @Nullable ContextArgumentProvider<S,T> getContextArgumentProviderFor(@NotNull @NotNull ParameterElement element) Fetches the context resolver forParameterElementof a method- Type Parameters:
T- the valueType of value this parameter should be resolved into- Parameters:
element- the element- Returns:
- the
ContextArgumentProviderfor this element
-
getContextArgumentProvider
Fetches theContextArgumentProvidersuitable for theArgument- Type Parameters:
T- the valueType of value that will be resolved byArgumentType.parse(CommandContext, Argument, String)ORArgumentType.parse(ExecutionContext, Cursor)during execution- Parameters:
Argument- the parameter of a command's usage- Returns:
- the context resolver for this parameter's value valueType
-
getContextArgumentProviderFactory
@Nullable <T> @Nullable ContextArgumentProviderFactory<S,T> getContextArgumentProviderFactory(Type resolvingContextType) - Parameters:
resolvingContextType- the valueType the factory is registered to- Returns:
- returns the factory for creation of
ContextArgumentProvider
-
getPermissionChecker
PermissionChecker<S> getPermissionChecker()- Returns:
PermissionCheckerfor the dispatcher
-
setPermissionResolver
Sets the permission resolver for the platform- Parameters:
permissionChecker- the permission resolver to set
-
getContextFactory
ContextFactory<S> getContextFactory()- Returns:
- the factory for creation of
command related contexts
CommandContext
-
setContextFactory
sets the context factoryContextFactoryfor the contexts- Parameters:
contextFactory- the context factory to set
-
getPlaceHolder
The id/format of this placeholder, must be unique and lowercase- Parameters:
id- the id for the placeholder- Returns:
- the placeholder
-
replacePlaceholders
Replaces the placeholders of input by theirPlaceholderResolver- Parameters:
input- the input- Returns:
- the processed/replaced text input.
-
replacePlaceholders
Replaces the placeholders on each string of the array, modifying the input array content.- Parameters:
array- the array to replace its string contents- Returns:
- The placeholder replaced String array
-
registerDependencyResolver
Registers the dependency to the type- Parameters:
type- the type for the dependencyresolver- the resolver
-
resolveDependency
Resolves dependency of certain type- Parameters:
type- the type
-
hasSourceResolver
-
setErrorHandler
<T extends Throwable> void setErrorHandler(Class<T> exception, CommandExceptionHandler<T, S> handler) Registers a newCommandExceptionHandlerfor the specified valueType of throwable. This allows customizing the handling of specific throwable types within the application.- Specified by:
setErrorHandlerin interfaceThrowableHandler<S extends CommandSource>- Type Parameters:
T- The valueType of the throwable.- Parameters:
exception- The class of the throwable to set the resolver for.handler- TheCommandExceptionHandlerto be registered for the specified throwable valueType.- See Also:
-
getGlobalDefaultPathway
- Returns:
- The global/centralized default usage of EVERY command its empty by default.
-
setGlobalDefaultPathway
Sets the usual default usage if the user doesn't set the default-usage for aCommand- Parameters:
globalDefaultUsage- the global default usage BUILDER.
-
getHelpCoordinator
- Returns:
- the help coordinator that coordinates how a help is being shown and displayed to the source.
-
setHelpCoordinator
Sets the coordinator for displaying of a help.- Parameters:
coordinator- the new coordinator to set.
-
getInstanceFactory
InstanceFactory<S> getInstanceFactory()The factory for creating instances of types to be dependency injected.- Returns:
- the instance factory
-
setInstanceFactory
Sets the instance factory for creating instances of types to be dependency injected.- Parameters:
factory- the instance factory to set
-
getGlobalCommandCoordinator
CommandCoordinator<S> getGlobalCommandCoordinator()- Returns:
- the default global command coordinator
-
setGlobalCommandCoordinator
-
setCoroutineScope
-
getCoroutineScope
-
hasCoroutineScope
boolean hasCoroutineScope() -
setCommandParsingMode
-
getCommandParsingMode
CommandParsingMode getCommandParsingMode() -
getEventBus
EventBus getEventBus() -
setEventBus
-