mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Add CommandContext#getOrDefault
This commit is contained in:
parent
2b17edfc46
commit
bb1f4a3792
@ -44,10 +44,16 @@ public class CommandContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> T get(@NotNull String identifier) {
|
public <T> T get(@NotNull String identifier) {
|
||||||
return (T) args.computeIfAbsent(identifier, s -> {
|
return (T) args.get(identifier);
|
||||||
throw new NullPointerException(
|
}
|
||||||
"The argument with the id '" + identifier + "' has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
|
||||||
});
|
public <T> T getOrDefault(@NotNull Argument<T> argument, T defaultValue) {
|
||||||
|
return getOrDefault(argument.getId(), defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getOrDefault(@NotNull String identifier, T defaultValue) {
|
||||||
|
T value;
|
||||||
|
return (value = get(identifier)) != null ? value : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean has(@NotNull Argument<?> argument) {
|
public boolean has(@NotNull Argument<?> argument) {
|
||||||
|
Loading…
Reference in New Issue
Block a user