Comments for the optional argument support

This commit is contained in:
themode 2021-01-02 16:09:20 +01:00
parent 0faaea2c1b
commit 82631fc6f8
2 changed files with 25 additions and 1 deletions

View File

@ -551,7 +551,8 @@ public final class MinecraftServer {
* This feature allows some packets (implementing the {@link net.minestom.server.utils.cache.CacheablePacket} to be cached
* in order to do not have to be written and compressed over and over again), this is especially useful for chunk and light packets.
* <p>
* It is enabled by default and it is our recommendation, you should only disable it if you want to focus on low memory usage
* It is enabled by default and it is our recommendation,
* you should only disable it if you want to focus on low memory usage
* at the cost of many packet writing and compression.
*
* @return true if the packet caching feature is enabled, false otherwise

View File

@ -149,15 +149,38 @@ public abstract class Argument<T> {
this.callback = callback;
}
/**
* Gets if this argument is 'optional'.
* <p>
* Optional means that this argument can be put at the end of a syntax
* and obtains a default value ({@link #getDefaultValue()}).
*
* @return true if this argument is considered optional
*/
public boolean isOptional() {
return defaultValue != null;
}
/**
* Gets the default value of this argument.
*
* @return the argument default value, null if the argument is not optional
*/
@Nullable
public T getDefaultValue() {
return defaultValue;
}
/**
* Sets the default value of the argument.
* <p>
* A non-null value means that the argument can be put at the end of a syntax
* to act as an optional one.
*
* @param defaultValue the default argument value, null to make the argument non-optional
* @return 'this' for chaining
* @throws IllegalArgumentException if {@code defaultValue} does not validate {@link #getConditionResult(Object)}
*/
@NotNull
public Argument<T> setDefaultValue(@Nullable T defaultValue) {
Check.argCondition(defaultValue != null && getConditionResult(defaultValue) != SUCCESS,