diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bf8faeb..63e140b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added access to the CloudBrigadierManager from Brigadier-enabled command managers - - Added parameter injectors + - Added parameter injectors (cloud-annotations) - Store currently parsing command argument in the command context - Added a method to CloudBrigadierManager to enable or disable Brigadier native suggestions for specific argument types - Added a method to get the failure reason of SelectorParseExceptions + - Added some methods to FlagContext to work with flag values as optionals + - Allow for use of named suggestion providers with `@Flag`s (cloud-annotations) ### Changed - Allow for use of `@Completions` annotation with argument types other than String diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/Argument.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/Argument.java index e9fc1aef..398cdc8e 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/Argument.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/Argument.java @@ -23,6 +23,8 @@ // package cloud.commandframework.annotations; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -41,14 +43,14 @@ public @interface Argument { * * @return Argument name */ - String value(); + @NonNull String value(); /** * Name of the argument parser * * @return Argument name */ - String parserName() default ""; + @NonNull String parserName() default ""; /** * Name of the suggestions provider to use. If the string is left empty, the default @@ -64,20 +66,20 @@ public @interface Argument { * should be used instead * @since 1.1.0 */ - String suggestions() default ""; + @NonNull String suggestions() default ""; /** * Get the default value * * @return Default value */ - String defaultValue() default ""; + @NonNull String defaultValue() default ""; /** * The argument description * * @return Argument description */ - String description() default ""; + @NonNull String description() default ""; } diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandDescription.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandDescription.java index 2dc6cdf9..5e632c5f 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandDescription.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandDescription.java @@ -24,6 +24,7 @@ package cloud.commandframework.annotations; import cloud.commandframework.arguments.parser.StandardParameters; +import org.checkerframework.checker.nullness.qual.NonNull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -42,6 +43,6 @@ public @interface CommandDescription { * * @return Command syntax */ - String value() default ""; + @NonNull String value() default ""; } diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java index 69baf09d..4edc9d9e 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java @@ -23,6 +23,8 @@ // package cloud.commandframework.annotations; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -40,13 +42,13 @@ public @interface CommandMethod { * * @return Command syntax */ - String value(); + @NonNull String value(); /** * The required sender * * @return Required sender */ - Class> requiredSender() default Object.class; + @NonNull Class> requiredSender() default Object.class; } diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java index 907f421c..0f341f25 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java @@ -23,6 +23,8 @@ // package cloud.commandframework.annotations; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -40,6 +42,6 @@ public @interface CommandPermission { * * @return Command permission */ - String value() default ""; + @NonNull String value() default ""; } diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/Flag.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/Flag.java index de47def5..af9e461a 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/Flag.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/Flag.java @@ -23,15 +23,21 @@ // package cloud.commandframework.annotations; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.function.BiFunction; /** * Indicates that the parameter should be treated like a {@link cloud.commandframework.arguments.flags.CommandFlag}. - * If the parameter is a {@code boolean} then a presence flag will be created, else a value flag will be created - * and the parser will be resolved the same way as it would for a {@link Argument} + *
+ * For this to work, the suggestion needs to be registered in the parser registry. To do this, use
+ * {@link cloud.commandframework.arguments.parser.ParserRegistry#registerSuggestionProvider(String, BiFunction)}.
+ * The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#getParserRegistry()}.
+ *
+ * @return The name of the suggestion provider, or {@code ""} if the default suggestion provider for the argument parser
+ * should be used instead
+ * @since 1.2.0
+ */
+ @NonNull String suggestions() default "";
/**
* The argument description
*
* @return Argument description
*/
- String description() default "";
+ @NonNull String description() default "";
}
diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagExtractor.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagExtractor.java
index 18a369db..5054b9b0 100644
--- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagExtractor.java
+++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/FlagExtractor.java
@@ -37,6 +37,8 @@ import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.List;
+import java.util.function.BiFunction;
import java.util.function.Function;
final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNull CommandFlag>>> {
@@ -78,14 +80,25 @@ final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNu
parameter.getType().getCanonicalName(), flag.value(), method.getName()
));
}
- final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
+ final BiFunction, @NonNull String, @NonNull List