Package org.incendo.cloud.context
Class CommandContext<C>
java.lang.Object
org.incendo.cloud.context.CommandContext<C>
- Type Parameters:
C- command sender type
- All Implemented Interfaces:
CloudKeyContainer,MutableCloudKeyContainer
@API(status=STABLE)
public class CommandContext<C>
extends Object
implements MutableCloudKeyContainer
Command context used to assist in the parsing of commands
-
Constructor Summary
ConstructorsConstructorDescriptionCommandContext(boolean suggestions, @NonNull C commandSender, @NonNull CommandManager<C> commandManager) Creates a new command context instance.CommandContext(@NonNull C commandSender, @NonNull CommandManager<C> commandManager) Creates a new command context instance. -
Method Summary
Modifier and TypeMethodDescriptionall()Returns all stored values.command()Returns the currentCommand.voidSets the currentCommand.<T> TReturns the value associated with the givenkeyif it exists, else computes and stores the value returned by the givendefaultFunctionand then returns it.booleanReturns whether the registry contains a value associated with the givenkey.createParsingContext(@NonNull CommandComponent<C> component) Creates a parsing context instance for the given component.flags()Returns the associatedFlagContextinstance.<T> @NonNull TformatCaption(@NonNull CaptionFormatter<C, T> formatter, @NonNull Caption caption, @NonNull List<@NonNull CaptionVariable> variables) Formats acaptionusing the givenformatter.<T> @NonNull TformatCaption(@NonNull CaptionFormatter<C, T> formatter, @NonNull Caption caption, @NonNull CaptionVariable @NonNull ... variables) Formats acaptionusing the givenformatter.formatCaption(@NonNull Caption caption, @NonNull List<@NonNull CaptionVariable> variables) Formats acaptionusing theCommandManager.captionFormatter().formatCaption(@NonNull Caption caption, @NonNull CaptionVariable @NonNull ... variables) Formats acaptionusing theCommandManager.captionFormatter().booleanhasPermission(@NonNull String permission) Checks whether the sender that executed the command has a permission.booleanhasPermission(@NonNull Permission permission) Checks whether the sender that executed the command has a permission.Attempts to retrieve a value that has been registered to the associated command manager'sParameterInjectorRegistry.Attempts to retrieve a value that has been registered to the associated command manager'sParameterInjectorRegistry.booleanChecks if this context was created for tab completion purposes.Returns the value associated with the givenkey.Returns the value associated with the givenkey.parsingContext(int position) Returns the context for the component at the given position.parsingContext(String name) Returns the context for the component with the given name.parsingContext(@NonNull CommandComponent<C> component) Returns the context for the given component.Returns an unmodifiable view of the stored parsing contexts.rawInput()Returns a copy of the raw input.voidRemoves value associated with the givenkey.sender()Returns the sender that executed the command.Stores thekey-valuepair.Stores thekey-valuepair.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.incendo.cloud.key.CloudKeyContainer
contains, contains, get, get, get, getOrDefault, getOrDefault, getOrDefault, getOrSupplyDefault, getOrSupplyDefault, getOrSupplyDefault, optionalMethods inherited from interface org.incendo.cloud.key.MutableCloudKeyContainer
computeIfAbsent, remove, remove, set, set, set, store
-
Constructor Details
-
CommandContext
@API(status=STABLE) public CommandContext(@NonNull C commandSender, @NonNull CommandManager<C> commandManager) Creates a new command context instance.- Parameters:
commandSender- the sender of the commandcommandManager- command manager
-
CommandContext
@API(status=STABLE) public CommandContext(boolean suggestions, @NonNull C commandSender, @NonNull CommandManager<C> commandManager) Creates a new command context instance.- Parameters:
suggestions- whether the context is created for command suggestionscommandSender- the sender of the commandcommandManager- command manager
-
-
Method Details
-
formatCaption
public @NonNull String formatCaption(@NonNull Caption caption, @NonNull CaptionVariable @NonNull ... variables) Formats acaptionusing theCommandManager.captionFormatter().- Parameters:
caption- the caption keyvariables- the variables to use during formatting- Returns:
- the formatted caption
-
formatCaption
public @NonNull String formatCaption(@NonNull Caption caption, @NonNull List<@NonNull CaptionVariable> variables) Formats acaptionusing theCommandManager.captionFormatter().- Parameters:
caption- the caption keyvariables- the variables to use during formatting- Returns:
- the formatted caption
-
formatCaption
public <T> @NonNull T formatCaption(@NonNull CaptionFormatter<C, T> formatter, @NonNull Caption caption, @NonNull CaptionVariable @NonNull ... variables) Formats acaptionusing the givenformatter.- Type Parameters:
T- the message type produced by the formatter- Parameters:
formatter- the formattercaption- the caption keyvariables- the variables to use during formatting- Returns:
- the formatted caption
-
formatCaption
public <T> @NonNull T formatCaption(@NonNull CaptionFormatter<C, T> formatter, @NonNull Caption caption, @NonNull List<@NonNull CaptionVariable> variables) Formats acaptionusing the givenformatter.- Type Parameters:
T- the message type produced by the formatter- Parameters:
formatter- the formattercaption- the caption keyvariables- the variables to use during formatting- Returns:
- the formatted caption
-
sender
Returns the sender that executed the command.- Returns:
- the command sender
-
hasPermission
Checks whether the sender that executed the command has a permission.- Parameters:
permission- the permission- Returns:
trueif thesender()has the permission, elsefalse
-
hasPermission
Checks whether the sender that executed the command has a permission.- Parameters:
permission- the permission- Returns:
trueif thesender()has the permission, elsefalse
-
isSuggestions
public boolean isSuggestions()Checks if this context was created for tab completion purposes.- Returns:
trueif this context is requesting suggestions, elsefalse
-
store
Stores thekey-valuepair.This will overwrite any existing value stored with the same
key.- Specified by:
storein interfaceMutableCloudKeyContainer- Type Parameters:
T- the type of the value- Parameters:
key- the keyvalue- the value
-
store
Stores thekey-valuepair.This will overwrite any existing value stored with the same
key.- Specified by:
storein interfaceMutableCloudKeyContainer- Type Parameters:
T- the type of the value- Parameters:
key- the keyvalue- the value
-
contains
Returns whether the registry contains a value associated with the givenkey.- Specified by:
containsin interfaceCloudKeyContainer- Parameters:
key- the key- Returns:
trueif the value exists, orfalseif it does not
-
optional
Returns the value associated with the givenkey.- Specified by:
optionalin interfaceCloudKeyContainer- Type Parameters:
T- the type of the value- Parameters:
key- the key- Returns:
- the value
-
optional
Returns the value associated with the givenkey.- Specified by:
optionalin interfaceCloudKeyContainer- Type Parameters:
T- the type of the value- Parameters:
key- the key- Returns:
- the value
-
remove
Removes value associated with the givenkey.- Specified by:
removein interfaceMutableCloudKeyContainer- Parameters:
key- the key
-
computeIfAbsent
public <T> T computeIfAbsent(@NonNull CloudKey<T> key, @NonNull Function<CloudKey<T>, T> defaultFunction) Returns the value associated with the givenkeyif it exists, else computes and stores the value returned by the givendefaultFunctionand then returns it.- Specified by:
computeIfAbsentin interfaceMutableCloudKeyContainer- Type Parameters:
T- the type of the value- Parameters:
key- the keydefaultFunction- the function used to generate the value in case it's missing- Returns:
- the present or computed value
-
rawInput
Returns a copy of the raw input.- Returns:
- raw input
-
createParsingContext
@API(status=MAINTAINED) public @NonNull ParsingContext<C> createParsingContext(@NonNull CommandComponent<C> component) Creates a parsing context instance for the given component.- Parameters:
component- the component- Returns:
- the created context
-
parsingContext
@API(status=MAINTAINED) public @NonNull ParsingContext<C> parsingContext(@NonNull CommandComponent<C> component) Returns the context for the given component.- Parameters:
component- the component- Returns:
- the context
-
parsingContext
Returns the context for the component at the given position.- Parameters:
position- the position- Returns:
- the context
-
parsingContext
Returns the context for the component with the given name.- Parameters:
name- the name- Returns:
- the context
-
parsingContexts
Returns an unmodifiable view of the stored parsing contexts.- Returns:
- the contexts
-
flags
Returns the associatedFlagContextinstance.- Returns:
- flag context
-
command
Returns the currentCommand. This is only available fromCommandExecutionHandlers andCommandPostprocessors.- Returns:
- the current command
-
command
Sets the currentCommand.- Parameters:
command- the command
-
inject
Attempts to retrieve a value that has been registered to the associated command manager'sParameterInjectorRegistry.- Type Parameters:
T- type to inject- Parameters:
clazz- class of type to inject- Returns:
- optional that may contain the created value
-
inject
Attempts to retrieve a value that has been registered to the associated command manager'sParameterInjectorRegistry.- Type Parameters:
T- type to inject- Parameters:
type- type to inject- Returns:
- optional that may contain the created value
-
all
Description copied from interface:CloudKeyContainerReturns all stored values.- Specified by:
allin interfaceCloudKeyContainer- Returns:
- immutable view of all values
-