🚚 More removal of javax annotations
This commit is contained in:
parent
4556b392b0
commit
26f11e3a7e
47 changed files with 594 additions and 691 deletions
|
|
@ -36,9 +36,9 @@ import cloud.commandframework.meta.CommandMeta;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
|
|
@ -75,9 +75,9 @@ public final class AnnotationParser<C> {
|
||||||
* {@link ParserParameter}. Mappers for the
|
* {@link ParserParameter}. Mappers for the
|
||||||
* parser parameters can be registered using {@link #registerAnnotationMapper(Class, Function)}
|
* parser parameters can be registered using {@link #registerAnnotationMapper(Class, Function)}
|
||||||
*/
|
*/
|
||||||
public AnnotationParser(@Nonnull final CommandManager<C> manager,
|
public AnnotationParser(@NonNull final CommandManager<C> manager,
|
||||||
@Nonnull final Class<C> commandSenderClass,
|
@NonNull final Class<C> commandSenderClass,
|
||||||
@Nonnull final Function<ParserParameters, CommandMeta> metaMapper) {
|
@NonNull final Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) {
|
||||||
this.commandSenderClass = commandSenderClass;
|
this.commandSenderClass = commandSenderClass;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.metaFactory = new MetaFactory(this, metaMapper);
|
this.metaFactory = new MetaFactory(this, metaMapper);
|
||||||
|
|
@ -93,8 +93,9 @@ public final class AnnotationParser<C> {
|
||||||
* @param mapper Mapping function
|
* @param mapper Mapping function
|
||||||
* @param <A> Annotation type
|
* @param <A> Annotation type
|
||||||
*/
|
*/
|
||||||
public <A extends Annotation> void registerAnnotationMapper(@Nonnull final Class<A> annotation,
|
public <A extends Annotation> void registerAnnotationMapper(@NonNull final Class<A> annotation,
|
||||||
@Nonnull final Function<A, ParserParameters> mapper) {
|
@NonNull final Function<@NonNull A,
|
||||||
|
@NonNull ParserParameters> mapper) {
|
||||||
this.annotationMappers.put(annotation, mapper);
|
this.annotationMappers.put(annotation, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,8 +107,7 @@ public final class AnnotationParser<C> {
|
||||||
* @param <T> Type of the instance
|
* @param <T> Type of the instance
|
||||||
* @return Collection of parsed annotations
|
* @return Collection of parsed annotations
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <T> @NonNull Collection<@NonNull Command<C>> parse(@NonNull final T instance) {
|
||||||
public <T> Collection<Command<C>> parse(@Nonnull final T instance) {
|
|
||||||
final Method[] methods = instance.getClass().getDeclaredMethods();
|
final Method[] methods = instance.getClass().getDeclaredMethods();
|
||||||
final Collection<CommandMethodPair> commandMethodPairs = new ArrayList<>();
|
final Collection<CommandMethodPair> commandMethodPairs = new ArrayList<>();
|
||||||
for (final Method method : methods) {
|
for (final Method method : methods) {
|
||||||
|
|
@ -133,10 +133,10 @@ public final class AnnotationParser<C> {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Collection<Command<C>> construct(@Nonnull final Object instance,
|
private @NonNull Collection<@NonNull Command<C>> construct(
|
||||||
@Nonnull final Collection<CommandMethodPair> methodPairs) {
|
@NonNull final Object instance,
|
||||||
|
@NonNull final Collection<@NonNull CommandMethodPair> methodPairs) {
|
||||||
final Collection<Command<C>> commands = new ArrayList<>();
|
final Collection<Command<C>> commands = new ArrayList<>();
|
||||||
for (final CommandMethodPair commandMethodPair : methodPairs) {
|
for (final CommandMethodPair commandMethodPair : methodPairs) {
|
||||||
final CommandMethod commandMethod = commandMethodPair.getCommandMethod();
|
final CommandMethod commandMethod = commandMethodPair.getCommandMethod();
|
||||||
|
|
@ -239,11 +239,10 @@ public final class AnnotationParser<C> {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private CommandArgument<C, ?> buildArgument(@Nonnull final Method method,
|
private @NonNull CommandArgument<C, ?> buildArgument(@NonNull final Method method,
|
||||||
@Nullable final SyntaxFragment syntaxFragment,
|
@Nullable final SyntaxFragment syntaxFragment,
|
||||||
@Nonnull final ArgumentParameterPair argumentPair) {
|
@NonNull final ArgumentParameterPair argumentPair) {
|
||||||
final Parameter parameter = argumentPair.getParameter();
|
final Parameter parameter = argumentPair.getParameter();
|
||||||
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
|
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
|
||||||
final TypeToken<?> token = TypeToken.get(parameter.getParameterizedType());
|
final TypeToken<?> token = TypeToken.get(parameter.getParameterizedType());
|
||||||
|
|
@ -291,8 +290,8 @@ public final class AnnotationParser<C> {
|
||||||
return argumentBuilder.manager(this.manager).withParser(parser).build();
|
return argumentBuilder.manager(this.manager).withParser(parser).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull Map<@NonNull Class<@NonNull ? extends Annotation>,
|
||||||
Map<Class<? extends Annotation>, Function<? extends Annotation, ParserParameters>> getAnnotationMappers() {
|
@NonNull Function<@NonNull ? extends Annotation, @NonNull ParserParameters>> getAnnotationMappers() {
|
||||||
return this.annotationMappers;
|
return this.annotationMappers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.annotations;
|
package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -34,10 +35,10 @@ import java.util.function.Function;
|
||||||
* Utility that extract {@link Argument arguments} from
|
* Utility that extract {@link Argument arguments} from
|
||||||
* {@link java.lang.reflect.Method method} {@link java.lang.reflect.Parameter parameters}
|
* {@link java.lang.reflect.Method method} {@link java.lang.reflect.Parameter parameters}
|
||||||
*/
|
*/
|
||||||
class ArgumentExtractor implements Function<Method, Collection<ArgumentParameterPair>> {
|
class ArgumentExtractor implements Function<@NonNull Method, Collection<@NonNull ArgumentParameterPair>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ArgumentParameterPair> apply(@Nonnull final Method method) {
|
public @NonNull Collection<@NonNull ArgumentParameterPair> apply(@NonNull final Method method) {
|
||||||
final Collection<ArgumentParameterPair> arguments = new ArrayList<>();
|
final Collection<ArgumentParameterPair> arguments = new ArrayList<>();
|
||||||
for (final Parameter parameter : method.getParameters()) {
|
for (final Parameter parameter : method.getParameters()) {
|
||||||
if (!parameter.isAnnotationPresent(Argument.class)) {
|
if (!parameter.isAnnotationPresent(Argument.class)) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.annotations;
|
package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
|
|
||||||
final class ArgumentParameterPair {
|
final class ArgumentParameterPair {
|
||||||
|
|
@ -31,18 +32,17 @@ final class ArgumentParameterPair {
|
||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Argument argument;
|
private final Argument argument;
|
||||||
|
|
||||||
ArgumentParameterPair(@Nonnull final Parameter parameter, @Nonnull final Argument argument) {
|
ArgumentParameterPair(@NonNull final Parameter parameter,
|
||||||
|
@NonNull final Argument argument) {
|
||||||
this.parameter = parameter;
|
this.parameter = parameter;
|
||||||
this.argument = argument;
|
this.argument = argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull Parameter getParameter() {
|
||||||
Parameter getParameter() {
|
|
||||||
return this.parameter;
|
return this.parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull Argument getArgument() {
|
||||||
Argument getArgument() {
|
|
||||||
return this.argument;
|
return this.argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.annotations;
|
package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
final class CommandMethodPair {
|
final class CommandMethodPair {
|
||||||
|
|
@ -31,18 +32,17 @@ final class CommandMethodPair {
|
||||||
private final Method method;
|
private final Method method;
|
||||||
private final CommandMethod commandMethod;
|
private final CommandMethod commandMethod;
|
||||||
|
|
||||||
CommandMethodPair(@Nonnull final Method method, @Nonnull final CommandMethod commandMethod) {
|
CommandMethodPair(@NonNull final Method method,
|
||||||
|
@NonNull final CommandMethod commandMethod) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.commandMethod = commandMethod;
|
this.commandMethod = commandMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull Method getMethod() {
|
||||||
Method getMethod() {
|
|
||||||
return this.method;
|
return this.method;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull CommandMethod getCommandMethod() {
|
||||||
CommandMethod getCommandMethod() {
|
|
||||||
return this.commandMethod;
|
return this.commandMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,24 +25,24 @@ package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
import cloud.commandframework.meta.CommandMeta;
|
import cloud.commandframework.meta.CommandMeta;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
class MetaFactory implements Function<Annotation[], CommandMeta> {
|
class MetaFactory implements Function<@NonNull Annotation @NonNull [], @NonNull CommandMeta> {
|
||||||
|
|
||||||
private final AnnotationParser<?> annotationParser;
|
private final AnnotationParser<?> annotationParser;
|
||||||
private final Function<ParserParameters, CommandMeta> metaMapper;
|
private final Function<ParserParameters, CommandMeta> metaMapper;
|
||||||
|
|
||||||
MetaFactory(@Nonnull final AnnotationParser<?> annotationParser,
|
MetaFactory(@NonNull final AnnotationParser<?> annotationParser,
|
||||||
@Nonnull final Function<ParserParameters, CommandMeta> metaMapper) {
|
@NonNull final Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) {
|
||||||
this.annotationParser = annotationParser;
|
this.annotationParser = annotationParser;
|
||||||
this.metaMapper = metaMapper;
|
this.metaMapper = metaMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandMeta apply(@Nonnull final Annotation[] annotations) {
|
public @NonNull CommandMeta apply(@NonNull final Annotation @NonNull [] annotations) {
|
||||||
final ParserParameters parameters = ParserParameters.empty();
|
final ParserParameters parameters = ParserParameters.empty();
|
||||||
for (final Annotation annotation : annotations) {
|
for (final Annotation annotation : annotations) {
|
||||||
@SuppressWarnings("ALL") final Function function = this.annotationParser.getAnnotationMappers()
|
@SuppressWarnings("ALL") final Function function = this.annotationParser.getAnnotationMappers()
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.annotations;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.execution.CommandExecutionHandler;
|
import cloud.commandframework.execution.CommandExecutionHandler;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
@ -42,9 +42,10 @@ class MethodCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
|
||||||
private final MethodHandle methodHandle;
|
private final MethodHandle methodHandle;
|
||||||
private final Map<String, CommandArgument<C, ?>> commandArguments;
|
private final Map<String, CommandArgument<C, ?>> commandArguments;
|
||||||
|
|
||||||
MethodCommandExecutionHandler(@Nonnull final Object instance,
|
MethodCommandExecutionHandler(@NonNull final Object instance,
|
||||||
@Nonnull final Map<String, CommandArgument<C, ?>> commandArguments,
|
@NonNull final Map<@NonNull String,
|
||||||
@Nonnull final Method method) throws Exception {
|
@NonNull CommandArgument<@NonNull C, @NonNull ?>> commandArguments,
|
||||||
|
@NonNull final Method method) throws Exception {
|
||||||
this.commandArguments = commandArguments;
|
this.commandArguments = commandArguments;
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
this.methodHandle = MethodHandles.lookup().unreflect(method).bindTo(instance);
|
this.methodHandle = MethodHandles.lookup().unreflect(method).bindTo(instance);
|
||||||
|
|
@ -52,7 +53,7 @@ class MethodCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(@Nonnull final CommandContext<C> commandContext) {
|
public void execute(@NonNull final CommandContext<C> commandContext) {
|
||||||
final List<Object> arguments = new ArrayList<>(this.parameters.length);
|
final List<Object> arguments = new ArrayList<>(this.parameters.length);
|
||||||
|
|
||||||
/* Bind parameters to context */
|
/* Bind parameters to context */
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.annotations;
|
package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
@ -44,7 +44,7 @@ public @interface ProxiedBy {
|
||||||
*
|
*
|
||||||
* @return Proxy syntax
|
* @return Proxy syntax
|
||||||
*/
|
*/
|
||||||
@Nonnull String value();
|
@NonNull String value();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the proxying command should be {@link Hidden}
|
* Whether or not the proxying command should be {@link Hidden}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.annotations;
|
package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
final class SyntaxFragment {
|
final class SyntaxFragment {
|
||||||
|
|
@ -32,26 +33,23 @@ final class SyntaxFragment {
|
||||||
private final List<String> minor;
|
private final List<String> minor;
|
||||||
private final ArgumentMode argumentMode;
|
private final ArgumentMode argumentMode;
|
||||||
|
|
||||||
SyntaxFragment(@Nonnull final String major,
|
SyntaxFragment(@NonNull final String major,
|
||||||
@Nonnull final List<String> minor,
|
@NonNull final List<@NonNull String> minor,
|
||||||
@Nonnull final ArgumentMode argumentMode) {
|
@NonNull final ArgumentMode argumentMode) {
|
||||||
this.major = major;
|
this.major = major;
|
||||||
this.minor = minor;
|
this.minor = minor;
|
||||||
this.argumentMode = argumentMode;
|
this.argumentMode = argumentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull String getMajor() {
|
||||||
String getMajor() {
|
|
||||||
return this.major;
|
return this.major;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull List<@NonNull String> getMinor() {
|
||||||
List<String> getMinor() {
|
|
||||||
return this.minor;
|
return this.minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull ArgumentMode getArgumentMode() {
|
||||||
ArgumentMode getArgumentMode() {
|
|
||||||
return this.argumentMode;
|
return this.argumentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.annotations;
|
package cloud.commandframework.annotations;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
@ -36,7 +37,7 @@ import java.util.regex.Pattern;
|
||||||
/**
|
/**
|
||||||
* Parses command syntax into syntax fragments
|
* Parses command syntax into syntax fragments
|
||||||
*/
|
*/
|
||||||
final class SyntaxParser implements Function<String, LinkedHashMap<String, SyntaxFragment>> {
|
final class SyntaxParser implements Function<@NonNull String, @NonNull LinkedHashMap<@NonNull String, @NonNull SyntaxFragment>> {
|
||||||
|
|
||||||
private static final Predicate<String> PATTERN_ARGUMENT_LITERAL = Pattern.compile("([A-Za-z0-9]+)(|([A-Za-z0-9]+))*")
|
private static final Predicate<String> PATTERN_ARGUMENT_LITERAL = Pattern.compile("([A-Za-z0-9]+)(|([A-Za-z0-9]+))*")
|
||||||
.asPredicate();
|
.asPredicate();
|
||||||
|
|
@ -46,7 +47,7 @@ final class SyntaxParser implements Function<String, LinkedHashMap<String, Synta
|
||||||
.asPredicate();
|
.asPredicate();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkedHashMap<String, SyntaxFragment> apply(@Nonnull final String syntax) {
|
public @NonNull LinkedHashMap<@NonNull String, @NonNull SyntaxFragment> apply(@NonNull final String syntax) {
|
||||||
final StringTokenizer stringTokenizer = new StringTokenizer(syntax, " ");
|
final StringTokenizer stringTokenizer = new StringTokenizer(syntax, " ");
|
||||||
final LinkedHashMap<String, SyntaxFragment> map = new LinkedHashMap<>();
|
final LinkedHashMap<String, SyntaxFragment> map = new LinkedHashMap<>();
|
||||||
while (stringTokenizer.hasMoreTokens()) {
|
while (stringTokenizer.hasMoreTokens()) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
@ -63,9 +62,9 @@ class AnnotationParserTest {
|
||||||
|
|
||||||
@ProxiedBy("proxycommand")
|
@ProxiedBy("proxycommand")
|
||||||
@CommandMethod("test|t literal <int> [string]")
|
@CommandMethod("test|t literal <int> [string]")
|
||||||
public void testCommand(@Nonnull final TestCommandSender sender,
|
public void testCommand(final TestCommandSender sender,
|
||||||
@Argument("int") @Range(max = "100") final int argument,
|
@Argument("int") @Range(max = "100") final int argument,
|
||||||
@Nonnull @Argument(value = "string", defaultValue = "potato", parserName = "potato")
|
@Argument(value = "string", defaultValue = "potato", parserName = "potato")
|
||||||
final String string) {
|
final String string) {
|
||||||
System.out.printf("Received int: %d and string '%s'\n", argument, string);
|
System.out.printf("Received int: %d and string '%s'\n", argument, string);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,23 +28,20 @@ import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class TestCommandManager extends CommandManager<TestCommandSender> {
|
public class TestCommandManager extends CommandManager<TestCommandSender> {
|
||||||
|
|
||||||
protected TestCommandManager() {
|
protected TestCommandManager() {
|
||||||
super(CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler());
|
super(CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final SimpleCommandMeta createDefaultCommandMeta() {
|
public final SimpleCommandMeta createDefaultCommandMeta() {
|
||||||
return SimpleCommandMeta.empty();
|
return SimpleCommandMeta.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasPermission(@Nonnull final TestCommandSender sender,
|
public final boolean hasPermission(final TestCommandSender sender,
|
||||||
@Nonnull final String permission) {
|
final String permission) {
|
||||||
return !permission.equalsIgnoreCase("no");
|
return !permission.equalsIgnoreCase("no");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import cloud.commandframework.permission.CommandPermission;
|
||||||
import cloud.commandframework.permission.Permission;
|
import cloud.commandframework.permission.Permission;
|
||||||
import cloud.commandframework.types.tuples.Pair;
|
import cloud.commandframework.types.tuples.Pair;
|
||||||
import cloud.commandframework.types.tuples.Triplet;
|
import cloud.commandframework.types.tuples.Triplet;
|
||||||
import com.google.common.reflect.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
|
@ -391,11 +391,10 @@ public class Command<C> {
|
||||||
* @param <V> Second type
|
* @param <V> Second type
|
||||||
* @return Builder instance with the argument inserted
|
* @return Builder instance with the argument inserted
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <U, V> @NonNull Builder<C> argumentPair(@NonNull final String name,
|
||||||
public <U, V> Builder<C> argumentPair(@Nonnull final String name,
|
@NonNull final Pair<@NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Pair<String, String> names,
|
@NonNull final Pair<@NonNull Class<U>, @NonNull Class<V>> parserPair,
|
||||||
@Nonnull final Pair<Class<U>, Class<V>> parserPair,
|
@NonNull final Description description) {
|
||||||
@Nonnull final Description description) {
|
|
||||||
if (this.commandManager == null) {
|
if (this.commandManager == null) {
|
||||||
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
||||||
}
|
}
|
||||||
|
|
@ -422,13 +421,13 @@ public class Command<C> {
|
||||||
* @param <O> Output type
|
* @param <O> Output type
|
||||||
* @return Builder instance with the argument inserted
|
* @return Builder instance with the argument inserted
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <U, V, O> @NonNull Builder<C> argumentPair(@NonNull final String name,
|
||||||
public <U, V, O> Builder<C> argumentPair(@Nonnull final String name,
|
@NonNull final TypeToken<O> outputType,
|
||||||
@Nonnull final TypeToken<O> outputType,
|
@NonNull final Pair<@NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Pair<String, String> names,
|
@NonNull final Pair<@NonNull Class<U>, @NonNull Class<V>> parserPair,
|
||||||
@Nonnull final Pair<Class<U>, Class<V>> parserPair,
|
@NonNull final Function<Pair<@NonNull U, @NonNull V>,
|
||||||
@Nonnull final Function<Pair<U, V>, O> mapper,
|
@NonNull O> mapper,
|
||||||
@Nonnull final Description description) {
|
@NonNull final Description description) {
|
||||||
if (this.commandManager == null) {
|
if (this.commandManager == null) {
|
||||||
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
||||||
}
|
}
|
||||||
|
|
@ -455,11 +454,12 @@ public class Command<C> {
|
||||||
* @param <W> Third type
|
* @param <W> Third type
|
||||||
* @return Builder instance with the argument inserted
|
* @return Builder instance with the argument inserted
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <U, V, W> @NonNull Builder<C> argumentTriplet(@NonNull final String name,
|
||||||
public <U, V, W> Builder<C> argumentTriplet(@Nonnull final String name,
|
@NonNull final Triplet<@NonNull String,
|
||||||
@Nonnull final Triplet<String, String, String> names,
|
@NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Triplet<Class<U>, Class<V>, Class<W>> parserTriplet,
|
@NonNull final Triplet<@NonNull Class<U>,
|
||||||
@Nonnull final Description description) {
|
@NonNull Class<V>, @NonNull Class<W>> parserTriplet,
|
||||||
|
@NonNull final Description description) {
|
||||||
if (this.commandManager == null) {
|
if (this.commandManager == null) {
|
||||||
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
||||||
}
|
}
|
||||||
|
|
@ -487,13 +487,15 @@ public class Command<C> {
|
||||||
* @param <O> Output type
|
* @param <O> Output type
|
||||||
* @return Builder instance with the argument inserted
|
* @return Builder instance with the argument inserted
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <U, V, W, O> @NonNull Builder<C> argumentTriplet(@NonNull final String name,
|
||||||
public <U, V, W, O> Builder<C> argumentTriplet(@Nonnull final String name,
|
@NonNull final TypeToken<O> outputType,
|
||||||
@Nonnull final TypeToken<O> outputType,
|
@NonNull final Triplet<@NonNull String,
|
||||||
@Nonnull final Triplet<String, String, String> names,
|
@NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Triplet<Class<U>, Class<V>, Class<W>> parserTriplet,
|
@NonNull final Triplet<@NonNull Class<U>,
|
||||||
@Nonnull final Function<Triplet<U, V, W>, O> mapper,
|
@NonNull Class<V>, @NonNull Class<W>> parserTriplet,
|
||||||
@Nonnull final Description description) {
|
@NonNull final Function<@NonNull Triplet<@NonNull U,
|
||||||
|
@NonNull V, @NonNull W>, @NonNull O> mapper,
|
||||||
|
@NonNull final Description description) {
|
||||||
if (this.commandManager == null) {
|
if (this.commandManager == null) {
|
||||||
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,12 +125,13 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param suggestionsProvider Suggestions provider
|
* @param suggestionsProvider Suggestions provider
|
||||||
*/
|
*/
|
||||||
public CommandArgument(final boolean required,
|
public CommandArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final ArgumentParser<C, T> parser,
|
@NonNull final ArgumentParser<C, T> parser,
|
||||||
@Nonnull final String defaultValue,
|
@NonNull final String defaultValue,
|
||||||
@Nonnull final Class<T> valueType,
|
@NonNull final Class<T> valueType,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>,
|
||||||
this(required, name, parser, defaultValue, TypeToken.of(valueType), suggestionsProvider);
|
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
|
this(required, name, parser, defaultValue, TypeToken.get(valueType), suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -162,9 +163,8 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param <T> Argument Type. Used to make the compiler happy.
|
* @param <T> Argument Type. Used to make the compiler happy.
|
||||||
* @return Argument builder
|
* @return Argument builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, T> CommandArgument.@NonNull Builder<C, T> ofType(@NonNull final TypeToken<T> clazz,
|
||||||
public static <C, T> CommandArgument.Builder<C, T> ofType(@Nonnull final TypeToken<T> clazz,
|
@NonNull final String name) {
|
||||||
@Nonnull final String name) {
|
|
||||||
return new Builder<>(clazz, name);
|
return new Builder<>(clazz, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,9 +352,9 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Builder(@Nonnull final Class<T> valueType,
|
protected Builder(@NonNull final Class<T> valueType,
|
||||||
@Nonnull final String name) {
|
@NonNull final String name) {
|
||||||
this(TypeToken.of(valueType), name);
|
this(TypeToken.get(valueType), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.compound;
|
package cloud.commandframework.arguments.compound;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import cloud.commandframework.CommandManager;
|
import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
import cloud.commandframework.arguments.parser.ParserRegistry;
|
import cloud.commandframework.arguments.parser.ParserRegistry;
|
||||||
import cloud.commandframework.types.tuples.Pair;
|
import cloud.commandframework.types.tuples.Pair;
|
||||||
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -55,12 +55,12 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
||||||
* @param valueType The output type
|
* @param valueType The output type
|
||||||
*/
|
*/
|
||||||
protected ArgumentPair(final boolean required,
|
protected ArgumentPair(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final Pair<String, String> names,
|
@NonNull final Pair<@NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Pair<Class<U>, Class<V>> types,
|
@NonNull final Pair<@NonNull Class<U>, @NonNull Class<V>> types,
|
||||||
@Nonnull final Pair<ArgumentParser<C, U>, ArgumentParser<C, V>> parserPair,
|
@NonNull final Pair<@NonNull ArgumentParser<C, U>, @NonNull ArgumentParser<C, V>> parserPair,
|
||||||
@Nonnull final Function<Pair<U, V>, O> mapper,
|
@NonNull final Function<@NonNull Pair<@NonNull U, @NonNull V>, @NonNull O> mapper,
|
||||||
@Nonnull final TypeToken<O> valueType) {
|
@NonNull final TypeToken<O> valueType) {
|
||||||
super(required, name, names, parserPair, types, mapper, o -> Pair.of((U) o[0], (V) o[1]), valueType);
|
super(required, name, names, parserPair, types, mapper, o -> Pair.of((U) o[0], (V) o[1]), valueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,17 +78,18 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
||||||
* @param <V> Second parsed type
|
* @param <V> Second parsed type
|
||||||
* @return Intermediary builder
|
* @return Intermediary builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, U, V> @NonNull ArgumentPairIntermediaryBuilder<C, U, V> required(@NonNull final CommandManager<C> manager,
|
||||||
public static <C, U, V> ArgumentPairIntermediaryBuilder<C, U, V> required(@Nonnull final CommandManager<C> manager,
|
@NonNull final String name,
|
||||||
@Nonnull final String name,
|
@NonNull final Pair<@NonNull String,
|
||||||
@Nonnull final Pair<String, String> names,
|
@NonNull String> names,
|
||||||
@Nonnull final Pair<Class<U>, Class<V>> types) {
|
@NonNull final Pair<@NonNull Class<U>,
|
||||||
|
@NonNull Class<V>> types) {
|
||||||
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
|
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
|
||||||
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(TypeToken.of(types.getFirst()),
|
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(TypeToken.get(types.getFirst()),
|
||||||
ParserParameters.empty()).orElseThrow(() ->
|
ParserParameters.empty()).orElseThrow(() ->
|
||||||
new IllegalArgumentException(
|
new IllegalArgumentException(
|
||||||
"Could not create parser for primary type"));
|
"Could not create parser for primary type"));
|
||||||
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(TypeToken.of(types.getSecond()),
|
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(TypeToken.get(types.getSecond()),
|
||||||
ParserParameters.empty()).orElseThrow(() ->
|
ParserParameters.empty()).orElseThrow(() ->
|
||||||
new IllegalArgumentException(
|
new IllegalArgumentException(
|
||||||
"Could not create parser for secondary type"));
|
"Could not create parser for secondary type"));
|
||||||
|
|
@ -105,10 +106,11 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
||||||
private final Pair<Class<U>, Class<V>> types;
|
private final Pair<Class<U>, Class<V>> types;
|
||||||
|
|
||||||
private ArgumentPairIntermediaryBuilder(final boolean required,
|
private ArgumentPairIntermediaryBuilder(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final Pair<String, String> names,
|
@NonNull final Pair<@NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Pair<ArgumentParser<C, U>, ArgumentParser<C, V>> parserPair,
|
@NonNull final Pair<@NonNull ArgumentParser<@NonNull C, @NonNull U>,
|
||||||
@Nonnull final Pair<Class<U>, Class<V>> types) {
|
@NonNull ArgumentParser<@NonNull C, @NonNull V>> parserPair,
|
||||||
|
@NonNull final Pair<@NonNull Class<U>, @NonNull Class<V>> types) {
|
||||||
this.required = required;
|
this.required = required;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.names = names;
|
this.names = names;
|
||||||
|
|
@ -121,8 +123,7 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
||||||
*
|
*
|
||||||
* @return Argument pair
|
* @return Argument pair
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull ArgumentPair<@NonNull C, @NonNull U, @NonNull V, @NonNull Pair<@NonNull U, @NonNull V>> simple() {
|
||||||
public ArgumentPair<C, U, V, Pair<U, V>> simple() {
|
|
||||||
return new ArgumentPair<C, U, V, Pair<U, V>>(this.required,
|
return new ArgumentPair<C, U, V, Pair<U, V>>(this.required,
|
||||||
this.name,
|
this.name,
|
||||||
this.names,
|
this.names,
|
||||||
|
|
@ -141,9 +142,9 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
||||||
* @param <O> Output type
|
* @param <O> Output type
|
||||||
* @return Created pair
|
* @return Created pair
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <O> @NonNull ArgumentPair<C, U, V, O> withMapper(@NonNull final TypeToken<O> clazz,
|
||||||
public <O> ArgumentPair<C, U, V, O> withMapper(@Nonnull final TypeToken<O> clazz,
|
@NonNull final Function<@NonNull Pair<@NonNull U,
|
||||||
@Nonnull final Function<Pair<U, V>, O> mapper) {
|
@NonNull V>, @NonNull O> mapper) {
|
||||||
return new ArgumentPair<C, U, V, O>(this.required, this.name, this.names, this.types, this.parserPair, mapper, clazz);
|
return new ArgumentPair<C, U, V, O>(this.required, this.name, this.names, this.types, this.parserPair, mapper, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,10 +156,10 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
||||||
* @param <O> Output type
|
* @param <O> Output type
|
||||||
* @return Created pair
|
* @return Created pair
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <O> @NonNull ArgumentPair<@NonNull C, @NonNull U, @NonNull V, @NonNull O> withMapper(
|
||||||
public <O> ArgumentPair<C, U, V, O> withMapper(@Nonnull final Class<O> clazz,
|
@NonNull final Class<O> clazz,
|
||||||
@Nonnull final Function<Pair<U, V>, O> mapper) {
|
@NonNull final Function<@NonNull Pair<@NonNull U, @NonNull V>, @NonNull O> mapper) {
|
||||||
return this.withMapper(TypeToken.of(clazz), mapper);
|
return this.withMapper(TypeToken.get(clazz), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
import cloud.commandframework.arguments.parser.ParserRegistry;
|
import cloud.commandframework.arguments.parser.ParserRegistry;
|
||||||
import cloud.commandframework.types.tuples.Triplet;
|
import cloud.commandframework.types.tuples.Triplet;
|
||||||
import com.google.common.reflect.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,13 +56,13 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
||||||
* @param valueType The output type
|
* @param valueType The output type
|
||||||
*/
|
*/
|
||||||
protected ArgumentTriplet(final boolean required,
|
protected ArgumentTriplet(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final Triplet<String, String, String> names,
|
@NonNull final Triplet<@NonNull String, @NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Triplet<Class<U>, Class<V>, Class<W>> types,
|
@NonNull final Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types,
|
||||||
@Nonnull final Triplet<ArgumentParser<C, U>, ArgumentParser<C, V>,
|
@NonNull final Triplet<@NonNull ArgumentParser<C, U>, @NonNull ArgumentParser<C, V>,
|
||||||
ArgumentParser<C, W>> parserTriplet,
|
@NonNull ArgumentParser<C, W>> parserTriplet,
|
||||||
@Nonnull final Function<Triplet<U, V, W>, O> mapper,
|
@NonNull final Function<@NonNull Triplet<U, @NonNull V, @NonNull W>, @NonNull O> mapper,
|
||||||
@Nonnull final TypeToken<O> valueType) {
|
@NonNull final TypeToken<O> valueType) {
|
||||||
super(required, name, names, parserTriplet, types, mapper, o -> Triplet.of((U) o[0], (V) o[1], (W) o[2]), valueType);
|
super(required, name, names, parserTriplet, types, mapper, o -> Triplet.of((U) o[0], (V) o[1], (W) o[2]), valueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,22 +81,21 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
||||||
* @param <W> Third type
|
* @param <W> Third type
|
||||||
* @return Intermediary builder
|
* @return Intermediary builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, U, V, W> @NonNull ArgumentTripletIntermediaryBuilder<@NonNull C, @NonNull U, @NonNull V, @NonNull W>
|
||||||
public static <C, U, V, W> ArgumentTripletIntermediaryBuilder<C, U, V, W>
|
required(@NonNull final CommandManager<C> manager,
|
||||||
required(@Nonnull final CommandManager<C> manager,
|
@NonNull final String name,
|
||||||
@Nonnull final String name,
|
@NonNull final Triplet<@NonNull String, @NonNull String, @NonNull String> names,
|
||||||
@Nonnull final Triplet<String, String, String> names,
|
@NonNull final Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types) {
|
||||||
@Nonnull final Triplet<Class<U>, Class<V>, Class<W>> types) {
|
|
||||||
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
|
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
|
||||||
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(TypeToken.of(types.getFirst()),
|
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(TypeToken.get(types.getFirst()),
|
||||||
ParserParameters.empty()).orElseThrow(() ->
|
ParserParameters.empty()).orElseThrow(() ->
|
||||||
new IllegalArgumentException(
|
new IllegalArgumentException(
|
||||||
"Could not create parser for primary type"));
|
"Could not create parser for primary type"));
|
||||||
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(TypeToken.of(types.getSecond()),
|
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(TypeToken.get(types.getSecond()),
|
||||||
ParserParameters.empty()).orElseThrow(() ->
|
ParserParameters.empty()).orElseThrow(() ->
|
||||||
new IllegalArgumentException(
|
new IllegalArgumentException(
|
||||||
"Could not create parser for secondary type"));
|
"Could not create parser for secondary type"));
|
||||||
final ArgumentParser<C, W> tertiaryParser = parserRegistry.createParser(TypeToken.of(types.getThird()),
|
final ArgumentParser<C, W> tertiaryParser = parserRegistry.createParser(TypeToken.get(types.getThird()),
|
||||||
ParserParameters.empty()).orElseThrow(() ->
|
ParserParameters.empty()).orElseThrow(() ->
|
||||||
new IllegalArgumentException(
|
new IllegalArgumentException(
|
||||||
"Could not create parser for tertiary type"));
|
"Could not create parser for tertiary type"));
|
||||||
|
|
@ -114,11 +113,14 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
||||||
private final Triplet<Class<U>, Class<V>, Class<W>> types;
|
private final Triplet<Class<U>, Class<V>, Class<W>> types;
|
||||||
|
|
||||||
private ArgumentTripletIntermediaryBuilder(final boolean required,
|
private ArgumentTripletIntermediaryBuilder(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final Triplet<String, String, String> names,
|
@NonNull final Triplet<@NonNull String, @NonNull String,
|
||||||
@Nonnull final Triplet<ArgumentParser<C, U>,
|
@NonNull String> names,
|
||||||
ArgumentParser<C, V>, ArgumentParser<C, W>> parserTriplet,
|
@NonNull final Triplet<@NonNull ArgumentParser<C, U>,
|
||||||
@Nonnull final Triplet<Class<U>, Class<V>, Class<W>> types) {
|
@NonNull ArgumentParser<C, V>,
|
||||||
|
@NonNull ArgumentParser<C, W>> parserTriplet,
|
||||||
|
@NonNull final Triplet<@NonNull Class<U>,
|
||||||
|
@NonNull Class<V>, @NonNull Class<W>> types) {
|
||||||
this.required = required;
|
this.required = required;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.names = names;
|
this.names = names;
|
||||||
|
|
@ -131,8 +133,8 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
||||||
*
|
*
|
||||||
* @return Argument triplet
|
* @return Argument triplet
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull ArgumentTriplet<@NonNull C, @NonNull U, @NonNull V,
|
||||||
public ArgumentTriplet<C, U, V, W, Triplet<U, V, W>> simple() {
|
@NonNull W, Triplet<@NonNull U, @NonNull V, @NonNull W>> simple() {
|
||||||
return new ArgumentTriplet<>(this.required,
|
return new ArgumentTriplet<>(this.required,
|
||||||
this.name,
|
this.name,
|
||||||
this.names,
|
this.names,
|
||||||
|
|
@ -151,9 +153,10 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
||||||
* @param <O> Output type
|
* @param <O> Output type
|
||||||
* @return Created triplet
|
* @return Created triplet
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <O> @NonNull ArgumentTriplet<@NonNull C, @NonNull U, @NonNull V,
|
||||||
public <O> ArgumentTriplet<C, U, V, W, O> withMapper(@Nonnull final TypeToken<O> clazz,
|
@NonNull W, @NonNull O> withMapper(@NonNull final TypeToken<O> clazz,
|
||||||
@Nonnull final Function<Triplet<U, V, W>, O> mapper) {
|
@NonNull final Function<@NonNull Triplet<@NonNull U,
|
||||||
|
@NonNull V, @NonNull W>, @NonNull O> mapper) {
|
||||||
return new ArgumentTriplet<>(this.required, this.name, this.names, this.types, this.parserTriplet, mapper, clazz);
|
return new ArgumentTriplet<>(this.required, this.name, this.names, this.types, this.parserTriplet, mapper, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,11 +168,11 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
||||||
* @param <O> Output type
|
* @param <O> Output type
|
||||||
* @return Created triplet
|
* @return Created triplet
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <O> @NonNull ArgumentTriplet<C, U, V, W, O> withMapper(@NonNull final Class<O> clazz,
|
||||||
public <O> ArgumentTriplet<C, U, V, W, O> withMapper(@Nonnull final Class<O> clazz,
|
@NonNull final Function<@NonNull Triplet<@NonNull U,
|
||||||
@Nonnull final Function<Triplet<U, V, W>, O> mapper) {
|
@NonNull V, @NonNull W>, @NonNull O> mapper) {
|
||||||
return new ArgumentTriplet<>(this.required, this.name, this.names, this.types,
|
return new ArgumentTriplet<>(this.required, this.name, this.names, this.types,
|
||||||
this.parserTriplet, mapper, TypeToken.of(clazz));
|
this.parserTriplet, mapper, TypeToken.get(clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.types.tuples.Tuple;
|
import cloud.commandframework.types.tuples.Tuple;
|
||||||
import com.google.common.reflect.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -49,13 +49,13 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
private final Tuple parserTuple;
|
private final Tuple parserTuple;
|
||||||
|
|
||||||
CompoundArgument(final boolean required,
|
CompoundArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final Tuple names,
|
@NonNull final Tuple names,
|
||||||
@Nonnull final Tuple parserTuple,
|
@NonNull final Tuple parserTuple,
|
||||||
@Nonnull final Tuple types,
|
@NonNull final Tuple types,
|
||||||
@Nonnull final Function<T, O> mapper,
|
@NonNull final Function<@NonNull T, @NonNull O> mapper,
|
||||||
@Nonnull final Function<Object[], T> tupleFactory,
|
@NonNull final Function<@NonNull Object[], @NonNull T> tupleFactory,
|
||||||
@Nonnull final TypeToken<O> valueType) {
|
@NonNull final TypeToken<O> valueType) {
|
||||||
super(required,
|
super(required,
|
||||||
name,
|
name,
|
||||||
new CompoundParser<>(parserTuple, mapper, tupleFactory),
|
new CompoundParser<>(parserTuple, mapper, tupleFactory),
|
||||||
|
|
@ -72,8 +72,7 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
*
|
*
|
||||||
* @return Internal parsers
|
* @return Internal parsers
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Tuple getParserTuple() {
|
||||||
public Tuple getParserTuple() {
|
|
||||||
return this.parserTuple;
|
return this.parserTuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,8 +81,7 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
*
|
*
|
||||||
* @return Argument names
|
* @return Argument names
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Tuple getNames() {
|
||||||
public Tuple getNames() {
|
|
||||||
return this.names;
|
return this.names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,8 +90,7 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
*
|
*
|
||||||
* @return Parser types
|
* @return Parser types
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Tuple getTypes() {
|
||||||
public Tuple getTypes() {
|
|
||||||
return this.types;
|
return this.types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,22 +101,20 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
private final Function<T, O> mapper;
|
private final Function<T, O> mapper;
|
||||||
private final Function<Object[], T> tupleFactory;
|
private final Function<Object[], T> tupleFactory;
|
||||||
|
|
||||||
private CompoundParser(@Nonnull final Tuple parserTuple,
|
private CompoundParser(@NonNull final Tuple parserTuple,
|
||||||
@Nonnull final Function<T, O> mapper,
|
@NonNull final Function<@NonNull T, @NonNull O> mapper,
|
||||||
@Nonnull final Function<Object[], T> tupleFactory) {
|
@NonNull final Function<@NonNull Object[], @NonNull T> tupleFactory) {
|
||||||
this.parsers = parserTuple.toArray();
|
this.parsers = parserTuple.toArray();
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.tupleFactory = tupleFactory;
|
this.tupleFactory = tupleFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<O> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull ArgumentParseResult<O> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final Object[] output = new Object[this.parsers.length];
|
final Object[] output = new Object[this.parsers.length];
|
||||||
for (int i = 0; i < this.parsers.length; i++) {
|
for (int i = 0; i < this.parsers.length; i++) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) this.parsers[i];
|
||||||
final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) this.parsers[i];
|
|
||||||
final ArgumentParseResult<?> result = parser.parse(commandContext, inputQueue);
|
final ArgumentParseResult<?> result = parser.parse(commandContext, inputQueue);
|
||||||
if (result.getFailure().isPresent()) {
|
if (result.getFailure().isPresent()) {
|
||||||
/* Return the failure */
|
/* Return the failure */
|
||||||
|
|
@ -139,10 +134,9 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
/*
|
/*
|
||||||
This method will be called n times, each time for each of the internal types.
|
This method will be called n times, each time for each of the internal types.
|
||||||
The problem is that we need to then know which of the parsers to forward the
|
The problem is that we need to then know which of the parsers to forward the
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
@ -39,9 +39,12 @@ import java.util.function.BiFunction;
|
||||||
public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
private final boolean liberal;
|
private final boolean liberal;
|
||||||
|
|
||||||
private BooleanArgument(final boolean required, @Nonnull final String name,
|
private BooleanArgument(final boolean required,
|
||||||
final boolean liberal, @Nonnull final String defaultValue,
|
@NonNull final String name,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
final boolean liberal,
|
||||||
|
@NonNull final String defaultValue,
|
||||||
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new BooleanParser<>(liberal), defaultValue, Boolean.class, suggestionsProvider);
|
super(required, name, new BooleanParser<>(liberal), defaultValue, Boolean.class, suggestionsProvider);
|
||||||
this.liberal = liberal;
|
this.liberal = liberal;
|
||||||
}
|
}
|
||||||
|
|
@ -53,8 +56,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,8 +67,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Boolean> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Boolean> required(@Nonnull final String name) {
|
|
||||||
return BooleanArgument.<C>newBuilder(name).asRequired().build();
|
return BooleanArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,8 +78,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Boolean> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Boolean> optional(@Nonnull final String name) {
|
|
||||||
return BooleanArgument.<C>newBuilder(name).asOptional().build();
|
return BooleanArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,8 +90,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Boolean> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Boolean> optional(@Nonnull final String name,
|
|
||||||
final boolean defaultBoolean) {
|
final boolean defaultBoolean) {
|
||||||
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(Boolean.toString(defaultBoolean)).build();
|
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(Boolean.toString(defaultBoolean)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +108,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
|
|
||||||
private boolean liberal = false;
|
private boolean liberal = false;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Boolean.class, name);
|
super(Boolean.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,8 +118,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
* @param liberal liberal value
|
* @param liberal liberal value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withLiberal(final boolean liberal) {
|
||||||
public Builder<C> withLiberal(final boolean liberal) {
|
|
||||||
this.liberal = liberal;
|
this.liberal = liberal;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -130,9 +128,8 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public BooleanArgument<C> build() {
|
public @NonNull BooleanArgument<C> build() {
|
||||||
return new BooleanArgument<>(this.isRequired(), this.getName(), this.liberal,
|
return new BooleanArgument<>(this.isRequired(), this.getName(), this.liberal,
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -156,10 +153,9 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
this.liberal = liberal;
|
this.liberal = liberal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Boolean> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull ArgumentParseResult<Boolean> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -191,10 +187,9 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
return ArgumentParseResult.failure(new BooleanParseException(input, true));
|
return ArgumentParseResult.failure(new BooleanParseException(input, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
if (!liberal) {
|
if (!liberal) {
|
||||||
return Arrays.asList("TRUE", "FALSE");
|
return Arrays.asList("TRUE", "FALSE");
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +218,8 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
* @param input String input
|
* @param input String input
|
||||||
* @param liberal Liberal value
|
* @param liberal Liberal value
|
||||||
*/
|
*/
|
||||||
public BooleanParseException(@Nonnull final String input, final boolean liberal) {
|
public BooleanParseException(@NonNull final String input,
|
||||||
|
final boolean liberal) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.liberal = liberal;
|
this.liberal = liberal;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.standard;
|
package cloud.commandframework.arguments.standard;
|
||||||
|
|
||||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -41,9 +41,13 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
private final byte min;
|
private final byte min;
|
||||||
private final byte max;
|
private final byte max;
|
||||||
|
|
||||||
private ByteArgument(final boolean required, @Nonnull final String name, final byte min,
|
private ByteArgument(final boolean required,
|
||||||
final byte max, final String defaultValue,
|
@NonNull final String name,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
final byte min,
|
||||||
|
final byte max,
|
||||||
|
@NonNull final String defaultValue,
|
||||||
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new ByteParser<>(min, max), defaultValue, Byte.class, suggestionsProvider);
|
super(required, name, new ByteParser<>(min, max), defaultValue, Byte.class, suggestionsProvider);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -56,8 +60,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,8 +71,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Byte> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Byte> required(@Nonnull final String name) {
|
|
||||||
return ByteArgument.<C>newBuilder(name).asRequired().build();
|
return ByteArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,8 +82,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Byte> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Byte> optional(@Nonnull final String name) {
|
|
||||||
return ByteArgument.<C>newBuilder(name).asOptional().build();
|
return ByteArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,8 +94,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Byte> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Byte> optional(@Nonnull final String name,
|
|
||||||
final byte defaultNum) {
|
final byte defaultNum) {
|
||||||
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
|
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +122,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
private byte min = Byte.MIN_VALUE;
|
private byte min = Byte.MIN_VALUE;
|
||||||
private byte max = Byte.MAX_VALUE;
|
private byte max = Byte.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Byte.class, name);
|
super(Byte.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,8 +132,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMin(final byte min) {
|
||||||
public Builder<C> withMin(final byte min) {
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -144,8 +143,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMax(final byte max) {
|
||||||
public Builder<C> withMax(final byte max) {
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -155,9 +153,8 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ByteArgument<C> build() {
|
public @NonNull ByteArgument<C> build() {
|
||||||
return new ByteArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
return new ByteArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -180,11 +177,10 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Byte> parse(
|
public @NonNull ArgumentParseResult<Byte> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -211,10 +207,9 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
|
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,7 +246,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
*/
|
*/
|
||||||
public ByteParseException(@Nonnull final String input, final byte min, final byte max) {
|
public ByteParseException(@NonNull final String input, final byte min, final byte max) {
|
||||||
super(input, min, max);
|
super(input, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,8 +261,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public @NonNull String getNumberType() {
|
||||||
public String getNumberType() {
|
|
||||||
return "byte";
|
return "byte";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,12 @@
|
||||||
package cloud.commandframework.arguments.standard;
|
package cloud.commandframework.arguments.standard;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -37,9 +37,11 @@ import java.util.function.BiFunction;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class CharArgument<C> extends CommandArgument<C, Character> {
|
public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
|
|
||||||
private CharArgument(final boolean required, @Nonnull final String name,
|
private CharArgument(final boolean required,
|
||||||
@Nonnull final String defaultValue, @Nullable
|
@NonNull final String name,
|
||||||
final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@NonNull final String defaultValue,
|
||||||
|
@Nullable final BiFunction<@NonNull CommandContext<C>,
|
||||||
|
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new CharacterParser<>(), defaultValue, Character.class, suggestionsProvider);
|
super(required, name, new CharacterParser<>(), defaultValue, Character.class, suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,8 +52,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> CharArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> CharArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new CharArgument.Builder<>(name);
|
return new CharArgument.Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,8 +63,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Character> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Character> required(@Nonnull final String name) {
|
|
||||||
return CharArgument.<C>newBuilder(name).asRequired().build();
|
return CharArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,8 +74,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Character> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Character> optional(@Nonnull final String name) {
|
|
||||||
return CharArgument.<C>newBuilder(name).asOptional().build();
|
return CharArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,16 +86,15 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Character> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Character> optional(@Nonnull final String name,
|
@NonNull final String defaultNum) {
|
||||||
final String defaultNum) {
|
|
||||||
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, Character> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Character> {
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Character.class, name);
|
super(Character.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,9 +103,8 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public CharArgument<C> build() {
|
public @NonNull CharArgument<C> build() {
|
||||||
return new CharArgument<>(this.isRequired(), this.getName(),
|
return new CharArgument<>(this.isRequired(), this.getName(),
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -117,10 +114,9 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
|
|
||||||
public static final class CharacterParser<C> implements ArgumentParser<C, Character> {
|
public static final class CharacterParser<C> implements ArgumentParser<C, Character> {
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Character> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull ArgumentParseResult<Character> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -153,7 +149,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
*
|
*
|
||||||
* @param input String input
|
* @param input String input
|
||||||
*/
|
*/
|
||||||
public CharParseException(final String input) {
|
public CharParseException(@NonNull final String input) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +158,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
*
|
*
|
||||||
* @return Input value
|
* @return Input value
|
||||||
*/
|
*/
|
||||||
public String getInput() {
|
public @NonNull String getInput() {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@
|
||||||
package cloud.commandframework.arguments.standard;
|
package cloud.commandframework.arguments.standard;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
|
||||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -42,11 +42,12 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
private final double max;
|
private final double max;
|
||||||
|
|
||||||
private DoubleArgument(final boolean required,
|
private DoubleArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
final double min,
|
final double min,
|
||||||
final double max,
|
final double max,
|
||||||
final String defaultValue,
|
final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new DoubleParser<>(min, max), defaultValue, Double.class, suggestionsProvider);
|
super(required, name, new DoubleParser<>(min, max), defaultValue, Double.class, suggestionsProvider);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -59,8 +60,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +71,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Double> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Double> required(@Nonnull final String name) {
|
|
||||||
return DoubleArgument.<C>newBuilder(name).asRequired().build();
|
return DoubleArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,8 +82,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Double> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Double> optional(@Nonnull final String name) {
|
|
||||||
return DoubleArgument.<C>newBuilder(name).asOptional().build();
|
return DoubleArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,8 +94,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Double> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Double> optional(@Nonnull final String name,
|
|
||||||
final double defaultNum) {
|
final double defaultNum) {
|
||||||
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
|
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +122,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
private double min = Double.MIN_VALUE;
|
private double min = Double.MIN_VALUE;
|
||||||
private double max = Double.MAX_VALUE;
|
private double max = Double.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Double.class, name);
|
super(Double.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,8 +132,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMin(final int min) {
|
||||||
public Builder<C> withMin(final int min) {
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +143,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMax(final int max) {
|
||||||
public Builder<C> withMax(final int max) {
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +153,8 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public DoubleArgument<C> build() {
|
public @NonNull DoubleArgument<C> build() {
|
||||||
return new DoubleArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
return new DoubleArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -183,11 +177,10 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Double> parse(
|
public @NonNull ArgumentParseResult<Double> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -239,7 +232,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
*/
|
*/
|
||||||
public DoubleParseException(@Nonnull final String input, final double min, final double max) {
|
public DoubleParseException(@NonNull final String input, final double min, final double max) {
|
||||||
super(input, min, max);
|
super(input, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,8 +247,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public @NonNull String getNumberType() {
|
||||||
public String getNumberType() {
|
|
||||||
return "double";
|
return "double";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
@ -45,11 +45,12 @@ import java.util.stream.Collectors;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
|
|
||||||
protected EnumArgument(@Nonnull final Class<E> enumClass,
|
protected EnumArgument(@NonNull final Class<E> enumClass,
|
||||||
final boolean required,
|
final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final String defaultValue,
|
@NonNull final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new EnumParser<>(enumClass), defaultValue, enumClass, suggestionsProvider);
|
super(required, name, new EnumParser<>(enumClass), defaultValue, enumClass, suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,9 +63,9 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, E extends Enum<E>> EnumArgument.@NonNull Builder<C, E> newBuilder(
|
||||||
public static <C, E extends Enum<E>> EnumArgument.Builder<C, E> newBuilder(
|
@NonNull final Class<E> enumClass,
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
@NonNull final String name) {
|
||||||
return new EnumArgument.Builder<>(name, enumClass);
|
return new EnumArgument.Builder<>(name, enumClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,9 +78,9 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, E extends Enum<E>> @NonNull CommandArgument<C, E> required(
|
||||||
public static <C, E extends Enum<E>> CommandArgument<C, E> required(
|
@NonNull final Class<E> enumClass,
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
@NonNull final String name) {
|
||||||
return EnumArgument.<C, E>newBuilder(enumClass, name).asRequired().build();
|
return EnumArgument.<C, E>newBuilder(enumClass, name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,9 +93,9 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, E extends Enum<E>> @NonNull CommandArgument<C, E> optional(
|
||||||
public static <C, E extends Enum<E>> CommandArgument<C, E> optional(
|
@NonNull final Class<E> enumClass,
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
@NonNull final String name) {
|
||||||
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptional().build();
|
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,9 +109,10 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, E extends Enum<E>> @NonNull CommandArgument<C, E> optional(
|
||||||
public static <C, E extends Enum<E>> CommandArgument<C, E> optional(
|
@NonNull final Class<E> enumClass,
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name, @Nonnull final E defaultValue) {
|
@NonNull final String name,
|
||||||
|
@NonNull final E defaultValue) {
|
||||||
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
|
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,14 +121,13 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
|
|
||||||
private final Class<E> enumClass;
|
private final Class<E> enumClass;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name, @Nonnull final Class<E> enumClass) {
|
protected Builder(@NonNull final String name, @NonNull final Class<E> enumClass) {
|
||||||
super(enumClass, name);
|
super(enumClass, name);
|
||||||
this.enumClass = enumClass;
|
this.enumClass = enumClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public CommandArgument<C, E> build() {
|
public @NonNull CommandArgument<C, E> build() {
|
||||||
return new EnumArgument<>(this.enumClass, this.isRequired(), this.getName(),
|
return new EnumArgument<>(this.enumClass, this.isRequired(), this.getName(),
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -143,15 +144,14 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
*
|
*
|
||||||
* @param enumClass Enum class
|
* @param enumClass Enum class
|
||||||
*/
|
*/
|
||||||
public EnumParser(@Nonnull final Class<E> enumClass) {
|
public EnumParser(@NonNull final Class<E> enumClass) {
|
||||||
this.enumClass = enumClass;
|
this.enumClass = enumClass;
|
||||||
this.allowedValues = EnumSet.allOf(enumClass);
|
this.allowedValues = EnumSet.allOf(enumClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<E> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull ArgumentParseResult<E> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -167,9 +167,9 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
return ArgumentParseResult.failure(new EnumParseException(input, this.enumClass));
|
return ArgumentParseResult.failure(new EnumParseException(input, this.enumClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext, @Nonnull final String input) {
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
|
@NonNull final String input) {
|
||||||
return EnumSet.allOf(this.enumClass).stream().map(e -> e.name().toLowerCase()).collect(Collectors.toList());
|
return EnumSet.allOf(this.enumClass).stream().map(e -> e.name().toLowerCase()).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,14 +191,14 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
* @param input Input
|
* @param input Input
|
||||||
* @param enumClass Enum class
|
* @param enumClass Enum class
|
||||||
*/
|
*/
|
||||||
public EnumParseException(@Nonnull final String input, @Nonnull final Class<? extends Enum<?>> enumClass) {
|
public EnumParseException(@NonNull final String input,
|
||||||
|
@NonNull final Class<? extends Enum<?>> enumClass) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.enumClass = enumClass;
|
this.enumClass = enumClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private static String join(@Nonnull final Class<? extends Enum> clazz) {
|
private static @NonNull String join(@NonNull final Class<? extends Enum> clazz) {
|
||||||
final EnumSet<?> enumSet = EnumSet.allOf(clazz);
|
final EnumSet<?> enumSet = EnumSet.allOf(clazz);
|
||||||
return enumSet.stream()
|
return enumSet.stream()
|
||||||
.map(e -> e.toString().toLowerCase())
|
.map(e -> e.toString().toLowerCase())
|
||||||
|
|
@ -210,8 +210,7 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
*
|
*
|
||||||
* @return Input
|
* @return Input
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getInput() {
|
||||||
public String getInput() {
|
|
||||||
return this.input;
|
return this.input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,7 +219,7 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
*
|
*
|
||||||
* @return Enum class
|
* @return Enum class
|
||||||
*/
|
*/
|
||||||
public Class<? extends Enum<?>> getEnumClass() {
|
public @NonNull Class<? extends Enum<?>> getEnumClass() {
|
||||||
return this.enumClass;
|
return this.enumClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.standard;
|
package cloud.commandframework.arguments.standard;
|
||||||
|
|
||||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -42,11 +42,12 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
private final float max;
|
private final float max;
|
||||||
|
|
||||||
private FloatArgument(final boolean required,
|
private FloatArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
final float min,
|
final float min,
|
||||||
final float max,
|
final float max,
|
||||||
final String defaultValue,
|
@NonNull final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>,
|
||||||
|
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new FloatParser<>(min, max), defaultValue, Float.class, suggestionsProvider);
|
super(required, name, new FloatParser<>(min, max), defaultValue, Float.class, suggestionsProvider);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -59,8 +60,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +71,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Float> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Float> required(@Nonnull final String name) {
|
|
||||||
return FloatArgument.<C>newBuilder(name).asRequired().build();
|
return FloatArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,8 +82,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Float> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Float> optional(@Nonnull final String name) {
|
|
||||||
return FloatArgument.<C>newBuilder(name).asOptional().build();
|
return FloatArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,8 +94,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Float> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Float> optional(@Nonnull final String name,
|
|
||||||
final float defaultNum) {
|
final float defaultNum) {
|
||||||
return FloatArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
|
return FloatArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +122,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
private float min = Float.MIN_VALUE;
|
private float min = Float.MIN_VALUE;
|
||||||
private float max = Float.MAX_VALUE;
|
private float max = Float.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Float.class, name);
|
super(Float.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,8 +132,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMin(final int min) {
|
||||||
public Builder<C> withMin(final int min) {
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +143,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMax(final int max) {
|
||||||
public Builder<C> withMax(final int max) {
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +153,8 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public FloatArgument<C> build() {
|
public @NonNull FloatArgument<C> build() {
|
||||||
return new FloatArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
return new FloatArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -183,11 +177,10 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Float> parse(
|
public @NonNull ArgumentParseResult<Float> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -239,7 +232,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
*/
|
*/
|
||||||
public FloatParseException(@Nonnull final String input, final float min, final float max) {
|
public FloatParseException(@NonNull final String input, final float min, final float max) {
|
||||||
super(input, min, max);
|
super(input, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,8 +247,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public @NonNull String getNumberType() {
|
||||||
public String getNumberType() {
|
|
||||||
return "float";
|
return "float";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.standard;
|
package cloud.commandframework.arguments.standard;
|
||||||
|
|
||||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -49,11 +49,12 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
private final int max;
|
private final int max;
|
||||||
|
|
||||||
private IntegerArgument(final boolean required,
|
private IntegerArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
final int min,
|
final int min,
|
||||||
final int max,
|
final int max,
|
||||||
final String defaultValue,
|
final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new IntegerParser<>(min, max), defaultValue, Integer.class, suggestionsProvider);
|
super(required, name, new IntegerParser<>(min, max), defaultValue, Integer.class, suggestionsProvider);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -66,8 +67,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,8 +78,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Integer> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Integer> required(@Nonnull final String name) {
|
|
||||||
return IntegerArgument.<C>newBuilder(name).asRequired().build();
|
return IntegerArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,8 +89,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Integer> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Integer> optional(@Nonnull final String name) {
|
|
||||||
return IntegerArgument.<C>newBuilder(name).asOptional().build();
|
return IntegerArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,8 +101,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Integer> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Integer> optional(@Nonnull final String name,
|
|
||||||
final int defaultNum) {
|
final int defaultNum) {
|
||||||
return IntegerArgument.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
|
return IntegerArgument.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +129,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
private int min = Integer.MIN_VALUE;
|
private int min = Integer.MIN_VALUE;
|
||||||
private int max = Integer.MAX_VALUE;
|
private int max = Integer.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Integer.class, name);
|
super(Integer.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,8 +139,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMin(final int min) {
|
||||||
public Builder<C> withMin(final int min) {
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -154,8 +150,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMax(final int max) {
|
||||||
public Builder<C> withMax(final int max) {
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -165,9 +160,8 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public IntegerArgument<C> build() {
|
public @NonNull IntegerArgument<C> build() {
|
||||||
return new IntegerArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
return new IntegerArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -190,8 +184,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
static @NonNull List<@NonNull String> getSuggestions(final long min, final long max, @NonNull final String input) {
|
||||||
static List<String> getSuggestions(final long min, final long max, @Nonnull final String input) {
|
|
||||||
if (input.isEmpty()) {
|
if (input.isEmpty()) {
|
||||||
return IntStream.range(0, MAX_SUGGESTIONS_INCREMENT).mapToObj(Integer::toString).collect(Collectors.toList());
|
return IntStream.range(0, MAX_SUGGESTIONS_INCREMENT).mapToObj(Integer::toString).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
@ -213,11 +206,10 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Integer> parse(
|
public @NonNull ArgumentParseResult<Integer> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -257,10 +249,9 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
return getSuggestions(this.min, this.max, input);
|
return getSuggestions(this.min, this.max, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,7 +267,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
*/
|
*/
|
||||||
public IntegerParseException(@Nonnull final String input, final int min, final int max) {
|
public IntegerParseException(@NonNull final String input, final int min, final int max) {
|
||||||
super(input, min, max);
|
super(input, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,8 +282,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public @NonNull String getNumberType() {
|
||||||
public String getNumberType() {
|
|
||||||
return "integer";
|
return "integer";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.standard;
|
package cloud.commandframework.arguments.standard;
|
||||||
|
|
||||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -42,11 +42,12 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
private final long max;
|
private final long max;
|
||||||
|
|
||||||
private LongArgument(final boolean required,
|
private LongArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
final long min,
|
final long min,
|
||||||
final long max,
|
final long max,
|
||||||
final String defaultValue,
|
final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new LongParser<>(min, max), defaultValue, Long.class, suggestionsProvider);
|
super(required, name, new LongParser<>(min, max), defaultValue, Long.class, suggestionsProvider);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -59,8 +60,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> LongArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> LongArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +71,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Long> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Long> required(@Nonnull final String name) {
|
|
||||||
return LongArgument.<C>newBuilder(name).asRequired().build();
|
return LongArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,8 +82,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Long> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Long> optional(@Nonnull final String name) {
|
|
||||||
return LongArgument.<C>newBuilder(name).asOptional().build();
|
return LongArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,8 +94,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Long> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Long> optional(@Nonnull final String name,
|
|
||||||
final long defaultNum) {
|
final long defaultNum) {
|
||||||
return LongArgument.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
|
return LongArgument.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +122,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
private long min = Long.MIN_VALUE;
|
private long min = Long.MIN_VALUE;
|
||||||
private long max = Long.MAX_VALUE;
|
private long max = Long.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Long.class, name);
|
super(Long.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,8 +132,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMin(final long min) {
|
||||||
public Builder<C> withMin(final long min) {
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +143,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMax(final long max) {
|
||||||
public Builder<C> withMax(final long max) {
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +153,8 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public LongArgument<C> build() {
|
public @NonNull LongArgument<C> build() {
|
||||||
return new LongArgument<>(this.isRequired(), this.getName(), this.min,
|
return new LongArgument<>(this.isRequired(), this.getName(), this.min,
|
||||||
this.max, this.getDefaultValue(), this.getSuggestionsProvider());
|
this.max, this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -177,11 +171,10 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Long> parse(
|
public @NonNull ArgumentParseResult<Long> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -203,10 +196,9 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
|
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -222,7 +214,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
*/
|
*/
|
||||||
public LongParseException(@Nonnull final String input, final long min, final long max) {
|
public LongParseException(@NonNull final String input, final long min, final long max) {
|
||||||
super(input, min, max);
|
super(input, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,8 +229,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public @NonNull String getNumberType() {
|
||||||
public String getNumberType() {
|
|
||||||
return "long";
|
return "long";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
@ -41,10 +41,11 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
private final StringMode stringMode;
|
private final StringMode stringMode;
|
||||||
|
|
||||||
private StringArgument(final boolean required,
|
private StringArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final StringMode stringMode,
|
@NonNull final StringMode stringMode,
|
||||||
@Nonnull final String defaultValue,
|
@NonNull final String defaultValue,
|
||||||
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@NonNull final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new StringParser<>(stringMode, suggestionsProvider),
|
super(required, name, new StringParser<>(stringMode, suggestionsProvider),
|
||||||
defaultValue, String.class, suggestionsProvider);
|
defaultValue, String.class, suggestionsProvider);
|
||||||
this.stringMode = stringMode;
|
this.stringMode = stringMode;
|
||||||
|
|
@ -57,8 +58,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> StringArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> StringArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new StringArgument.Builder<>(name);
|
return new StringArgument.Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,8 +69,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, String> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, String> required(@Nonnull final String name) {
|
|
||||||
return StringArgument.<C>newBuilder(name).single().asRequired().build();
|
return StringArgument.<C>newBuilder(name).single().asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,8 +81,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, String> required(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, String> required(@Nonnull final String name, @Nonnull final StringMode stringMode) {
|
@NonNull final StringMode stringMode) {
|
||||||
return StringArgument.<C>newBuilder(name).withMode(stringMode).asRequired().build();
|
return StringArgument.<C>newBuilder(name).withMode(stringMode).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,8 +93,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, String> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, String> optional(@Nonnull final String name) {
|
|
||||||
return StringArgument.<C>newBuilder(name).single().asOptional().build();
|
return StringArgument.<C>newBuilder(name).single().asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,8 +105,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, String> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, String> optional(@Nonnull final String name, @Nonnull final StringMode stringMode) {
|
@NonNull final StringMode stringMode) {
|
||||||
return StringArgument.<C>newBuilder(name).withMode(stringMode).asOptional().build();
|
return StringArgument.<C>newBuilder(name).withMode(stringMode).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,14 +114,13 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* Create a new required command argument with a default value
|
* Create a new required command argument with a default value
|
||||||
*
|
*
|
||||||
* @param name Argument name
|
* @param name Argument name
|
||||||
* @param defaultNum Default num
|
* @param defaultString Default string
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, String> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, String> optional(@Nonnull final String name,
|
@NonNull String defaultString) {
|
||||||
final String defaultNum) {
|
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultString).build();
|
||||||
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,8 +128,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return String mode
|
* @return String mode
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull StringMode getStringMode() {
|
||||||
public StringMode getStringMode() {
|
|
||||||
return this.stringMode;
|
return this.stringMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,12 +145,11 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
private StringMode stringMode = StringMode.SINGLE;
|
private StringMode stringMode = StringMode.SINGLE;
|
||||||
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(String.class, name);
|
super(String.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull Builder<C> withMode(@NonNull final StringMode stringMode) {
|
||||||
private Builder<C> withMode(@Nonnull final StringMode stringMode) {
|
|
||||||
this.stringMode = stringMode;
|
this.stringMode = stringMode;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -164,8 +159,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> greedy() {
|
||||||
public Builder<C> greedy() {
|
|
||||||
this.stringMode = StringMode.GREEDY;
|
this.stringMode = StringMode.GREEDY;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -175,8 +169,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> single() {
|
||||||
public Builder<C> single() {
|
|
||||||
this.stringMode = StringMode.SINGLE;
|
this.stringMode = StringMode.SINGLE;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -186,8 +179,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> quoted() {
|
||||||
public Builder<C> quoted() {
|
|
||||||
this.stringMode = StringMode.QUOTED;
|
this.stringMode = StringMode.QUOTED;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -198,9 +190,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param suggestionsProvider Suggestions provider
|
* @param suggestionsProvider Suggestions provider
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withSuggestionsProvider(@NonNull final BiFunction<@NonNull CommandContext<C>,
|
||||||
public Builder<C> withSuggestionsProvider(@Nonnull final BiFunction<CommandContext<C>,
|
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
String, List<String>> suggestionsProvider) {
|
|
||||||
this.suggestionsProvider = suggestionsProvider;
|
this.suggestionsProvider = suggestionsProvider;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -210,9 +201,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public StringArgument<C> build() {
|
public @NonNull StringArgument<C> build() {
|
||||||
return new StringArgument<>(this.isRequired(), this.getName(), this.stringMode,
|
return new StringArgument<>(this.isRequired(), this.getName(), this.stringMode,
|
||||||
this.getDefaultValue(), this.suggestionsProvider);
|
this.getDefaultValue(), this.suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
@ -231,16 +221,16 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param stringMode String parsing mode
|
* @param stringMode String parsing mode
|
||||||
* @param suggestionsProvider Suggestions provider
|
* @param suggestionsProvider Suggestions provider
|
||||||
*/
|
*/
|
||||||
public StringParser(@Nonnull final StringMode stringMode,
|
public StringParser(@NonNull final StringMode stringMode,
|
||||||
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@NonNull final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
this.stringMode = stringMode;
|
this.stringMode = stringMode;
|
||||||
this.suggestionsProvider = suggestionsProvider;
|
this.suggestionsProvider = suggestionsProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull ArgumentParseResult<String> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -303,9 +293,9 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
return ArgumentParseResult.success(sj.toString());
|
return ArgumentParseResult.success(sj.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext, @Nonnull final String input) {
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
|
@NonNull final String input) {
|
||||||
return this.suggestionsProvider.apply(commandContext, input);
|
return this.suggestionsProvider.apply(commandContext, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,8 +309,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return String mode
|
* @return String mode
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull StringMode getStringMode() {
|
||||||
public StringMode getStringMode() {
|
|
||||||
return this.stringMode;
|
return this.stringMode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -337,7 +326,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param input Input
|
* @param input Input
|
||||||
* @param stringMode String mode
|
* @param stringMode String mode
|
||||||
*/
|
*/
|
||||||
public StringParseException(@Nonnull final String input, @Nonnull final StringMode stringMode) {
|
public StringParseException(@NonNull final String input, @NonNull final StringMode stringMode) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.stringMode = stringMode;
|
this.stringMode = stringMode;
|
||||||
}
|
}
|
||||||
|
|
@ -348,8 +337,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Input
|
* @return Input
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getInput() {
|
||||||
public String getInput() {
|
|
||||||
return this.input;
|
return this.input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,8 +346,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return String mode
|
* @return String mode
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull StringMode getStringMode() {
|
||||||
public StringMode getStringMode() {
|
|
||||||
return this.stringMode;
|
return this.stringMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -39,9 +39,10 @@ import java.util.function.BiFunction;
|
||||||
public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
|
|
||||||
private UUIDArgument(final boolean required,
|
private UUIDArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final String defaultValue,
|
@NonNull final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>,
|
||||||
|
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
|
||||||
super(required, name, new UUIDParser<>(), defaultValue, UUID.class, suggestionsProvider);
|
super(required, name, new UUIDParser<>(), defaultValue, UUID.class, suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,8 +53,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,8 +64,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created component
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, UUID> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, UUID> required(@Nonnull final String name) {
|
|
||||||
return UUIDArgument.<C>newBuilder(name).asRequired().build();
|
return UUIDArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,8 +75,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created component
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, UUID> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, UUID> optional(@Nonnull final String name) {
|
|
||||||
return UUIDArgument.<C>newBuilder(name).asOptional().build();
|
return UUIDArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,16 +87,15 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created component
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, UUID> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, UUID> optional(@Nonnull final String name,
|
@NonNull final UUID defaultUUID) {
|
||||||
final UUID defaultUUID) {
|
|
||||||
return UUIDArgument.<C>newBuilder(name).asOptionalWithDefault(defaultUUID.toString()).build();
|
return UUIDArgument.<C>newBuilder(name).asOptionalWithDefault(defaultUUID.toString()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, UUID> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, UUID> {
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(UUID.class, name);
|
super(UUID.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,9 +104,8 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
*
|
*
|
||||||
* @return Constructed component
|
* @return Constructed component
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public UUIDArgument<C> build() {
|
public @NonNull UUIDArgument<C> build() {
|
||||||
return new UUIDArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
return new UUIDArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,11 +114,10 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
|
|
||||||
private static final class UUIDParser<C> implements ArgumentParser<C, UUID> {
|
private static final class UUIDParser<C> implements ArgumentParser<C, UUID> {
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<UUID> parse(
|
public @NonNull ArgumentParseResult<UUID> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -151,7 +146,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
*
|
*
|
||||||
* @param input String input
|
* @param input String input
|
||||||
*/
|
*/
|
||||||
public UUIDParseException(@Nonnull final String input) {
|
public UUIDParseException(@NonNull final String input) {
|
||||||
super(input);
|
super(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,12 +101,11 @@ public class Pair<U, V> implements Tuple {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getSize() {
|
public final int getSize() {
|
||||||
return Tuples.SIZE_PAIR;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final Object[] toArray() {
|
public final @NonNull Object @NonNull [] toArray() {
|
||||||
final Object[] array = new Object[2];
|
final Object[] array = new Object[2];
|
||||||
array[0] = this.first;
|
array[0] = this.first;
|
||||||
array[1] = this.second;
|
array[1] = this.second;
|
||||||
|
|
|
||||||
|
|
@ -135,12 +135,11 @@ public class Quartet<U, V, W, X> implements Tuple {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getSize() {
|
public final int getSize() {
|
||||||
return Tuples.SIZE_QUARTET;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final Object[] toArray() {
|
public final @NonNull Object @NonNull [] toArray() {
|
||||||
final Object[] array = new Object[4];
|
final Object[] array = new Object[4];
|
||||||
array[0] = this.first;
|
array[0] = this.first;
|
||||||
array[1] = this.second;
|
array[1] = this.second;
|
||||||
|
|
|
||||||
|
|
@ -153,12 +153,11 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getSize() {
|
public final int getSize() {
|
||||||
return Tuples.SIZE_QUINTET;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final Object[] toArray() {
|
public final @NonNull Object @NonNull [] toArray() {
|
||||||
final Object[] array = new Object[5];
|
final Object[] array = new Object[5];
|
||||||
array[0] = this.first;
|
array[0] = this.first;
|
||||||
array[1] = this.second;
|
array[1] = this.second;
|
||||||
|
|
|
||||||
|
|
@ -171,12 +171,11 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getSize() {
|
public final int getSize() {
|
||||||
return Tuples.SIZE_SEXTET;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final Object[] toArray() {
|
public @NonNull final Object @NonNull [] toArray() {
|
||||||
final Object[] array = new Object[6];
|
final Object[] array = new Object[6];
|
||||||
array[0] = this.first;
|
array[0] = this.first;
|
||||||
array[1] = this.second;
|
array[1] = this.second;
|
||||||
|
|
|
||||||
|
|
@ -118,12 +118,11 @@ public class Triplet<U, V, W> implements Tuple {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getSize() {
|
public final int getSize() {
|
||||||
return Tuples.SIZE_TRIPLET;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final Object[] toArray() {
|
public final @NonNull Object @NonNull [] toArray() {
|
||||||
final Object[] array = new Object[3];
|
final Object[] array = new Object[3];
|
||||||
array[0] = this.first;
|
array[0] = this.first;
|
||||||
array[1] = this.second;
|
array[1] = this.second;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.types.tuples;
|
package cloud.commandframework.types.tuples;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tuple type
|
* Tuple type
|
||||||
|
|
@ -42,7 +42,6 @@ public interface Tuple {
|
||||||
*
|
*
|
||||||
* @return Created array
|
* @return Created array
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@NonNull Object @NonNull [] toArray();
|
||||||
Object[] toArray();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import cloud.commandframework.exceptions.NoSuchCommandException;
|
||||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jline.reader.Candidate;
|
import org.jline.reader.Candidate;
|
||||||
import org.jline.reader.Completer;
|
import org.jline.reader.Completer;
|
||||||
import org.jline.reader.LineReader;
|
import org.jline.reader.LineReader;
|
||||||
|
|
@ -40,7 +41,6 @@ import org.jline.reader.ParsedLine;
|
||||||
import org.jline.terminal.Terminal;
|
import org.jline.terminal.Terminal;
|
||||||
import org.jline.terminal.TerminalBuilder;
|
import org.jline.terminal.TerminalBuilder;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
|
||||||
*
|
*
|
||||||
* @param executionCoordinatorFunction Function producing a new coordinator
|
* @param executionCoordinatorFunction Function producing a new coordinator
|
||||||
*/
|
*/
|
||||||
public JLineCommandManager(@Nonnull final Function<CommandTree<JLineCommandSender>,
|
public JLineCommandManager(@NonNull final Function<CommandTree<JLineCommandSender>,
|
||||||
CommandExecutionCoordinator<JLineCommandSender>> executionCoordinatorFunction) {
|
CommandExecutionCoordinator<JLineCommandSender>> executionCoordinatorFunction) {
|
||||||
super(executionCoordinatorFunction, CommandRegistrationHandler.nullCommandRegistrationHandler());
|
super(executionCoordinatorFunction, CommandRegistrationHandler.nullCommandRegistrationHandler());
|
||||||
}
|
}
|
||||||
|
|
@ -138,9 +138,9 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void complete(@Nonnull final LineReader lineReader,
|
public final void complete(@NonNull final LineReader lineReader,
|
||||||
@Nonnull final ParsedLine parsedLine,
|
@NonNull final ParsedLine parsedLine,
|
||||||
@Nonnull final List<Candidate> list) {
|
@NonNull final List<@NonNull Candidate> list) {
|
||||||
final String line = parsedLine.line();
|
final String line = parsedLine.line();
|
||||||
if (line == null || line.isEmpty() || !line.startsWith("/")) {
|
if (line == null || line.isEmpty() || !line.startsWith("/")) {
|
||||||
System.out.println("Cannot suggest: empty line");
|
System.out.println("Cannot suggest: empty line");
|
||||||
|
|
@ -149,14 +149,14 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
|
||||||
System.out.printf("Trying to complete '%s'\n", line);
|
System.out.printf("Trying to complete '%s'\n", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final SimpleCommandMeta createDefaultCommandMeta() {
|
public final @NonNull SimpleCommandMeta createDefaultCommandMeta() {
|
||||||
return SimpleCommandMeta.empty();
|
return SimpleCommandMeta.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasPermission(@Nonnull final JLineCommandSender sender, @Nonnull final String permission) {
|
public final boolean hasPermission(@NonNull final JLineCommandSender sender,
|
||||||
|
@NonNull final String permission) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
@ -94,8 +94,8 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
* @param commandManager Command manager
|
* @param commandManager Command manager
|
||||||
* @param dummyContextProvider Provider of dummy context for completions
|
* @param dummyContextProvider Provider of dummy context for completions
|
||||||
*/
|
*/
|
||||||
public CloudBrigadierManager(@Nonnull final CommandManager<C> commandManager,
|
public CloudBrigadierManager(@NonNull final CommandManager<C> commandManager,
|
||||||
@Nonnull final Supplier<CommandContext<C>>
|
@NonNull final Supplier<@NonNull CommandContext<C>>
|
||||||
dummyContextProvider) {
|
dummyContextProvider) {
|
||||||
this.mappers = new HashMap<>();
|
this.mappers = new HashMap<>();
|
||||||
this.defaultArgumentTypeSuppliers = new HashMap<>();
|
this.defaultArgumentTypeSuppliers = new HashMap<>();
|
||||||
|
|
@ -194,9 +194,9 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
* @param <K> cloud argument type
|
* @param <K> cloud argument type
|
||||||
* @param <O> Brigadier argument type value
|
* @param <O> Brigadier argument type value
|
||||||
*/
|
*/
|
||||||
public <T, K extends ArgumentParser<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> argumentType,
|
public <T, K extends ArgumentParser<C, T>, O> void registerMapping(@NonNull final TypeToken<K> argumentType,
|
||||||
@Nonnull final Function<? extends K,
|
@NonNull final Function<@NonNull ? extends K,
|
||||||
? extends ArgumentType<O>> mapper) {
|
@NonNull ? extends ArgumentType<O>> mapper) {
|
||||||
this.mappers.put(GenericTypeReflector.erase(argumentType.getType()), mapper);
|
this.mappers.put(GenericTypeReflector.erase(argumentType.getType()), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,17 +206,16 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
* @param clazz Type to map
|
* @param clazz Type to map
|
||||||
* @param supplier Supplier that supplies the argument type
|
* @param supplier Supplier that supplies the argument type
|
||||||
*/
|
*/
|
||||||
public void registerDefaultArgumentTypeSupplier(@Nonnull final Class<?> clazz,
|
public void registerDefaultArgumentTypeSupplier(@NonNull final Class<?> clazz,
|
||||||
@Nonnull final Supplier<ArgumentType<?>> supplier) {
|
@NonNull final Supplier<@NonNull ArgumentType<?>> supplier) {
|
||||||
this.defaultArgumentTypeSuppliers.put(clazz, supplier);
|
this.defaultArgumentTypeSuppliers.put(clazz, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private <T, K extends ArgumentParser<?, ?>> Pair<ArgumentType<?>, Boolean> getArgument(
|
private <T, K extends ArgumentParser<?, ?>> @Nullable Pair<@NonNull ArgumentType<?>, @NonNull Boolean> getArgument(
|
||||||
@Nonnull final TypeToken<?> valueType,
|
@NonNull final TypeToken<?> valueType,
|
||||||
@Nonnull final TypeToken<T> argumentType,
|
@NonNull final TypeToken<T> argumentType,
|
||||||
@Nonnull final K argument) {
|
@NonNull final K argument) {
|
||||||
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
||||||
Function function = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
|
Function function = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
|
||||||
if (function == null) {
|
if (function == null) {
|
||||||
|
|
@ -225,11 +224,11 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
return new Pair<>((ArgumentType<?>) function.apply(commandArgument), !(argument instanceof StringArgument.StringParser));
|
return new Pair<>((ArgumentType<?>) function.apply(commandArgument), !(argument instanceof StringArgument.StringParser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private <T, K extends ArgumentParser<C, T>> @NonNull Pair<@NonNull ArgumentType<?>, @NonNull Boolean> createDefaultMapper(
|
||||||
private <T, K extends ArgumentParser<C, T>> Pair<ArgumentType<?>, Boolean> createDefaultMapper(
|
@NonNull final TypeToken<?> clazz,
|
||||||
@Nonnull final TypeToken<?> clazz,
|
@NonNull final ArgumentParser<C, T> argument) {
|
||||||
@Nonnull final ArgumentParser<C, T> argument) {
|
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers
|
||||||
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers.get(clazz.getRawType());
|
.get(GenericTypeReflector.erase(clazz.getType()));
|
||||||
if (argumentTypeSupplier != null) {
|
if (argumentTypeSupplier != null) {
|
||||||
return new Pair<>(argumentTypeSupplier.get(), true);
|
return new Pair<>(argumentTypeSupplier.get(), true);
|
||||||
}
|
}
|
||||||
|
|
@ -245,10 +244,11 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
* @param executor Command executor
|
* @param executor Command executor
|
||||||
* @return Literal command node
|
* @return Literal command node
|
||||||
*/
|
*/
|
||||||
public LiteralCommandNode<S> createLiteralCommandNode(@Nonnull final String label,
|
public @NonNull LiteralCommandNode<S> createLiteralCommandNode(@NonNull final String label,
|
||||||
@Nonnull final Command<C> cloudCommand,
|
@NonNull final Command<C> cloudCommand,
|
||||||
@Nonnull final BiPredicate<S, CommandPermission> permissionChecker,
|
@NonNull final BiPredicate<@NonNull S,
|
||||||
@Nonnull final com.mojang.brigadier.Command<S> executor) {
|
@NonNull CommandPermission> permissionChecker,
|
||||||
|
final com.mojang.brigadier.@NonNull Command<S> executor) {
|
||||||
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager
|
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager
|
||||||
.getCommandTree().getNamedNode(cloudCommand.getArguments().get(0).getName());
|
.getCommandTree().getNamedNode(cloudCommand.getArguments().get(0).getName());
|
||||||
final SuggestionProvider<S> provider = (context, builder) -> this.buildSuggestions(node.getValue(), context, builder);
|
final SuggestionProvider<S> provider = (context, builder) -> this.buildSuggestions(node.getValue(), context, builder);
|
||||||
|
|
@ -275,12 +275,12 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
* @param permissionChecker Permission checker
|
* @param permissionChecker Permission checker
|
||||||
* @return Constructed literal command node
|
* @return Constructed literal command node
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull LiteralCommandNode<S> createLiteralCommandNode(
|
||||||
public LiteralCommandNode<S> createLiteralCommandNode(@Nonnull final CommandTree.Node<CommandArgument<C, ?>> cloudCommand,
|
final CommandTree.@NonNull Node<@NonNull CommandArgument<C, ?>> cloudCommand,
|
||||||
@Nonnull final LiteralCommandNode<S> root,
|
@NonNull final LiteralCommandNode<S> root,
|
||||||
@Nonnull final SuggestionProvider<S> suggestionProvider,
|
@NonNull final SuggestionProvider<S> suggestionProvider,
|
||||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
final com.mojang.brigadier.@NonNull Command<S> executor,
|
||||||
@Nonnull final BiPredicate<S, CommandPermission> permissionChecker) {
|
@NonNull final BiPredicate<@NonNull S, @NonNull CommandPermission> permissionChecker) {
|
||||||
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder.<S>literal(root.getLiteral())
|
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder.<S>literal(root.getLiteral())
|
||||||
.requires(sender -> permissionChecker.test(sender, (CommandPermission) cloudCommand.getNodeMeta()
|
.requires(sender -> permissionChecker.test(sender, (CommandPermission) cloudCommand.getNodeMeta()
|
||||||
.getOrDefault("permission", Permission.empty())));
|
.getOrDefault("permission", Permission.empty())));
|
||||||
|
|
@ -295,11 +295,12 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
return constructedRoot;
|
return constructedRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArgumentBuilder<S, ?> constructCommandNode(final boolean forceExecutor,
|
private @NonNull ArgumentBuilder<S, ?> constructCommandNode(
|
||||||
@Nonnull final CommandTree.Node<CommandArgument<C, ?>> root,
|
final boolean forceExecutor,
|
||||||
@Nonnull final BiPredicate<S, CommandPermission> permissionChecker,
|
final CommandTree.@NonNull Node<CommandArgument<C, ?>> root,
|
||||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
@NonNull final BiPredicate<@NonNull S, @NonNull CommandPermission> permissionChecker,
|
||||||
@Nonnull final SuggestionProvider<S> suggestionProvider) {
|
final com.mojang.brigadier.@NonNull Command<S> executor,
|
||||||
|
final SuggestionProvider<S> suggestionProvider) {
|
||||||
if (root.getValue() instanceof CompoundArgument) {
|
if (root.getValue() instanceof CompoundArgument) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final CompoundArgument<?, C, ?> compoundArgument = (CompoundArgument<?, C, ?>) root.getValue();
|
final CompoundArgument<?, C, ?> compoundArgument = (CompoundArgument<?, C, ?>) root.getValue();
|
||||||
|
|
@ -313,8 +314,8 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
for (int i = parsers.length - 1; i >= 0; i--) {
|
for (int i = parsers.length - 1; i >= 0; i--) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) parsers[i];
|
final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) parsers[i];
|
||||||
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(TypeToken.of((Class<?>) types[i]),
|
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(TypeToken.get((Class<?>) types[i]),
|
||||||
TypeToken.of(parser.getClass()),
|
TypeToken.get(parser.getClass()),
|
||||||
parser);
|
parser);
|
||||||
final SuggestionProvider<S> provider = pair.getRight() ? null : suggestionProvider;
|
final SuggestionProvider<S> provider = pair.getRight() ? null : suggestionProvider;
|
||||||
final ArgumentBuilder<S, ?> fragmentBuilder = RequiredArgumentBuilder
|
final ArgumentBuilder<S, ?> fragmentBuilder = RequiredArgumentBuilder
|
||||||
|
|
@ -369,10 +370,10 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
return argumentBuilder;
|
return argumentBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull CompletableFuture<Suggestions> buildSuggestions(
|
||||||
private CompletableFuture<Suggestions> buildSuggestions(@Nonnull final CommandArgument<C, ?> argument,
|
@NonNull final CommandArgument<C, ?> argument,
|
||||||
@Nonnull final com.mojang.brigadier.context.CommandContext<S> s,
|
final com.mojang.brigadier.context.@NonNull CommandContext<S> s,
|
||||||
@Nonnull final SuggestionsBuilder builder) {
|
@NonNull final SuggestionsBuilder builder) {
|
||||||
final CommandContext<C> commandContext = this.dummyContextProvider.get();
|
final CommandContext<C> commandContext = this.dummyContextProvider.get();
|
||||||
final LinkedList<String> inputQueue = new LinkedList<>(Collections.singletonList(builder.getInput()));
|
final LinkedList<String> inputQueue = new LinkedList<>(Collections.singletonList(builder.getInput()));
|
||||||
final CommandPreprocessingContext<C> commandPreprocessingContext =
|
final CommandPreprocessingContext<C> commandPreprocessingContext =
|
||||||
|
|
@ -416,18 +417,17 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
private final L left;
|
private final L left;
|
||||||
private final R right;
|
private final R right;
|
||||||
|
|
||||||
private Pair(@Nonnull final L left, @Nonnull final R right) {
|
private Pair(@NonNull final L left,
|
||||||
|
@NonNull final R right) {
|
||||||
this.left = left;
|
this.left = left;
|
||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull L getLeft() {
|
||||||
private L getLeft() {
|
|
||||||
return this.left;
|
return this.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull R getRight() {
|
||||||
private R getRight() {
|
|
||||||
return this.right;
|
return this.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
||||||
|
|
@ -51,11 +51,11 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
private final Command<C> cloudCommand;
|
private final Command<C> cloudCommand;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
BukkitCommand(@Nonnull final String label,
|
BukkitCommand(@NonNull final String label,
|
||||||
@Nonnull final List<String> aliases,
|
@NonNull final List<@NonNull String> aliases,
|
||||||
@Nonnull final Command<C> cloudCommand,
|
@NonNull final Command<C> cloudCommand,
|
||||||
@Nonnull final CommandArgument<C, ?> command,
|
@NonNull final CommandArgument<C, ?> command,
|
||||||
@Nonnull final BukkitCommandManager<C> manager) {
|
@NonNull final BukkitCommandManager<C> manager) {
|
||||||
super(label,
|
super(label,
|
||||||
cloudCommand.getCommandMeta().getOrDefault("description", ""),
|
cloudCommand.getCommandMeta().getOrDefault("description", ""),
|
||||||
"",
|
"",
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -71,11 +71,11 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||||
* @throws Exception If the construction of the manager fails
|
* @throws Exception If the construction of the manager fails
|
||||||
*/
|
*/
|
||||||
public BukkitCommandManager(@Nonnull final Plugin owningPlugin,
|
public BukkitCommandManager(@NonNull final Plugin owningPlugin,
|
||||||
@Nonnull final Function<CommandTree<C>,
|
@NonNull final Function<@NonNull CommandTree<C>,
|
||||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
@NonNull final Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
|
@NonNull final Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler<>());
|
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler<>());
|
||||||
((BukkitPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
((BukkitPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||||
|
|
@ -117,8 +117,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Owning plugin
|
* @return Owning plugin
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Plugin getOwningPlugin() {
|
||||||
public Plugin getOwningPlugin() {
|
|
||||||
return this.owningPlugin;
|
return this.owningPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,9 +126,8 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Meta data
|
* @return Meta data
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public BukkitCommandMeta createDefaultCommandMeta() {
|
public @NonNull BukkitCommandMeta createDefaultCommandMeta() {
|
||||||
return BukkitCommandMetaBuilder.builder().withDescription("").build();
|
return BukkitCommandMetaBuilder.builder().withDescription("").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,13 +136,12 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Command sender mapper
|
* @return Command sender mapper
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public final @NonNull Function<@NonNull CommandSender, @NonNull C> getCommandSenderMapper() {
|
||||||
public final Function<CommandSender, C> getCommandSenderMapper() {
|
|
||||||
return this.commandSenderMapper;
|
return this.commandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasPermission(@Nonnull final C sender, @Nonnull final String permission) {
|
public final boolean hasPermission(@NonNull final C sender, @NonNull final String permission) {
|
||||||
if (permission.isEmpty()) {
|
if (permission.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +169,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
* @param capability Capability
|
* @param capability Capability
|
||||||
* @return {@code true} if the manager has the given capability, else {@code false}
|
* @return {@code true} if the manager has the given capability, else {@code false}
|
||||||
*/
|
*/
|
||||||
public final boolean queryCapability(@Nonnull final CloudBukkitCapabilities capability) {
|
public final boolean queryCapability(@NonNull final CloudBukkitCapabilities capability) {
|
||||||
return this.queryCapabilities().contains(capability);
|
return this.queryCapabilities().contains(capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +178,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return A set containing all capabilities of the instance
|
* @return A set containing all capabilities of the instance
|
||||||
*/
|
*/
|
||||||
public final Set<CloudBukkitCapabilities> queryCapabilities() {
|
public final @NonNull Set<@NonNull CloudBukkitCapabilities> queryCapabilities() {
|
||||||
if (this.paper) {
|
if (this.paper) {
|
||||||
if (this.minecraftVersion >= BRIGADIER_MINIMAL_VERSION) {
|
if (this.minecraftVersion >= BRIGADIER_MINIMAL_VERSION) {
|
||||||
if (this.minecraftVersion >= PAPER_BRIGADIER_VERSION) {
|
if (this.minecraftVersion >= PAPER_BRIGADIER_VERSION) {
|
||||||
|
|
@ -226,8 +223,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return The backwards command sender mapper
|
* @return The backwards command sender mapper
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public final @NonNull Function<@NonNull C, @NonNull CommandSender> getBackwardsCommandSenderMapper() {
|
||||||
public final Function<C, CommandSender> getBackwardsCommandSenderMapper() {
|
|
||||||
return this.backwardsCommandSenderMapper;
|
return this.backwardsCommandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,7 +244,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @param reason Reason
|
* @param reason Reason
|
||||||
*/
|
*/
|
||||||
public BrigadierFailureException(@Nonnull final BrigadierFailureReason reason) {
|
public BrigadierFailureException(@NonNull final BrigadierFailureReason reason) {
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,7 +254,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
* @param reason Reason
|
* @param reason Reason
|
||||||
* @param cause Cause
|
* @param cause Cause
|
||||||
*/
|
*/
|
||||||
public BrigadierFailureException(@Nonnull final BrigadierFailureReason reason, @Nonnull final Throwable cause) {
|
public BrigadierFailureException(@NonNull final BrigadierFailureReason reason, @NonNull final Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
@ -268,8 +264,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Reason
|
* @return Reason
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull BrigadierFailureReason getReason() {
|
||||||
public BrigadierFailureReason getReason() {
|
|
||||||
return this.reason;
|
return this.reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ package cloud.commandframework.bukkit;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
||||||
|
|
@ -41,7 +40,7 @@ public abstract class BukkitCommandSender {
|
||||||
*
|
*
|
||||||
* @param internalSender Bukkit command sender
|
* @param internalSender Bukkit command sender
|
||||||
*/
|
*/
|
||||||
public BukkitCommandSender(@Nonnull final org.bukkit.command.CommandSender internalSender) {
|
public BukkitCommandSender(final org.bukkit.command.@NonNull CommandSender internalSender) {
|
||||||
this.internalSender = internalSender;
|
this.internalSender = internalSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,8 +50,7 @@ public abstract class BukkitCommandSender {
|
||||||
* @param player Player instance
|
* @param player Player instance
|
||||||
* @return Constructed command sender
|
* @return Constructed command sender
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull BukkitCommandSender player(@NonNull final Player player) {
|
||||||
public static BukkitCommandSender player(@Nonnull final Player player) {
|
|
||||||
return new BukkitPlayerSender(player);
|
return new BukkitPlayerSender(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,8 +59,7 @@ public abstract class BukkitCommandSender {
|
||||||
*
|
*
|
||||||
* @return Constructed command sender
|
* @return Constructed command sender
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull BukkitCommandSender console() {
|
||||||
public static BukkitCommandSender console() {
|
|
||||||
return new BukkitConsoleSender();
|
return new BukkitConsoleSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,8 +69,7 @@ public abstract class BukkitCommandSender {
|
||||||
* @param sender Bukkit command sender
|
* @param sender Bukkit command sender
|
||||||
* @return Constructed command sender
|
* @return Constructed command sender
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull BukkitCommandSender of(final org.bukkit.command.@NonNull CommandSender sender) {
|
||||||
public static BukkitCommandSender of(@Nonnull final org.bukkit.command.CommandSender sender) {
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return player((Player) sender);
|
return player((Player) sender);
|
||||||
}
|
}
|
||||||
|
|
@ -102,8 +98,7 @@ public abstract class BukkitCommandSender {
|
||||||
*
|
*
|
||||||
* @return Proxied command sneder
|
* @return Proxied command sneder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public org.bukkit.command.@NonNull CommandSender getInternalSender() {
|
||||||
public org.bukkit.command.CommandSender getInternalSender() {
|
|
||||||
return this.internalSender;
|
return this.internalSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,15 +115,14 @@ public abstract class BukkitCommandSender {
|
||||||
*
|
*
|
||||||
* @return Player object
|
* @return Player object
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull Player asPlayer();
|
||||||
public abstract Player asPlayer();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the command sender
|
* Send a message to the command sender
|
||||||
*
|
*
|
||||||
* @param message Message to send
|
* @param message Message to send
|
||||||
*/
|
*/
|
||||||
public void sendMessage(@Nonnull final String message) {
|
public void sendMessage(@NonNull final String message) {
|
||||||
this.internalSender.sendMessage(message);
|
this.internalSender.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,11 @@
|
||||||
package cloud.commandframework.bukkit;
|
package cloud.commandframework.bukkit;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
final class BukkitPlayerSender extends BukkitCommandSender {
|
final class BukkitPlayerSender extends BukkitCommandSender {
|
||||||
|
|
||||||
BukkitPlayerSender(@Nonnull final Player player) {
|
BukkitPlayerSender(@NonNull final Player player) {
|
||||||
super(player);
|
super(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,9 +37,8 @@ final class BukkitPlayerSender extends BukkitCommandSender {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Player asPlayer() {
|
public @NonNull Player asPlayer() {
|
||||||
return (Player) this.getInternalSender();
|
return (Player) this.getInternalSender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
||||||
public final class BungeeCommand<C> extends Command implements TabExecutor {
|
public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||||
|
|
@ -51,9 +51,9 @@ public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||||
private final cloud.commandframework.Command<C> cloudCommand;
|
private final cloud.commandframework.Command<C> cloudCommand;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
BungeeCommand(@Nonnull final cloud.commandframework.Command<C> cloudCommand,
|
BungeeCommand(final cloud.commandframework.@NonNull Command<C> cloudCommand,
|
||||||
@Nonnull final CommandArgument<C, ?> command,
|
@NonNull final CommandArgument<C, ?> command,
|
||||||
@Nonnull final BungeeCommandManager<C> manager) {
|
@NonNull final BungeeCommandManager<C> manager) {
|
||||||
super(command.getName(),
|
super(command.getName(),
|
||||||
cloudCommand.getCommandPermission().toString(),
|
cloudCommand.getCommandPermission().toString(),
|
||||||
((StaticArgument<C>) command).getAlternativeAliases().toArray(new String[0]));
|
((StaticArgument<C>) command).getAlternativeAliases().toArray(new String[0]));
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class BungeeCommandManager<C> extends CommandManager<C> {
|
public class BungeeCommandManager<C> extends CommandManager<C> {
|
||||||
|
|
@ -48,11 +48,11 @@ public class BungeeCommandManager<C> extends CommandManager<C> {
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||||
* @throws Exception If the construction of the manager fails
|
* @throws Exception If the construction of the manager fails
|
||||||
*/
|
*/
|
||||||
public BungeeCommandManager(@Nonnull final Plugin owningPlugin,
|
public BungeeCommandManager(@NonNull final Plugin owningPlugin,
|
||||||
@Nonnull final Function<CommandTree<C>,
|
@NonNull final Function<@NonNull CommandTree<C>,
|
||||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
@NonNull final Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
|
@NonNull final Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
super(commandExecutionCoordinator, new BungeePluginRegistrationHandler<>());
|
super(commandExecutionCoordinator, new BungeePluginRegistrationHandler<>());
|
||||||
((BungeePluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
((BungeePluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||||
|
|
@ -62,22 +62,20 @@ public class BungeeCommandManager<C> extends CommandManager<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasPermission(@Nonnull final C sender,
|
public final boolean hasPermission(@NonNull final C sender,
|
||||||
@Nonnull final String permission) {
|
@NonNull final String permission) {
|
||||||
if (permission.isEmpty()) {
|
if (permission.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final SimpleCommandMeta createDefaultCommandMeta() {
|
public final @NonNull SimpleCommandMeta createDefaultCommandMeta() {
|
||||||
return SimpleCommandMeta.empty();
|
return SimpleCommandMeta.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
final @NonNull Function<@NonNull CommandSender, @NonNull C> getCommandSenderMapper() {
|
||||||
final Function<CommandSender, C> getCommandSenderMapper() {
|
|
||||||
return this.commandSenderMapper;
|
return this.commandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,8 +84,7 @@ public class BungeeCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Owning plugin
|
* @return Owning plugin
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Plugin getOwningPlugin() {
|
||||||
public Plugin getOwningPlugin() {
|
|
||||||
return this.owningPlugin;
|
return this.owningPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.bungee;
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -40,12 +40,12 @@ final class BungeePluginRegistrationHandler<C> implements CommandRegistrationHan
|
||||||
BungeePluginRegistrationHandler() {
|
BungeePluginRegistrationHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize(@Nonnull final BungeeCommandManager<C> bungeeCommandManager) {
|
void initialize(@NonNull final BungeeCommandManager<C> bungeeCommandManager) {
|
||||||
this.bungeeCommandManager = bungeeCommandManager;
|
this.bungeeCommandManager = bungeeCommandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean registerCommand(@Nonnull final Command<?> command) {
|
public boolean registerCommand(@NonNull final Command<?> command) {
|
||||||
/* We only care about the root command argument */
|
/* We only care about the root command argument */
|
||||||
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||||
if (this.registeredCommands.containsKey(commandArgument)) {
|
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,11 @@ import cloud.commandframework.annotations.CommandMethod;
|
||||||
import cloud.commandframework.annotations.specifier.Range;
|
import cloud.commandframework.annotations.specifier.Range;
|
||||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.server.command.CommandSender;
|
import org.cloudburstmc.server.command.CommandSender;
|
||||||
import org.cloudburstmc.server.plugin.PluginBase;
|
import org.cloudburstmc.server.plugin.PluginBase;
|
||||||
import org.cloudburstmc.server.utils.TextFormat;
|
import org.cloudburstmc.server.utils.TextFormat;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -61,8 +61,8 @@ public final class CloudCloudburstTest extends PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@CommandMethod("test <num> [str]")
|
@CommandMethod("test <num> [str]")
|
||||||
private void testCommand(@Nonnull @Argument(value = "str", defaultValue = "potato") final String string,
|
private void testCommand(@NonNull @Argument(value = "str", defaultValue = "potato") final String string,
|
||||||
@Nonnull final CommandSender source,
|
@NonNull final CommandSender source,
|
||||||
@Argument("num") @Range(min = "10", max = "33") final int num) {
|
@Argument("num") @Range(min = "10", max = "33") final int num) {
|
||||||
source.sendMessage(TextFormat.RED + "You said: "
|
source.sendMessage(TextFormat.RED + "You said: "
|
||||||
+ TextFormat.GOLD + string
|
+ TextFormat.GOLD + string
|
||||||
|
|
|
||||||
|
|
@ -24,18 +24,18 @@
|
||||||
package cloud.commandframework.cloudburst;
|
package cloud.commandframework.cloudburst;
|
||||||
|
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
import cloud.commandframework.exceptions.InvalidSyntaxException;
|
|
||||||
import cloud.commandframework.exceptions.NoPermissionException;
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.exceptions.ArgumentParseException;
|
import cloud.commandframework.exceptions.ArgumentParseException;
|
||||||
import cloud.commandframework.exceptions.InvalidCommandSenderException;
|
import cloud.commandframework.exceptions.InvalidCommandSenderException;
|
||||||
|
import cloud.commandframework.exceptions.InvalidSyntaxException;
|
||||||
|
import cloud.commandframework.exceptions.NoPermissionException;
|
||||||
import cloud.commandframework.exceptions.NoSuchCommandException;
|
import cloud.commandframework.exceptions.NoSuchCommandException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.server.command.CommandSender;
|
import org.cloudburstmc.server.command.CommandSender;
|
||||||
import org.cloudburstmc.server.command.PluginCommand;
|
import org.cloudburstmc.server.command.PluginCommand;
|
||||||
import org.cloudburstmc.server.command.data.CommandData;
|
import org.cloudburstmc.server.command.data.CommandData;
|
||||||
import org.cloudburstmc.server.plugin.Plugin;
|
import org.cloudburstmc.server.plugin.Plugin;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
||||||
|
|
@ -50,11 +50,11 @@ final class CloudburstCommand<C> extends PluginCommand<Plugin> {
|
||||||
private final CloudburstCommandManager<C> manager;
|
private final CloudburstCommandManager<C> manager;
|
||||||
private final Command<C> cloudCommand;
|
private final Command<C> cloudCommand;
|
||||||
|
|
||||||
CloudburstCommand(@Nonnull final String label,
|
CloudburstCommand(@NonNull final String label,
|
||||||
@Nonnull final List<String> aliases,
|
@NonNull final List<@NonNull String> aliases,
|
||||||
@Nonnull final Command<C> cloudCommand,
|
@NonNull final Command<C> cloudCommand,
|
||||||
@Nonnull final CommandArgument<C, ?> command,
|
@NonNull final CommandArgument<C, ?> command,
|
||||||
@Nonnull final CloudburstCommandManager<C> manager) {
|
@NonNull final CloudburstCommandManager<C> manager) {
|
||||||
super(manager.getOwningPlugin(), CommandData.builder(label)
|
super(manager.getOwningPlugin(), CommandData.builder(label)
|
||||||
.addAliases(aliases.toArray(new String[0]))
|
.addAliases(aliases.toArray(new String[0]))
|
||||||
.addPermission(cloudCommand.getCommandPermission().toString())
|
.addPermission(cloudCommand.getCommandPermission().toString())
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@ import cloud.commandframework.CommandTree;
|
||||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.meta.CommandMeta;
|
import cloud.commandframework.meta.CommandMeta;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.server.command.CommandSender;
|
import org.cloudburstmc.server.command.CommandSender;
|
||||||
import org.cloudburstmc.server.plugin.Plugin;
|
import org.cloudburstmc.server.plugin.Plugin;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,11 +54,11 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
|
||||||
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||||
*/
|
*/
|
||||||
public CloudburstCommandManager(@Nonnull final Plugin owningPlugin,
|
public CloudburstCommandManager(@NonNull final Plugin owningPlugin,
|
||||||
@Nonnull final Function<CommandTree<C>,
|
@NonNull final Function<@NonNull CommandTree<C>,
|
||||||
CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
@NonNull final Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||||
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper) {
|
@NonNull final Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper) {
|
||||||
super(commandExecutionCoordinator, new CloudburstPluginRegistrationHandler<>());
|
super(commandExecutionCoordinator, new CloudburstPluginRegistrationHandler<>());
|
||||||
((CloudburstPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
((CloudburstPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||||
this.commandSenderMapper = commandSenderMapper;
|
this.commandSenderMapper = commandSenderMapper;
|
||||||
|
|
@ -67,19 +67,17 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasPermission(@Nonnull final C sender,
|
public final boolean hasPermission(@NonNull final C sender,
|
||||||
@Nonnull final String permission) {
|
@NonNull final String permission) {
|
||||||
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final CommandMeta createDefaultCommandMeta() {
|
public final @NonNull CommandMeta createDefaultCommandMeta() {
|
||||||
return SimpleCommandMeta.builder().build();
|
return SimpleCommandMeta.builder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
final @NonNull Function<@NonNull CommandSender, @NonNull C> getCommandSenderMapper() {
|
||||||
final Function<CommandSender, C> getCommandSenderMapper() {
|
|
||||||
return this.commandSenderMapper;
|
return this.commandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,8 +86,7 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Owning plugin
|
* @return Owning plugin
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public final @NonNull Plugin getOwningPlugin() {
|
||||||
public final Plugin getOwningPlugin() {
|
|
||||||
return this.owningPlugin;
|
return this.owningPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.cloudburst;
|
package cloud.commandframework.cloudburst;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.StaticArgument;
|
import cloud.commandframework.arguments.StaticArgument;
|
||||||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.server.Server;
|
import org.cloudburstmc.server.Server;
|
||||||
import org.cloudburstmc.server.plugin.Plugin;
|
import org.cloudburstmc.server.plugin.Plugin;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -43,12 +43,12 @@ class CloudburstPluginRegistrationHandler<C> implements CommandRegistrationHandl
|
||||||
CloudburstPluginRegistrationHandler() {
|
CloudburstPluginRegistrationHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize(@Nonnull final CloudburstCommandManager<C> cloudburstCommandManager) {
|
void initialize(@NonNull final CloudburstCommandManager<C> cloudburstCommandManager) {
|
||||||
this.cloudburstCommandManager = cloudburstCommandManager;
|
this.cloudburstCommandManager = cloudburstCommandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean registerCommand(@Nonnull final Command<?> command) {
|
public final boolean registerCommand(@NonNull final Command<?> command) {
|
||||||
/* We only care about the root command argument */
|
/* We only care about the root command argument */
|
||||||
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||||
if (this.registeredCommands.containsKey(commandArgument)) {
|
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework;
|
package cloud.commandframework;
|
||||||
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,7 +34,7 @@ import java.util.function.Function;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface AudienceProvider<C> extends Function<C, Audience> {
|
public interface AudienceProvider<C> extends Function<@NonNull C, @NonNull Audience> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a command sender to an {@link Audience}
|
* Convert a command sender to an {@link Audience}
|
||||||
|
|
@ -43,7 +43,6 @@ public interface AudienceProvider<C> extends Function<C, Audience> {
|
||||||
* @return Mapped audience
|
* @return Mapped audience
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@NonNull Audience apply(@NonNull C sender);
|
||||||
Audience apply(@Nonnull C sender);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import cloud.commandframework.arguments.StaticArgument;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
@ -73,9 +73,9 @@ public final class MinecraftHelp<C> {
|
||||||
* @param audienceProvider Provider that maps the command sender type to {@link Audience}
|
* @param audienceProvider Provider that maps the command sender type to {@link Audience}
|
||||||
* @param commandManager Command manager instance
|
* @param commandManager Command manager instance
|
||||||
*/
|
*/
|
||||||
public MinecraftHelp(@Nonnull final String commandPrefix,
|
public MinecraftHelp(@NonNull final String commandPrefix,
|
||||||
@Nonnull final AudienceProvider<C> audienceProvider,
|
@NonNull final AudienceProvider<C> audienceProvider,
|
||||||
@Nonnull final CommandManager<C> commandManager) {
|
@NonNull final CommandManager<C> commandManager) {
|
||||||
this.commandPrefix = commandPrefix;
|
this.commandPrefix = commandPrefix;
|
||||||
this.audienceProvider = audienceProvider;
|
this.audienceProvider = audienceProvider;
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
|
|
@ -109,8 +109,7 @@ public final class MinecraftHelp<C> {
|
||||||
*
|
*
|
||||||
* @return Command manager
|
* @return Command manager
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandManager<C> getCommandManager() {
|
||||||
public CommandManager<C> getCommandManager() {
|
|
||||||
return this.commandManager;
|
return this.commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,8 +118,7 @@ public final class MinecraftHelp<C> {
|
||||||
*
|
*
|
||||||
* @return Audience provider
|
* @return Audience provider
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull AudienceProvider<C> getAudienceProvider() {
|
||||||
public AudienceProvider<C> getAudienceProvider() {
|
|
||||||
return this.audienceProvider;
|
return this.audienceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,8 +128,7 @@ public final class MinecraftHelp<C> {
|
||||||
* @param sender Sender to map
|
* @param sender Sender to map
|
||||||
* @return Mapped audience
|
* @return Mapped audience
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Audience getAudience(@NonNull final C sender) {
|
||||||
public Audience getAudience(@Nonnull final C sender) {
|
|
||||||
return this.audienceProvider.apply(sender);
|
return this.audienceProvider.apply(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +138,8 @@ public final class MinecraftHelp<C> {
|
||||||
* @param key Message key
|
* @param key Message key
|
||||||
* @param message Message
|
* @param message Message
|
||||||
*/
|
*/
|
||||||
public void setMessage(@Nonnull final String key, @Nonnull final String message) {
|
public void setMessage(@NonNull final String key,
|
||||||
|
@NonNull final String message) {
|
||||||
this.messageMap.put(key, message);
|
this.messageMap.put(key, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,17 +149,17 @@ public final class MinecraftHelp<C> {
|
||||||
* @param query Command query (without leading '/')
|
* @param query Command query (without leading '/')
|
||||||
* @param recipient Recipient
|
* @param recipient Recipient
|
||||||
*/
|
*/
|
||||||
public void queryCommands(@Nonnull final String query,
|
public void queryCommands(@NonNull final String query,
|
||||||
@Nonnull final C recipient) {
|
@NonNull final C recipient) {
|
||||||
final Audience audience = this.getAudience(recipient);
|
final Audience audience = this.getAudience(recipient);
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_HELP_HEADER)));
|
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_HELP_HEADER)));
|
||||||
this.printTopic(recipient, query, this.commandManager.getCommandHelpHandler().queryHelp(query));
|
this.printTopic(recipient, query, this.commandManager.getCommandHelpHandler().queryHelp(query));
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_HELP_FOOTER)));
|
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_HELP_FOOTER)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printTopic(@Nonnull final C sender,
|
private void printTopic(@NonNull final C sender,
|
||||||
@Nonnull final String query,
|
@NonNull final String query,
|
||||||
@Nonnull final CommandHelpHandler.HelpTopic<C> helpTopic) {
|
final CommandHelpHandler.@NonNull HelpTopic<C> helpTopic) {
|
||||||
this.getAudience(sender).sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_QUERY),
|
this.getAudience(sender).sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_QUERY),
|
||||||
Template.of("query", query)));
|
Template.of("query", query)));
|
||||||
if (helpTopic instanceof CommandHelpHandler.IndexHelpTopic) {
|
if (helpTopic instanceof CommandHelpHandler.IndexHelpTopic) {
|
||||||
|
|
@ -175,7 +173,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printIndexHelpTopic(@Nonnull final C sender, @Nonnull final CommandHelpHandler.IndexHelpTopic<C> helpTopic) {
|
private void printIndexHelpTopic(@NonNull final C sender,
|
||||||
|
final CommandHelpHandler.@NonNull IndexHelpTopic<C> helpTopic) {
|
||||||
final Audience audience = this.getAudience(sender);
|
final Audience audience = this.getAudience(sender);
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_AVAILABLE_COMMANDS)));
|
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_AVAILABLE_COMMANDS)));
|
||||||
final Iterator<CommandHelpHandler.VerboseHelpEntry<C>> iterator = helpTopic.getEntries().iterator();
|
final Iterator<CommandHelpHandler.VerboseHelpEntry<C>> iterator = helpTopic.getEntries().iterator();
|
||||||
|
|
@ -202,7 +201,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printMultiHelpTopic(@Nonnull final C sender, @Nonnull final CommandHelpHandler.MultiHelpTopic<C> helpTopic) {
|
private void printMultiHelpTopic(@NonNull final C sender,
|
||||||
|
final CommandHelpHandler.@NonNull MultiHelpTopic<C> helpTopic) {
|
||||||
final Audience audience = this.getAudience(sender);
|
final Audience audience = this.getAudience(sender);
|
||||||
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_LONGEST_PATH),
|
audience.sendMessage(this.miniMessage.parse(this.messageMap.get(MESSAGE_QUERY_LONGEST_PATH),
|
||||||
Template.of("command", helpTopic.getLongestPath())));
|
Template.of("command", helpTopic.getLongestPath())));
|
||||||
|
|
@ -236,7 +236,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printVerboseHelpTopic(@Nonnull final C sender, @Nonnull final CommandHelpHandler.VerboseHelpTopic<C> helpTopic) {
|
private void printVerboseHelpTopic(@NonNull final C sender,
|
||||||
|
final CommandHelpHandler.@NonNull VerboseHelpTopic<C> helpTopic) {
|
||||||
final Audience audience = this.getAudience(sender);
|
final Audience audience = this.getAudience(sender);
|
||||||
final String command = this.commandManager.getCommandSyntaxFormatter()
|
final String command = this.commandManager.getCommandSyntaxFormatter()
|
||||||
.apply(helpTopic.getCommand().getArguments(), null);
|
.apply(helpTopic.getCommand().getArguments(), null);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue