Interface ImperatConfig<S extends Source>
- Type Parameters:
S- The type of the source object used by the configuration, which implements theSourceinterface.
- All Superinterfaces:
BaseThrowableHandler<S>,ProcessorRegistrar<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.<T> @Nullable ContextResolver<S,T> getContextResolver(Type resolvingContextType) FetchesContextResolverfor a certain valueTypedefault <T> ContextResolver<S,T> getContextResolver(CommandParameter<S> commandParameter) Fetches theContextResolversuitable for theCommandParameter<T> @Nullable ContextResolverFactory<S,T> getContextResolverFactory(Type resolvingContextType) @NotNull AttachmentMode@NotNull HelpCoordinator<S>The factory for creating instances of types to be dependency injected.<T> @Nullable ContextResolver<S,T> getMethodParamContextResolver(@NotNull ParameterElement element) Fetches the context resolver forParameterElementof a method@Nullable ParameterType<S,?> getParameterType(Type resolvingValueType) FetchesParameterTypefor a certain value@NotNull NodePermissionAssigner<S>The permission assigner for everyCommandParameter@NotNull PermissionLoader<S>getPlaceHolder(String id) The id/format of this placeholder, must be unique and lowercasebooleanWhether 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.booleanhasContextResolver(Type type) Checks whether the valueType has a registered context-resolverdefault booleanhasParameterType(Type type) default booleanhasSourceResolver(Type wrap) booleanIs the automatic permission assigning mode enabled? If so, theCommandTreewill be usingPermissionLoaderto deduce the permission perCommandParameterand theNodePermissionAssignerto assign the deduced permission to aParameterNodewhich is a crucial part ofCommandTreebooleanDetermines 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 typevoidsetAutoPermissionAssignMode(boolean toggle) Toggles the auto permission assign mode.voidsetCommandPrefix(String cmdPrefix) voidsetContextFactory(ContextFactory<S> contextFactory) sets the context factoryContextFactoryfor the contextsvoidsetDefaultAttachmentMode(AttachmentMode attachmentMode) Sets the defaultAttachmentModevoidsetGlobalDefaultUsage(CommandUsage.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.voidsetNodePermissionAssigner(NodePermissionAssigner<S> assigner) Sets the permission assigner forCommandParameteron every command.voidsetOptionalParameterSuggestionOverlap(boolean enabled) Sets whether multiple optional parameters can be suggested simultaneously during tab completion at the same command depth level.voidsetPermissionLoader(PermissionLoader<S> assigner) Sets the permission assigner for every parametervoidsetPermissionResolver(PermissionChecker<S> permissionChecker) Sets the permission resolver for the platform<T extends Throwable>
voidsetThrowableResolver(Class<T> exception, ThrowableResolver<T, S> handler) Registers a newThrowableResolverfor the specified valueType of throwable.voidsetUsageVerifier(UsageVerifier<S> usageVerifier) Sets the usage verifier to a new instanceMethods inherited from interface studio.mevera.imperat.BaseThrowableHandler
handleExecutionThrowableMethods inherited from interface studio.mevera.imperat.ProcessorRegistrar
getPostProcessors, getPreProcessors, setPostProcessorsChain, setPreProcessorsChainMethods inherited from interface studio.mevera.imperat.ResolverRegistrar
getDefaultSuggestionResolver, getNamedSuggestionResolver, getParameterSuggestionResolver, getReturnResolver, getSourceResolver, getSuggestionResolverByType, registerCollectionInitializer, registerContextResolver, registerContextResolverFactory, registerMapInitializer, registerNamedSuggestionResolver, registerParamType, registerPlaceholder, registerReturnResolver, registerReturnResolver, registerSourceResolver, registerSourceResolver, setDefaultSuggestionResolverMethods inherited from interface studio.mevera.imperat.ThrowableHandler
getThrowableResolver
-
Method Details
-
commandPrefix
String commandPrefix()- Returns:
- The command prefix
-
setCommandPrefix
-
getParameterType
FetchesParameterTypefor a certain value- Parameters:
resolvingValueType- the value that the resolver ends providing it from the context- Returns:
- the value resolver of a certain valueType
-
hasParameterType
-
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
-
setPermissionLoader
Sets the permission assigner for every parameter- Parameters:
assigner- the assigner.
-
getPermissionLoader
- Returns:
- The permission loader for
CommandParameteron every command.
-
setNodePermissionAssigner
Sets the permission assigner forCommandParameteron every command.- Parameters:
assigner- the assigner.
-
getPermissionAssigner
The permission assigner for everyCommandParameter- Returns:
- the
NodePermissionAssignerwhich is responsible for assigning permissions loaded byPermissionLoaderperCommandParameter.
-
isAutoPermissionAssignMode
@Experimental boolean isAutoPermissionAssignMode()Is the automatic permission assigning mode enabled? If so, theCommandTreewill be usingPermissionLoaderto deduce the permission perCommandParameterand theNodePermissionAssignerto assign the deduced permission to aParameterNodewhich is a crucial part ofCommandTree- Returns:
- Whether the automatic permission assign mode is enabled or not.
-
setAutoPermissionAssignMode
@Experimental void setAutoPermissionAssignMode(boolean toggle) Toggles the auto permission assign mode.- Parameters:
toggle- whether to enable/disable the auto permission assign(APS) mode.
-
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
- Command 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:
// Command 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
ParameterValueAssignerwill 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
-
getContextResolver
FetchesContextResolverfor a certain valueType- Type Parameters:
T- the valueType of class- Parameters:
resolvingContextType- the valueType for this resolver- Returns:
- the context resolver
-
getMethodParamContextResolver
@Nullable <T> @Nullable ContextResolver<S,T> getMethodParamContextResolver(@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
ContextResolverfor this element
-
getContextResolver
Fetches theContextResolversuitable for theCommandParameter- Type Parameters:
T- the valueType of value that will be resolved byParameterType.resolve(ExecutionContext, CommandInputStream, String)- Parameters:
commandParameter- the parameter of a command's usage- Returns:
- the context resolver for this parameter's value valueType
-
getContextResolverFactory
@Nullable <T> @Nullable ContextResolverFactory<S,T> getContextResolverFactory(Type resolvingContextType) - Parameters:
resolvingContextType- the valueType the factory is registered to- Returns:
- returns the factory for creation of
ContextResolver
-
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
Context
-
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
-
setContextFactory
sets the context factoryContextFactoryfor the contexts- Parameters:
contextFactory- the context factory to set
-
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
-
getUsageVerifier
UsageVerifier<S> getUsageVerifier()- Returns:
- the usage verifier
-
setUsageVerifier
Sets the usage verifier to a new instance- Parameters:
usageVerifier- the usage verifier to set
-
hasSourceResolver
-
setThrowableResolver
Registers a newThrowableResolverfor the specified valueType of throwable. This allows customizing the handling of specific throwable types within the application.- Specified by:
setThrowableResolverin interfaceThrowableHandler<S extends Source>- Type Parameters:
T- The valueType of the throwable.- Parameters:
exception- The class of the throwable to set the resolver for.handler- TheThrowableResolverto be registered for the specified throwable valueType.- See Also:
-
getGlobalDefaultUsage
- Returns:
- The global/centralized default usage of EVERY command its empty by default.
-
setGlobalDefaultUsage
Sets the usual default usage if the user doesn't set the default-usage for aCommand- Parameters:
globalDefaultUsage- the global default usage BUILDER.
-
getDefaultAttachmentMode
- Returns:
- the default attachment mode
AttachmentMode
-
setDefaultAttachmentMode
Sets the defaultAttachmentMode- Parameters:
attachmentMode- the attachment mode.
-
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
-