Class ArgumentWord
public class ArgumentWord extends Argument<java.lang.String>
You can specify the valid words with from(String...)
(do not abuse it or the client will not be able to join).
Example: hey
-
Field Summary
Fields Modifier and Type Field Description static int
RESTRICTION_ERROR
protected java.lang.String[]
restrictions
static int
SPACE_ERROR
Fields inherited from class net.minestom.server.command.builder.arguments.Argument
SUCCESS, UNDEFINED_ERROR
-
Constructor Summary
Constructors Constructor Description ArgumentWord(java.lang.String id)
-
Method Summary
Modifier and Type Method Description boolean
equals(java.lang.Object o)
ArgumentWord
from(java.lang.String... restrictions)
Used to force the use of a few precise words instead of complete freedom.int
getConditionResult(java.lang.String value)
Called afterArgument.parse(String)
meaning thatvalue
should already represent a valid representation of the input.int
getCorrectionResult(java.lang.String value)
First method called to check the validity of an input.java.lang.String[]
getRestrictions()
Gets all the word restrictions.int
hashCode()
boolean
hasRestrictions()
Gets if this argument allow complete freedom in the word choice or if a list has been defined.java.lang.String
parse(java.lang.String value)
Called afterArgument.getCorrectionResult(String)
returnedArgument.SUCCESS
.Methods inherited from class net.minestom.server.command.builder.arguments.Argument
allowSpace, getCallback, getId, hasErrorCallback, setCallback, useRemaining
-
Field Details
-
SPACE_ERROR
public static final int SPACE_ERROR- See Also:
- Constant Field Values
-
RESTRICTION_ERROR
public static final int RESTRICTION_ERROR- See Also:
- Constant Field Values
-
restrictions
protected java.lang.String[] restrictions
-
-
Constructor Details
-
ArgumentWord
public ArgumentWord(java.lang.String id)
-
-
Method Details
-
from
Used to force the use of a few precise words instead of complete freedom.WARNING: having an array too long would result in a packet too big or the client being stuck during login.
- Parameters:
restrictions
- the accepted words- Returns:
- 'this'
-
getCorrectionResult
public int getCorrectionResult(@NotNull java.lang.String value)Description copied from class:Argument
First method called to check the validity of an input.If
Argument.allowSpace()
is enabled, the value will be incremented by the next word until it returnsArgument.SUCCESS
, meaning that you need to be sure to check the inexpensive operations first (eg the number of brackets, the first and last char, etc...).- Specified by:
getCorrectionResult
in classArgument<java.lang.String>
- Parameters:
value
- The received argument- Returns:
- the error code or
Argument.SUCCESS
-
parse
@NotNull public java.lang.String parse(@NotNull java.lang.String value)Description copied from class:Argument
Called afterArgument.getCorrectionResult(String)
returnedArgument.SUCCESS
.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. -
getConditionResult
public int getConditionResult(@NotNull java.lang.String value)Description copied from class:Argument
Called afterArgument.parse(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...).
- Specified by:
getConditionResult
in classArgument<java.lang.String>
- Parameters:
value
- The parsed argument- Returns:
- the error code or
Argument.SUCCESS
-
hasRestrictions
public boolean hasRestrictions()Gets if this argument allow complete freedom in the word choice or if a list has been defined.- Returns:
- true if the word selection is restricted
-
getRestrictions
@Nullable public java.lang.String[] getRestrictions()Gets all the word restrictions.- Returns:
- the word restrictions, can be null
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-