A - The actor typepublic final class Lamp<A extends CommandActor>
extends java.lang.Object
builder().
Lamp instances are expensive to create. They are immutable so they are safe to re-use and share across threads.
| Modifier and Type | Class and Description |
|---|---|
static class |
Lamp.Builder<A extends CommandActor> |
| Constructor and Description |
|---|
Lamp(Lamp.Builder<A> builder) |
| Modifier and Type | Method and Description |
|---|---|
@NotNull Lamp<A> |
accept(@NotNull LampVisitor<A> visitor)
Accepts the given visitor by calling
LampVisitor.visit(Lamp) on
this Lamp instance |
@Unmodifiable @NotNull java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Set<AnnotationReplacer<?>>> |
annotationReplacers()
Returns an immutable map of the annotation replacers registered
in this
Lamp instance |
@NotNull AutoCompleter<A> |
autoCompleter()
Returns the
AutoCompleter of this Lamp instance |
static <A extends CommandActor> |
builder()
Creates a new Lamp
Lamp.Builder |
@Unmodifiable @NotNull java.util.List<CommandCondition<? super A>> |
commandConditions()
Returns an immutable list of the command conditions registered
in this
Lamp instance |
@NotNull CommandPermission<A> |
createPermission(AnnotationList annotations)
Creates a new
CommandPermission for the given list of annotations. |
<T> T |
dependency(@NotNull java.lang.Class<T> type)
Returns the dependency that corresponds to the given type, otherwise
throws an
IllegalStateException |
void |
dispatch(A actor,
java.lang.String input)
Executes the given input on the behalf of the specified actor.
|
void |
dispatch(A actor,
StringStream input)
Executes the given input on the behalf of the specified actor.
|
@NotNull DispatcherSettings<A> |
dispatcherSettings()
Returns the
DispatcherSettings that are used by
Lamp under the hood to customize the dispatcher settings. |
@NotNull MessageSender<? super A,java.lang.String> |
errorSender()
Returns the
MessageSender responsible for sending
messages using CommandActor.error(String) |
<T> @NotNull ParameterResolver<A,T> |
findNextResolver(@NotNull java.lang.reflect.Type type,
@NotNull AnnotationList annotations,
@NotNull ParameterFactory skipPast)
Returns the first
ParameterType that comes after the skipPast
factory. |
SuggestionProvider<A> |
findNextSuggestionProvider(java.lang.reflect.Type type,
AnnotationList annotations,
SuggestionProvider.Factory<? super A> skipPast,
Lamp<A> lamp)
Returns the first
SuggestionProvider that comes after the skipPast
factory. |
void |
handleException(@NotNull java.lang.Throwable throwable,
@NotNull ErrorContext<A> errorContext)
Handles the given exception in the given context.
|
@NotNull Hooks<A> |
hooks()
Returns the hooks registry
|
@NotNull MessageSender<? super A,java.lang.String> |
messageSender()
Returns the
MessageSender responsible for sending
messages using CommandActor.reply(String) |
@NotNull ParameterNamingStrategy |
parameterNamingStrategy()
Returns the parameter naming strategy for this
Lamp instance |
@NotNull ParameterTypes<A> |
parameterTypes()
Returns the parameter type registry
|
@Unmodifiable @NotNull java.util.List<ParameterValidator<A,java.lang.Object>> |
parameterValidators()
Returns an immutable list of the parameter resolvers registered
in this
Lamp instance |
@NotNull @Unmodifiable java.util.List<ExecutableCommand<A>> |
register(java.lang.Object... instances)
Registers the given instance to the command handler.
|
@NotNull CommandRegistry<A> |
registry()
Returns the command registry.
|
<T> @NotNull ParameterResolver<A,T> |
resolver(@NotNull CommandParameter parameter)
Returns the first
ParameterType that can parse the given parameter. |
<T> @NotNull ParameterResolver<A,T> |
resolver(@NotNull java.lang.reflect.Type type)
Returns the first
ParameterType that can parse the given type. |
<T> @NotNull ParameterResolver<A,T> |
resolver(@NotNull java.lang.reflect.Type type,
@NotNull AnnotationList annotations)
Returns the first
ParameterType that can parse the given type
and annotations. |
<T> @NotNull ResponseHandler<A,T> |
responseHandler(@NotNull java.lang.reflect.Type type,
@NotNull AnnotationList annotations)
Returns the first
ResponseHandler that can handle the given type
and annotation list. |
@Unmodifiable @NotNull java.util.List<SenderResolver<? super A>> |
senderResolvers()
Returns an immutable list of the sender resolvers registered
in this
Lamp instance |
@NotNull SuggestionProvider<A> |
suggestionProvider(CommandParameter parameter)
Returns the first
SuggestionProvider that can create suggestions
for the given parameter. |
@NotNull SuggestionProvider<A> |
suggestionProvider(java.lang.reflect.Type type)
Returns the first
SuggestionProvider that can create suggestions
for the given type and annotations. |
@NotNull SuggestionProvider<A> |
suggestionProvider(java.lang.reflect.Type type,
AnnotationList annotations)
Returns the first
SuggestionProvider that can create suggestions
for the given type and annotations. |
@NotNull SuggestionProviders<A> |
suggestionProviders()
Returns the suggestion provider registry
|
void |
unregister(@NotNull ExecutableCommand<A> execution)
Unregisters the given executable command
|
void |
unregisterAllCommands()
Unregisters all the commands in this Lamp instance
|
void |
unregisterIf(@NotNull java.util.function.Predicate<ExecutableCommand<A>> commandPredicate)
Unregisters all the commands in this Lamp instance that match
the given predicate
|
<T> void |
validate(A actor,
T value,
ParameterNode<A,T> parameter)
Validates a parameter by passing it into the registered
ParameterValidators |
public Lamp(Lamp.Builder<A> builder)
@NotNull public static <A extends CommandActor> @NotNull Lamp.Builder<A> builder()
Lamp.BuilderA - The actor type@NotNull public <T> @NotNull ParameterResolver<A,T> resolver(@NotNull @NotNull CommandParameter parameter)
ParameterType that can parse the given parameter.
Note that this method will never return null. In cases where no
suitable factory is found, it will throw IllegalArgumentException.
parameter - The parameter to create a resolver forjava.lang.IllegalStateException - if no suitable parameter type was found@NotNull public <T> @NotNull ParameterResolver<A,T> resolver(@NotNull @NotNull java.lang.reflect.Type type)
ParameterType that can parse the given type.
This method can be used to create more complex parameter types for
composite types (such as T[]).
Note that this method assumes the type has no annotations.
Note that this method will never return null. In cases where no
suitable factory is found, it will throw IllegalArgumentException.
type - The type to create forjava.lang.IllegalStateException - if no suitable parameter type was found@NotNull public <T> @NotNull ParameterResolver<A,T> resolver(@NotNull @NotNull java.lang.reflect.Type type, @NotNull @NotNull AnnotationList annotations)
ParameterType that can parse the given type
and annotations. This method can be used to create more complex parameter
types for composite types (such as T[])
Note that this method will never return null. In cases where no
suitable factory is found, it will throw IllegalArgumentException.
type - The type to create forannotations - The annotations to pass to factoriesjava.lang.IllegalStateException - if no suitable parameter type was found@NotNull public <T> @NotNull ParameterResolver<A,T> findNextResolver(@NotNull @NotNull java.lang.reflect.Type type, @NotNull @NotNull AnnotationList annotations, @NotNull @NotNull ParameterFactory skipPast)
ParameterType that comes after the skipPast
factory. This is useful for adding behavior on top of existing factory.type - The type to create forannotations - The annotations to pass to factoriesskipPast - The factory to skip past. In most cases, this will be the caller factory,
i.e. this.java.lang.IllegalStateException - if no suitable parameter type was found@NotNull public @NotNull SuggestionProvider<A> suggestionProvider(java.lang.reflect.Type type)
SuggestionProvider that can create suggestions
for the given type and annotations. This method can be used
to create more complex suggestion providers for composite types (such as T[])
Note that this method assumes the type has no annotations.
Note that this method will never return null. In cases where no
suitable provider is found, it will return SuggestionProvider.empty().
type - The type to create forSuggestionProvider.empty().@NotNull public @NotNull SuggestionProvider<A> suggestionProvider(java.lang.reflect.Type type, AnnotationList annotations)
SuggestionProvider that can create suggestions
for the given type and annotations. This method can be used
to create more complex suggestion providers for composite types (such as T[])
Note that this method will never return null. In cases where no
suitable provider is found, it will return SuggestionProvider.empty().
type - The type to create forannotations - The annotations to pass to factoriesSuggestionProvider.empty().@NotNull public @NotNull SuggestionProvider<A> suggestionProvider(CommandParameter parameter)
SuggestionProvider that can create suggestions
for the given parameter.
Note that this method will never return null. In cases
where no suitable provider is found, it will return SuggestionProvider.empty().
parameter - The parameter to create forSuggestionProvider.empty().public SuggestionProvider<A> findNextSuggestionProvider(java.lang.reflect.Type type, AnnotationList annotations, SuggestionProvider.Factory<? super A> skipPast, Lamp<A> lamp)
SuggestionProvider that comes after the skipPast
factory. This is useful for adding behavior on top of existing providers.type - The type to create forannotations - The annotations to pass to factoriesskipPast - The factory to skip past. In most cases, this will be the caller factory,
i.e. this.lamp - The Lamp instance to pass to factoriesSuggestionProvider.empty().@NotNull public <T> @NotNull ResponseHandler<A,T> responseHandler(@NotNull @NotNull java.lang.reflect.Type type, @NotNull @NotNull AnnotationList annotations)
ResponseHandler that can handle the given type
and annotation list.
Note that this method will never return null. In cases
where no suitable provider is found, it will return ResponseHandler.noOp().
type - The type to create forannotations - The annotations to pass to factoriesSuggestionProvider.empty().@NotNull public @NotNull @Unmodifiable java.util.List<ExecutableCommand<A>> register(java.lang.Object... instances)
orphan commands as well as Class objects.instances - The instance to registerpublic void unregister(@NotNull
@NotNull ExecutableCommand<A> execution)
execution - The command to unregister.public void unregisterAllCommands()
public void unregisterIf(@NotNull
@NotNull java.util.function.Predicate<ExecutableCommand<A>> commandPredicate)
public void dispatch(@NotNull
A actor,
java.lang.String input)
actor - The actor to send forinput - The input to execute withpublic void dispatch(@NotNull
A actor,
StringStream input)
actor - The actor to send forinput - The input to execute with@NotNull public @NotNull CommandRegistry<A> registry()
@NotNull public @Unmodifiable @NotNull java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Set<AnnotationReplacer<?>>> annotationReplacers()
Lamp instanceLamp.Builder.annotationReplacer(Class, AnnotationReplacer)@NotNull public @Unmodifiable @NotNull java.util.List<CommandCondition<? super A>> commandConditions()
Lamp instanceLamp.Builder.commandCondition(CommandCondition)@NotNull public @NotNull ParameterNamingStrategy parameterNamingStrategy()
Lamp instanceLamp.Builder.parameterNamingStrategy(ParameterNamingStrategy)@NotNull public @NotNull ParameterTypes<A> parameterTypes()
Lamp.Builder.parameterTypes()@NotNull public @NotNull SuggestionProviders<A> suggestionProviders()
Lamp.Builder.suggestionProviders()@NotNull public @NotNull Hooks<A> hooks()
Lamp.Builder.hooks()@NotNull public @Unmodifiable @NotNull java.util.List<SenderResolver<? super A>> senderResolvers()
Lamp instanceLamp.Builder.senderResolver(SenderResolver)@NotNull public @Unmodifiable @NotNull java.util.List<ParameterValidator<A,java.lang.Object>> parameterValidators()
Lamp instanceLamp.Builder.parameterValidator(Class, ParameterValidator)@NotNull
public <T> T dependency(@NotNull
@NotNull java.lang.Class<T> type)
IllegalStateExceptionT - The dependency typetype - The dependency typejava.lang.IllegalStateException - if no suitable dependency was found@ApiStatus.Internal public <T> void validate(A actor, T value, ParameterNode<A,T> parameter)
ParameterValidatorsactor - The actor to validate forvalue - The value to validateparameter - The parameter to validate for@NotNull public @NotNull AutoCompleter<A> autoCompleter()
AutoCompleter of this Lamp instancepublic void handleException(@NotNull
@NotNull java.lang.Throwable throwable,
@NotNull
@NotNull ErrorContext<A> errorContext)
exceptionHandlerthrowable - The exception to handleerrorContext - The context in which the error occurred. For example,
if the error was because a parameter was invalid, this
will be a ErrorContext.ParsingParameter context,
which contains information about the parameter being parsed.Lamp.Builder.exceptionHandler(CommandExceptionHandler)@NotNull public @NotNull CommandPermission<A> createPermission(AnnotationList annotations)
CommandPermission for the given list of annotations. Note
that this will never return null. If no suitable permission factory
was found, it will return CommandPermission.alwaysTrue().annotations - Annotations to check for@NotNull public @NotNull MessageSender<? super A,java.lang.String> messageSender()
MessageSender responsible for sending
messages using CommandActor.reply(String)@NotNull public @NotNull MessageSender<? super A,java.lang.String> errorSender()
MessageSender responsible for sending
messages using CommandActor.error(String)@NotNull public @NotNull DispatcherSettings<A> dispatcherSettings()
DispatcherSettings that are used by
Lamp under the hood to customize the dispatcher settings.DispatcherSettings@Contract(value="_ -> this") @NotNull public @NotNull Lamp<A> accept(@NotNull @NotNull LampVisitor<A> visitor)
LampVisitor.visit(Lamp) on
this Lamp instancevisitor - Visitor to accept