parent
e9134efad6
commit
d8f0b1a47e
1 changed files with 17 additions and 0 deletions
|
|
@ -38,6 +38,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Command context used to assist in the parsing of commands
|
||||
|
|
@ -238,6 +239,22 @@ public final class CommandContext<C> {
|
|||
return this.<T>getOptional(key).orElse(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value if it exists, else return the value supplied by the given supplier
|
||||
*
|
||||
* @param key Argument key
|
||||
* @param defaultSupplier Supplier of default value
|
||||
* @param <T> Argument type
|
||||
* @return Argument, or supplied default value
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public <T> @Nullable T getOrDefault(
|
||||
final @NonNull String key,
|
||||
final @NonNull Supplier<@Nullable T> defaultSupplier
|
||||
) {
|
||||
return this.<T>getOptional(key).orElseGet(defaultSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw input. This should only be used when {@link #isSuggestions()} is {@code true}
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue