Context parameters
Context resolvers allow for dynamic resolution of context-specific values into command parameters, enabling commands to adapt based on the environment or actor state.
Overview
ContextParameter is a functional interface that allows you to resolve parameters based on the context of the command execution. This can be useful for extracting complex types or values from the command context.
ContextParameter Interface
The ContextParameter interface is used to define how a parameter should be resolved from the command context.
@FunctionalInterface
public interface ContextParameter<A extends CommandActor, T> {
/**
* Reads input from the given {@link MutableStringStream}, parses the object, or throws
* exceptions if needed.
*
* @param parameter The parameter
* @param context The command execution context, as well as arguments that have been resolved
* @return The parsed object. This should never be null.
*/
T resolve(@NotNull CommandParameter parameter, @NotNull ExecutionContext<A> context);
}ContextParameter.Factory Interface
The ContextParameter.Factory interface is used to create ContextParameter instances dynamically. It is helpful for creating custom parameter types.
Example: PlayerWorldContextParameterFactory
Here is an example of a ContextParameter.Factory that resolves a World from the Player context:
Registering ContextParameter.Factory
You can register a ContextParameter.Factory with the Lamp builder to handle custom parameter types.
Last updated
Was this helpful?