Package dev.jorel.commandapi.arguments
Class AbstractArgument<T,Impl extends AbstractArgument<T,Impl,Argument,CommandSender>,Argument extends AbstractArgument<?,?,Argument,CommandSender>,CommandSender>
java.lang.Object
dev.jorel.commandapi.AbstractArgumentTree<Impl,Argument,CommandSender>
dev.jorel.commandapi.arguments.AbstractArgument<T,Impl,Argument,CommandSender>
- Type Parameters:
T- The type of the underlying object that this argument casts toImpl- The class extending this class, used as the return type for chain callsArgument- The implementation of Argument used by the class extending this classCommandSender- The CommandSender class used by the class extending this class
- All Implemented Interfaces:
ChainableBuilder<Impl>
public abstract class AbstractArgument<T,Impl extends AbstractArgument<T,Impl,Argument,CommandSender>,Argument extends AbstractArgument<?,?,Argument,CommandSender>,CommandSender>
extends AbstractArgumentTree<Impl,Argument,CommandSender>
The core abstract class for Command API arguments
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CommandAPIExecutor<CommandSender, AbstractCommandSender<? extends CommandSender>> The CommandAPIExecutor for this executable implementation -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractArgument(String nodeName, com.mojang.brigadier.arguments.ArgumentType<?> rawType) Constructs an argument with a given NMS/brigadier type. -
Method Summary
Modifier and TypeMethodDescriptionClear all executors from the current command builderfinal ImplcombineWith(Argument... combinedArguments) Adds combined arguments to this argument.voidcopyPermissionsAndRequirements(Argument argument) Copies permissions and requirements from the provided argument to this argument This also resets additional permissions and requirements.final CommandPermissionReturns the permission required to run this commandabstract CommandAPIArgumentTypeReturns the argument type for this argument.Returns a list of arguments linked to this argument.getEntityNames(Object argument) Gets a list of entity names for the current provided argument.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<CommandSender>> 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<CommandSender> Returns the requirements required to run this commandbooleanReturns true if this argument has linked arguments.includeSuggestions(ArgumentSuggestions<CommandSender> suggestions) Include suggestions to add to the list of default suggestions represented by this argument.booleanisListed()Returns true if this argument will be listed in the Object args[] of the command executorbooleanReturns true if this argument will be optional when executing the command this argument is included inabstract <Source> TparseArgument(com.mojang.brigadier.context.CommandContext<Source> cmdCtx, String key, CommandArguments previousArgs) Parses an argument, returning the specific Bukkit object that the argument represents.replaceSuggestions(ArgumentSuggestions<CommandSender> suggestions) Replace the suggestions of this argument.voidsetExecutor(CommandAPIExecutor<CommandSender, AbstractCommandSender<? extends CommandSender>> executor) Sets the executors for this commandsetListed(boolean listed) Sets whether this argument will be listed in the Object args[] of the command executorsetOptional(boolean optional) Sets whether this argument will be optional when executing the command this argument is included intoString()final ImplwithPermission(CommandPermission permission) Assigns the given permission as a requirement to execute this command.final ImplwithPermission(String permission) Assigns the given permission as a requirement to execute this command.final ImplwithRequirement(Predicate<CommandSender> requirement) Adds a requirement that has to be satisfied to use this argument.Methods inherited from class dev.jorel.commandapi.AbstractArgumentTree
then, thenNested, thenNestedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface dev.jorel.commandapi.ChainableBuilder
instance
-
Field Details
-
executor
The CommandAPIExecutor for this executable implementation
-
-
Constructor Details
-
AbstractArgument
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
-
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 <Source> T parseArgument(com.mojang.brigadier.context.CommandContext<Source> cmdCtx, String key, CommandArguments 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:
Source- the command source type- Parameters:
cmdCtx- the context which ran this commandkey- the name of the argument nodepreviousArgs- aCommandArgumentsobject holding previous parsed 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
-
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
-
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
-
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
-
isOptional
public boolean isOptional()Returns true if this argument will be optional when executing the command this argument is included in- Returns:
- true if this argument will be optional when executing the command this argument is included in
-
setOptional
Sets whether this argument will be optional when executing the command this argument is included in- Parameters:
optional- if true, this argument will be optional when executing the command this argument is included in- Returns:
- this current argument
-
getCombinedArguments
-
hasCombinedArguments
public boolean hasCombinedArguments()Returns true if this argument has linked arguments.- Returns:
- true if this argument has linked arguments
-
combineWith
Adds combined arguments to this argument. Combined arguments are used to have required arguments after optional arguments by ignoring they exist until they are added to the arguments array for registration. This method also causes permissions and requirements from this argument to be copied over to the arguments you want to combine this argument with. Their permissions and requirements will be ignored.- Parameters:
combinedArguments- The arguments to combine to this argument- Returns:
- this current argument
-
getEntityNames
Gets a list of entity names for the current provided argument. This is expected to be implemented byEntitySelectorArgumentin Bukkit, 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
-
copyPermissionsAndRequirements
Copies permissions and requirements from the provided argument to this argument This also resets additional permissions and requirements.- Parameters:
argument- The argument to copy permissions and requirements from
-
getHelpString
-
toString
-
getExecutor
public CommandAPIExecutor<CommandSender,AbstractCommandSender<? extends CommandSender>> getExecutor()Returns the executors that this command has- Returns:
- the executors that this command has
-
setExecutor
public void setExecutor(CommandAPIExecutor<CommandSender, AbstractCommandSender<? extends CommandSender>> executor) 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
-