mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 03:57:50 +01:00
Comments for the optional argument support
This commit is contained in:
parent
0faaea2c1b
commit
82631fc6f8
@ -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
|
* 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.
|
* 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>
|
* <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.
|
* at the cost of many packet writing and compression.
|
||||||
*
|
*
|
||||||
* @return true if the packet caching feature is enabled, false otherwise
|
* @return true if the packet caching feature is enabled, false otherwise
|
||||||
|
@ -149,15 +149,38 @@ public abstract class Argument<T> {
|
|||||||
this.callback = callback;
|
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() {
|
public boolean isOptional() {
|
||||||
return defaultValue != null;
|
return defaultValue != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default value of this argument.
|
||||||
|
*
|
||||||
|
* @return the argument default value, null if the argument is not optional
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public T getDefaultValue() {
|
public T getDefaultValue() {
|
||||||
return defaultValue;
|
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
|
@NotNull
|
||||||
public Argument<T> setDefaultValue(@Nullable T defaultValue) {
|
public Argument<T> setDefaultValue(@Nullable T defaultValue) {
|
||||||
Check.argCondition(defaultValue != null && getConditionResult(defaultValue) != SUCCESS,
|
Check.argCondition(defaultValue != null && getConditionResult(defaultValue) != SUCCESS,
|
||||||
|
Loading…
Reference in New Issue
Block a user