Interface CommandContext
- 
- All Superinterfaces:
- Contextual,- Subject,- SubjectProxy
 - All Known Subinterfaces:
- CommandContext.Builder
 
 public interface CommandContext extends SubjectProxy TheCommandContextcontains the parsed arguments for a command, and any other information that might be important when executing a command.For information about the cause of the command, the CommandCauseis available (seecause(). Some popular tasks that operate on theCommandCauseare also directly available on this context, namely permission checks (viaSubjectProxy) and sending a message to theCommandCause'sAudience(viasendMessage(net.kyori.adventure.identity.Identified, net.kyori.adventure.text.Component)).
- 
- 
Nested Class SummaryNested Classes Modifier and Type Interface Description static interfaceCommandContext.BuilderA builder for creating this context.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Collection<? extends T>all(Parameter.Key<T> key)Gets all values for the given argument.<T> Collection<? extends T>all(Parameter.Value<T> parameter)Gets all values for the given argument.CommandCausecause()Gets theCommandCauseassociated with this context.Optional<Command.Parameterized>executedCommand()Gets theCommand.Parameterizedthat is being executed, if it exists.intflagInvocationCount(String flagKey)Returns how many times a given flag was invoked for this command.intflagInvocationCount(Flag flag)Returns how many times a givenFlagwas invoked for this command.booleanhasAny(Parameter.Key<?> key)Returns whether this context has any value for the given argument key.booleanhasAny(Parameter.Value<?> parameter)Returns whether this context has any value for the given argument key.booleanhasFlag(String flagAlias)Gets if a flag with given alias was specified at least once.booleanhasFlag(Flag flag)Gets if the given flag was specified once.<T> Optional<T>one(Parameter.Key<T> key)Gets the value for the given key if the key has only one value.<T> Optional<T>one(Parameter.Value<T> parameter)Gets the value for the given key if the key has only one value.<T> TrequireOne(Parameter.Key<T> key)Gets the value for the given key if the key has only one value, otherwise, throws aNoSuchElementException.<T> TrequireOne(Parameter.Value<T> parameter)Gets the value for the given key if the key has only one value, otherwise, throws aNoSuchElementException.voidsendMessage(Identified source, Component message)Sends a message viaCommandCause.audience()voidsendMessage(Identity source, Component message)Sends a message viaCommandCause.audience()- 
Methods inherited from interface org.spongepowered.api.service.permission.SubjectProxyassociatedObject, asSubjectReference, containingCollection, contextCause, friendlyIdentifier, hasPermission, hasPermission, hasPermission, identifier, isChildOf, isChildOf, isChildOf, isSubjectDataPersisted, option, option, option, parents, parents, parents, permissionValue, permissionValue, permissionValue, subject, subjectData, transientSubjectData
 
- 
 
- 
- 
- 
Method Detail- 
executedCommandOptional<Command.Parameterized> executedCommand() Gets theCommand.Parameterizedthat is being executed, if it exists.- Returns:
- The Command.Parameterized.
 
 - 
causeCommandCause cause() Gets theCommandCauseassociated with this context.- Returns:
- The CommandCause
 
 - 
hasFlagboolean hasFlag(String flagAlias) Gets if a flag with given alias was specified at least once.If the flag has multiple aliases, (for example, -fand--flag, passingforflagto this method will return the same result, regardless of the alias specified by the user.- Parameters:
- flagAlias- The flag's alias (without a prefixed dash)
- Returns:
- If the flag was specified
 
 - 
hasFlagboolean hasFlag(Flag flag) Gets if the given flag was specified once.- Parameters:
- flag- The- Flag
- Returns:
- If the flag was specified
 
 - 
flagInvocationCountint flagInvocationCount(String flagKey) Returns how many times a given flag was invoked for this command.If the flag has multiple aliases, (for example, -fand--flag, passingforflagto this method will return the same result, regardless of the alias specified by the user.- Parameters:
- flagKey- The flag's alias (without a prefixed dash)
- Returns:
- The number of times the flag was specified
 
 - 
flagInvocationCountint flagInvocationCount(Flag flag) Returns how many times a givenFlagwas invoked for this command.- Parameters:
- flag- The- Flag
- Returns:
- The number of times the flag was specified
 
 - 
hasAnyboolean hasAny(Parameter.Value<?> parameter) Returns whether this context has any value for the given argument key.- Parameters:
- parameter- the- Parameterassociated with the argument
- Returns:
- whether there are any values present
 
 - 
hasAnyboolean hasAny(Parameter.Key<?> key) Returns whether this context has any value for the given argument key.- Parameters:
- key- The key to look up
- Returns:
- whether there are any values present
 
 - 
one<T> Optional<T> one(Parameter.Value<T> parameter) throws IllegalArgumentException Gets the value for the given key if the key has only one value.- Type Parameters:
- T- the expected type of the argument
- Parameters:
- parameter- the- Parameterassociated with the argument
- Returns:
- the argument
- Throws:
- IllegalArgumentException- if more than one value for the key was found
 
 - 
one<T> Optional<T> one(Parameter.Key<T> key) throws IllegalArgumentException Gets the value for the given key if the key has only one value.- Type Parameters:
- T- the expected type of the argument
- Parameters:
- key- the key to get
- Returns:
- the argument
- Throws:
- IllegalArgumentException- if more than one value for the key was found
 
 - 
requireOne<T> T requireOne(Parameter.Value<T> parameter) throws NoSuchElementException, IllegalArgumentException Gets the value for the given key if the key has only one value, otherwise, throws aNoSuchElementException.- Type Parameters:
- T- the expected type of the argument
- Parameters:
- parameter- the- Parameterassociated with the argument
- Returns:
- the argument
- Throws:
- NoSuchElementException- if no value for the key was found
- IllegalArgumentException- if more than one value for the key was found
 
 - 
requireOne<T> T requireOne(Parameter.Key<T> key) throws NoSuchElementException, IllegalArgumentException Gets the value for the given key if the key has only one value, otherwise, throws aNoSuchElementException.- Type Parameters:
- T- the expected type of the argument
- Parameters:
- key- the key to get
- Returns:
- the argument
- Throws:
- NoSuchElementException- if no value for the key was found
- IllegalArgumentException- if more than one value for the key was found
 
 - 
all<T> Collection<? extends T> all(Parameter.Value<T> parameter) Gets all values for the given argument. May return an empty list if no values are present.- Type Parameters:
- T- the expected type of the argument
- Parameters:
- parameter- the- Parameterassociated with the argument
- Returns:
- the argument
 
 - 
all<T> Collection<? extends T> all(Parameter.Key<T> key) Gets all values for the given argument. May return an empty list if no values are present.- Type Parameters:
- T- the type of value to get
- Parameters:
- key- The key to get values for
- Returns:
- the collection of all values
 
 - 
sendMessagevoid sendMessage(Identified source, Component message) Sends a message viaCommandCause.audience()- Parameters:
- source- The- Identifiedthat is the sender of the message
- message- The message to send
- See Also:
- Audience.sendMessage(Identified, Component)
 
 - 
sendMessagevoid sendMessage(Identity source, Component message) Sends a message viaCommandCause.audience()- Parameters:
- source- The- Identityof the sender of the message
- message- The message to send
- See Also:
- Audience.sendMessage(Identity, Component)
 
 
- 
 
-