Class Argument<T>
- Type Parameters:
T
- the type of this parsed argument
- Direct Known Subclasses:
ArgumentBoolean
,ArgumentColor
,ArgumentDynamicStringArray
,ArgumentDynamicWord
,ArgumentEntities
,ArgumentItemStack
,ArgumentNbtCompoundTag
,ArgumentNbtTag
,ArgumentNumber
,ArgumentRange
,ArgumentRegistry
,ArgumentRelative
,ArgumentString
,ArgumentStringArray
,ArgumentTime
,ArgumentWord
public abstract class Argument<T>
extends java.lang.Object
Command
's syntax with Command.addSyntax(CommandExecutor, Argument[])
.
You can create your own with your own special conditions.
Here in order, how is parsed an argument: getCorrectionResult(String)
to check
if the syntax is correct, parse(String)
to convert the correct argument
and getConditionResult(Object)
to verify that the parsed object validate the additional
conditions.
-
Field Summary
Fields Modifier and Type Field Description static int
SUCCESS
static int
UNDEFINED_ERROR
-
Constructor Summary
Constructors Constructor Description Argument(java.lang.String id)
Creates a new argument withuseRemaining
andallowSpace
sets to false.Argument(java.lang.String id, boolean allowSpace)
Creates a new argument withuseRemaining
sets to false.Argument(java.lang.String id, boolean allowSpace, boolean useRemaining)
Creates a new argument. -
Method Summary
Modifier and Type Method Description boolean
allowSpace()
Gets if the argument can contain space.ArgumentCallback
getCallback()
Gets theArgumentCallback
to check if the argument-specific conditions are validated or not.abstract int
getConditionResult(T value)
Called afterparse(String)
meaning thatvalue
should already represent a valid representation of the input.abstract int
getCorrectionResult(java.lang.String value)
First method called to check the validity of an input.java.lang.String
getId()
Gets the ID of the argument, showed in-game above the chat bar and used to retrieve the data when the command is parsed inArguments
.boolean
hasErrorCallback()
Gets if the argument has any error callback.abstract T
parse(java.lang.String value)
Called aftergetCorrectionResult(String)
returnedSUCCESS
.void
setCallback(ArgumentCallback callback)
Sets theArgumentCallback
.boolean
useRemaining()
Gets if the argument always use all the remaining characters.
-
Field Details
-
SUCCESS
public static final int SUCCESS- See Also:
- Constant Field Values
-
UNDEFINED_ERROR
public static final int UNDEFINED_ERROR- See Also:
- Constant Field Values
-
-
Constructor Details
-
Argument
public Argument(@NotNull java.lang.String id, boolean allowSpace, boolean useRemaining)Creates a new argument.- Parameters:
id
- the id of the argument, used to retrieve the parsed valueallowSpace
- true if the argument can/should have spaces in ituseRemaining
- true if the argument will always take the rest of the command arguments
-
Argument
public Argument(@NotNull java.lang.String id, boolean allowSpace)Creates a new argument withuseRemaining
sets to false.- Parameters:
id
- the id of the argument, used to retrieve the parsed valueallowSpace
- true if the argument can/should have spaces in it
-
Argument
public Argument(@NotNull java.lang.String id)Creates a new argument withuseRemaining
andallowSpace
sets to false.- Parameters:
id
- the id of the argument, used to retrieve the parsed value
-
-
Method Details
-
getCorrectionResult
public abstract int getCorrectionResult(@NotNull java.lang.String value)First method called to check the validity of an input.If
allowSpace()
is enabled, the value will be incremented by the next word until it returnsSUCCESS
, meaning that you need to be sure to check the inexpensive operations first (eg the number of brackets, the first and last char, etc...).- Parameters:
value
- The received argument- Returns:
- the error code or
SUCCESS
-
parse
Called aftergetCorrectionResult(String)
returnedSUCCESS
.The correction being correct means that
value
shouldn't be verified again, you can assume that no exception will occur when converting it to the correct type.- Parameters:
value
- The correct argument which does not need to be verified again- Returns:
- The parsed argument
-
getConditionResult
Called afterparse(String)
meaning thatvalue
should already represent a valid representation of the input.The condition result has for goal to check the optional conditions that are user configurable (eg min/max values for a number, a specific material for an item, etc...).
- Parameters:
value
- The parsed argument- Returns:
- the error code or
SUCCESS
-
getId
@NotNull public java.lang.String getId()Gets the ID of the argument, showed in-game above the chat bar and used to retrieve the data when the command is parsed inArguments
.- Returns:
- the argument id
-
allowSpace
public boolean allowSpace()Gets if the argument can contain space.- Returns:
- true if the argument allows space, false otherwise
-
useRemaining
public boolean useRemaining()Gets if the argument always use all the remaining characters.ex: /help I am a test - will always give you "I am a test" if the first and single argument does use the remaining.
- Returns:
- true if the argument use all the remaining characters, false otherwise
-
getCallback
Gets theArgumentCallback
to check if the argument-specific conditions are validated or not.- Returns:
- the argument callback, null if not any
-
setCallback
Sets theArgumentCallback
.- Parameters:
callback
- the argument callback, null to do not have one
-
hasErrorCallback
public boolean hasErrorCallback()Gets if the argument has any error callback.- Returns:
- true if the argument has an error callback, false otherwise
-