✨ Add flag support to the annotation system.
This commit is contained in:
parent
782f3023fc
commit
c67619e5da
9 changed files with 214 additions and 2 deletions
|
|
@ -680,6 +680,17 @@ public class Command<C> {
|
|||
Collections.unmodifiableList(flags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new command flag
|
||||
*
|
||||
* @param builder Flag builder. {@link CommandFlag.Builder#build()} will be invoked.
|
||||
* @param <T> Flag value type
|
||||
* @return New builder instance that uses the provided flag
|
||||
*/
|
||||
public @NonNull <T> Builder<C> flag(final CommandFlag.@NonNull Builder<T> builder) {
|
||||
return this.flag(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a command using the builder instance
|
||||
*
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ public final class CommandFlag<T> {
|
|||
/**
|
||||
* Get the flag description
|
||||
* <p>
|
||||
*
|
||||
* @return Flag description
|
||||
*/
|
||||
public @NonNull Description getDescription() {
|
||||
|
|
@ -179,6 +180,17 @@ public final class CommandFlag<T> {
|
|||
return new Builder<>(this.name, this.aliases, this.description, argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance using the given command argument
|
||||
*
|
||||
* @param builder Command argument builder. {@link CommandArgument.Builder#build()} will be invoked.
|
||||
* @param <N> New argument type
|
||||
* @return New builder instance
|
||||
*/
|
||||
public <N> Builder<N> withArgument(final CommandArgument.@NonNull Builder<?, N> builder) {
|
||||
return this.withArgument(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new command flag instance
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
package cloud.commandframework.arguments.flags;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -94,7 +95,7 @@ public final class FlagContext {
|
|||
* @param <T> Value type
|
||||
* @return Stored value, or the supplied default value
|
||||
*/
|
||||
public <T> T getValue(@NonNull final String name, @NonNull final T defaultValue) {
|
||||
public <T> @Nullable T getValue(@NonNull final String name, @Nullable final T defaultValue) {
|
||||
final Object value = this.flagValues.get(name);
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue