Package dev.jorel.commandapi.arguments
Class Argument<T>
java.lang.Object
dev.jorel.commandapi.ArgumentTree
dev.jorel.commandapi.arguments.Argument<T>
- Type Parameters:
T- The type of the underlying object that this argument casts to
- Direct Known Subclasses:
AdventureChatArgument,AdventureChatComponentArgument,BlockPredicateArgument,BlockStateArgument,ChatArgument,ChatComponentArgument,CustomArgument,EntitySelectorArgument,ItemStackPredicateArgument,ListArgument,LiteralArgument,MultiLiteralArgument,ObjectiveCriteriaArgument,SafeOverrideableArgument,ScoreHolderArgument,StringArgument,TextArgument
The core abstract class for Command API arguments
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CustomCommandExecutor<?>The CustomCommandExecutor for this executable implementation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClear all executors from the current command builderexecutes(CommandExecutor executor, ExecutorType... types) Adds an executor to the current command builderexecutes(ResultingCommandExecutor executor, ExecutorType... types) Adds an executor to the current command builderAdds an executor to the current command builderAdds an executor to the current command builderexecutesConsole(ConsoleCommandExecutor executor) Adds an executor to the current command builderAdds an executor to the current command builderexecutesEntity(EntityCommandExecutor executor) Adds an executor to the current command builderexecutesEntity(EntityResultingCommandExecutor executor) Adds an executor to the current command builderexecutesNative(NativeCommandExecutor executor) Adds an executor to the current command builderexecutesNative(NativeResultingCommandExecutor executor) Adds an executor to the current command builderexecutesPlayer(PlayerCommandExecutor executor) Adds an executor to the current command builderexecutesPlayer(PlayerResultingCommandExecutor executor) Adds an executor to the current command builderexecutesProxy(ProxyCommandExecutor executor) Adds an executor to the current command builderexecutesProxy(ProxyResultingCommandExecutor executor) Adds an executor to the current command builderfinal CommandPermissionReturns the permission required to run this commandabstract CommandAPIArgumentTypeReturns the argument type for this argument.getEntityNames(Object argument) Gets a list of entity names for the current provided argument.CustomCommandExecutor<? extends org.bukkit.command.CommandSender>Returns the executors that this command hasReturns an optional function which produces an array of suggestions which should be added to existing suggestions.final StringReturns the name of this argument's nodefinal Optional<ArgumentSuggestions>Returns an optional function that maps the command sender to an IStringTooltip array of suggestions for the current commandReturns the primitive type of the current Argument.final com.mojang.brigadier.arguments.ArgumentType<?>Returns the NMS or brigadier type for this argument.final Predicate<org.bukkit.command.CommandSender>Returns the requirements required to run this commandincludeSuggestions(ArgumentSuggestions suggestions) Include suggestions to add to the list of default suggestions represented by this argument.includeSuggestions(Function<SuggestionInfo, String[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.includeSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.useincludeSuggestions(ArgumentSuggestions)insteadbooleanisListed()Returns true if this argument will be listed in the Object args[] of the command executorabstract <CommandSourceStack>
TparseArgument(NMS<CommandSourceStack> nms, com.mojang.brigadier.context.CommandContext<CommandSourceStack> cmdCtx, String key, Object[] previousArgs) Parses an argument, returning the specific Bukkit object that the argument represents.replaceSuggestions(ArgumentSuggestions suggestions) Replace the suggestions of this argument.replaceSuggestions(Function<SuggestionInfo, String[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.usereplaceSuggestions(ArgumentSuggestions)insteadreplaceSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.usereplaceSuggestions(ArgumentSuggestions)insteadvoidsetExecutor(CustomCommandExecutor<? extends org.bukkit.command.CommandSender> executor) Sets the executors for this commandsetListed(boolean listed) Sets whether this argument will be listed in the Object args[] of the command executorwithPermission(CommandPermission permission) Assigns the given permission as a requirement to execute this command.withPermission(String permission) Assigns the given permission as a requirement to execute this command.withRequirement(Predicate<org.bukkit.command.CommandSender> requirement) Adds a requirement that has to be satisfied to use this argument.Methods inherited from class dev.jorel.commandapi.ArgumentTree
then
-
Field Details
-
executor
The CustomCommandExecutor for this executable implementation
-
-
Constructor Details
-
Argument
Constructs an argument with a given NMS/brigadier type.- Parameters:
nodeName- the name to assign to this argument noderawType- the NMS or brigadier type to be used for this argument
-
-
Method Details
-
getPrimitiveType
Returns the primitive type of the current Argument. After executing a command, this argument should yield an object of this returned class.- Returns:
- the type that this argument yields when the command is run
-
getArgumentType
Returns the argument type for this argument.- Returns:
- the argument type for this argument
-
getRawType
public final com.mojang.brigadier.arguments.ArgumentType<?> getRawType()Returns the NMS or brigadier type for this argument.- Returns:
- the NMS or brigadier type for this argument
-
getNodeName
Returns the name of this argument's node- Returns:
- the name of this argument's node
-
parseArgument
public abstract <CommandSourceStack> T parseArgument(NMS<CommandSourceStack> nms, com.mojang.brigadier.context.CommandContext<CommandSourceStack> cmdCtx, String key, Object[] previousArgs) throws com.mojang.brigadier.exceptions.CommandSyntaxException Parses an argument, returning the specific Bukkit object that the argument represents. This is intended for use by the internals of the CommandAPI and isn't expected to be used outside the CommandAPI- Type Parameters:
CommandSourceStack- the command source type- Parameters:
nms- an instance of NMScmdCtx- the context which ran this commandkey- the name of the argument nodepreviousArgs- an array of previously declared arguments- Returns:
- the parsed object represented by this argument
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- if parsing fails
-
includeSuggestions
Include suggestions to add to the list of default suggestions represented by this argument.- Parameters:
suggestions- AnArgumentSuggestionsobject representing the suggestions. Use the Static methods on ArgumentSuggestions to create these.- Returns:
- the current argument
-
includeSuggestions
@Deprecated(forRemoval=true) public Argument<T> includeSuggestions(Function<SuggestionInfo, String[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.useincludeSuggestions(ArgumentSuggestions)insteadInclude suggestions to add to the list of default suggestions represented by this argument.- Parameters:
suggestions- a function that takes in SuggestionInfo which includes information about the current state at the time the suggestions are run and returns a String[] of suggestions to add- Returns:
- the current argument
-
includeSuggestionsT
@Deprecated(forRemoval=true) public Argument<T> includeSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.useincludeSuggestions(ArgumentSuggestions)insteadInclude suggestions to add to the list of default suggestions represented by this argument.- Parameters:
suggestions- a function that takes in SuggestionInfo which includes information about the current state at the time the suggestions are run and returns an IStringTooltip[] of suggestions (with tooltips) to add- Returns:
- the current argument
-
getIncludedSuggestions
Returns an optional function which produces an array of suggestions which should be added to existing suggestions.- Returns:
- An Optional containing a function which generates suggestions
-
replaceSuggestions
Replace the suggestions of this argument.- Parameters:
suggestions- AnArgumentSuggestionsobject representing the suggestions. Use the static methods in ArgumentSuggestions to create these.- Returns:
- the current argument
-
replaceSuggestions
@Deprecated(forRemoval=true) public Argument<T> replaceSuggestions(Function<SuggestionInfo, String[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.usereplaceSuggestions(ArgumentSuggestions)insteadReplaces the suggestions of this argument with an array of suggestions.- Parameters:
suggestions- a function that takes inSuggestionInfoand returns aStringof suggestions- Returns:
- the current argument
-
replaceSuggestionsT
@Deprecated(forRemoval=true) public Argument<T> replaceSuggestionsT(Function<SuggestionInfo, IStringTooltip[]> suggestions) Deprecated, for removal: This API element is subject to removal in a future version.usereplaceSuggestions(ArgumentSuggestions)insteadReplaces the suggestions of this argument with an array of suggestions with tooltips.- Parameters:
suggestions- a function that takes inSuggestionInfoand returns aIStringTooltipof suggestions- Returns:
- the current argument
-
getOverriddenSuggestions
Returns an optional function that maps the command sender to an IStringTooltip array of suggestions for the current command- Returns:
- a function that provides suggestions, or
Optional.empty()if there are no overridden suggestions.
-
withPermission
Assigns the given permission as a requirement to execute this command.- Parameters:
permission- the permission required to execute this command- Returns:
- this current argument
-
withPermission
Assigns the given permission as a requirement to execute this command.- Parameters:
permission- the permission required to execute this command- Returns:
- this current argument
-
getArgumentPermission
Returns the permission required to run this command- Returns:
- the permission required to run this command
-
getRequirements
Returns the requirements required to run this command- Returns:
- the requirements required to run this command
-
withRequirement
Adds a requirement that has to be satisfied to use this argument. This method can be used multiple times and each use of this method will AND its requirement with the previously declared ones- Parameters:
requirement- the predicate that must be satisfied to use this argument- Returns:
- this current argument
-
isListed
public boolean isListed()Returns true if this argument will be listed in the Object args[] of the command executor- Returns:
- true if this argument will be listed in the Object args[] of the command executor
-
setListed
Sets whether this argument will be listed in the Object args[] of the command executor- Parameters:
listed- if true, this argument will be included in the Object args[] of the command executor- Returns:
- this current argument
-
getEntityNames
Gets a list of entity names for the current provided argument. This is expected to be implemented by EntitySelectorArgument, seeEntitySelectorArgument.getEntityNames(Object)- Parameters:
argument- a parsed (Bukkit) object representing the entity selector type. This is either a List, an Entity or a Player- Returns:
- a list of strings representing the names of the entity or entities
from
argument
-
executes
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(CommandSender, Object[]) -> ()that will be executed when the command is runtypes- A list of executor types to use this executes method for.- Returns:
- this command builder
-
executes
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(CommandSender, Object[]) -> intthat will be executed when the command is runtypes- A list of executor types to use this executes method for.- Returns:
- this command builder
-
executesPlayer
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(Player, Object[]) -> ()that will be executed when the command is run- Returns:
- this command builder
-
executesPlayer
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(Player, Object[]) -> intthat will be executed when the command is run- Returns:
- this command builder
-
executesEntity
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(Entity, Object[]) -> ()that will be executed when the command is run- Returns:
- this command builder
-
executesEntity
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(Entity, Object[]) -> intthat will be executed when the command is run- Returns:
- this command builder
-
executesProxy
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(Entity, Object[]) -> ()that will be executed when the command is run- Returns:
- this command builder
-
executesProxy
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(Entity, Object[]) -> intthat will be executed when the command is run- Returns:
- this command builder
-
executesCommandBlock
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(BlockCommandSender, Object[]) -> ()that will be executed when the command is run- Returns:
- this command builder
-
executesCommandBlock
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(BlockCommandSender, Object[]) -> intthat will be executed when the command is run- Returns:
- this command builder
-
executesConsole
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(BlockCommandSender, Object[]) -> ()that will be executed when the command is run- Returns:
- this command builder
-
executesConsole
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(BlockCommandSender, Object[]) -> intthat will be executed when the command is run- Returns:
- this command builder
-
executesNative
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(NativeCommandExecutor, Object[]) -> ()that will be executed when the command is run- Returns:
- this command builder
-
executesNative
Adds an executor to the current command builder- Parameters:
executor- A lambda of type(NativeCommandExecutor, Object[]) -> intthat will be executed when the command is run- Returns:
- this command builder
-
getExecutor
Returns the executors that this command has- Returns:
- the executors that this command has
-
setExecutor
Sets the executors for this command- Parameters:
executor- the executors for this command
-
clearExecutors
Clear all executors from the current command builder- Returns:
- this command builder
-
includeSuggestions(ArgumentSuggestions)instead