✨ Add errorprone and fix warnings/errors
The compiler will also treat all warnings as errors from now on.
This commit is contained in:
parent
6ffee9d04f
commit
cfac2639ad
101 changed files with 309 additions and 146 deletions
|
|
@ -111,7 +111,7 @@ public abstract class CommandManager<C> {
|
|||
* registered to the command manager. This may be used to forward command registration
|
||||
* to the platform.
|
||||
*/
|
||||
public CommandManager(
|
||||
protected CommandManager(
|
||||
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull CommandRegistrationHandler commandRegistrationHandler
|
||||
) {
|
||||
|
|
@ -307,6 +307,7 @@ public abstract class CommandManager<C> {
|
|||
* @param captionRegistry Caption registry to use
|
||||
* @deprecated Use {@link #setCaptionRegistry(CaptionRegistry)} These methods are identical.
|
||||
*/
|
||||
@Deprecated
|
||||
public final void registerDefaultCaptions(final @NonNull CaptionRegistry<C> captionRegistry) {
|
||||
this.captionRegistry = captionRegistry;
|
||||
}
|
||||
|
|
@ -669,13 +670,13 @@ public abstract class CommandManager<C> {
|
|||
* @return Exception handler, or {@code null}
|
||||
* @see #registerCommandPreProcessor(CommandPreprocessor) Registering an exception handler
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <E extends Exception> @Nullable BiConsumer<@NonNull C, @NonNull E>
|
||||
getExceptionHandler(final @NonNull Class<E> clazz) {
|
||||
final BiConsumer<C, ? extends Exception> consumer = this.exceptionHandlers.get(clazz);
|
||||
if (consumer == null) {
|
||||
return null;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (BiConsumer<C, E>) consumer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -434,6 +434,7 @@ public final class CommandTree<C> {
|
|||
return getSuggestions(context, commandQueue, this.internalTree);
|
||||
}
|
||||
|
||||
@SuppressWarnings("MixedMutabilityReturnType")
|
||||
private @NonNull List<@NonNull String> getSuggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> commandQueue,
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public abstract class LockableCommandManager<C> extends CommandManager<C> {
|
|||
* @param commandRegistrationHandler Command registration handler. This will get called every time a new command is
|
||||
* registered to the command manager. This may be used to forward command registration
|
||||
*/
|
||||
public LockableCommandManager(
|
||||
protected LockableCommandManager(
|
||||
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull CommandRegistrationHandler commandRegistrationHandler
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public final @NonNull String apply(
|
||||
final @NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
|
||||
final CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
|
|||
* @param mapper Mapper that maps the sub-arguments to the output type
|
||||
* @param valueType The output type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ArgumentPair(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
|
|||
* @param mapper Mapper that maps the sub-arguments to the output type
|
||||
* @param valueType The output type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ArgumentTriplet(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
|
|
@ -170,7 +171,6 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
|||
in the context, so we can then extract that number and forward the request
|
||||
*/
|
||||
final int argument = commandContext.getOrDefault("__parsing_argument__", 1) - 1;
|
||||
//noinspection all
|
||||
return ((ArgumentParser<C, ?>) this.parsers[argument]).suggestions(commandContext, input);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public @NonNull ArgumentParseResult<@NonNull Object> parse(
|
||||
final @NonNull CommandContext<@NonNull C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
|
|
@ -207,11 +208,13 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
|||
);
|
||||
if (result.getFailure().isPresent()) {
|
||||
return ArgumentParseResult.failure(result.getFailure().get());
|
||||
} else {
|
||||
} else if (result.getParsedValue().isPresent()) {
|
||||
final CommandFlag erasedFlag = currentFlag;
|
||||
final Object value = result.getParsedValue().get();
|
||||
commandContext.flags().addValueFlag(erasedFlag, value);
|
||||
currentFlag = null;
|
||||
} else {
|
||||
throw new IllegalStateException("Neither result or value were present. Panicking.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -229,6 +232,7 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
|
|
@ -330,7 +334,6 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
|||
}
|
||||
}
|
||||
if (currentFlag != null && currentFlag.getCommandArgument() != null) {
|
||||
// noinspection all
|
||||
return (List<String>) ((BiFunction) currentFlag.getCommandArgument().getSuggestionsProvider())
|
||||
.apply(commandContext, input);
|
||||
}
|
||||
|
|
@ -346,6 +349,7 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
|||
*/
|
||||
public static final class FlagParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = -7725389394142868549L;
|
||||
private final String input;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -59,9 +59,13 @@ import java.util.function.Function;
|
|||
*
|
||||
* @param <C> Command sender type
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked", "rawtypes"})
|
||||
public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||
|
||||
@SuppressWarnings({"DoubleBraceInitialization"})
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = new HashMap<Class<?>, Class<?>>() {
|
||||
private static final long serialVersionUID = 958977651563195489L;
|
||||
|
||||
{
|
||||
put(char.class, Character.class);
|
||||
put(int.class, Integer.class);
|
||||
|
|
@ -93,31 +97,31 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
|
||||
/* Register standard types */
|
||||
this.registerParserSupplier(TypeToken.get(Byte.class), options ->
|
||||
new ByteArgument.ByteParser<C>(
|
||||
new ByteArgument.ByteParser<>(
|
||||
(byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
|
||||
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)
|
||||
));
|
||||
this.registerParserSupplier(TypeToken.get(Short.class), options ->
|
||||
new ShortArgument.ShortParser<C>(
|
||||
new ShortArgument.ShortParser<>(
|
||||
(short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
|
||||
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)
|
||||
));
|
||||
this.registerParserSupplier(TypeToken.get(Integer.class), options ->
|
||||
new IntegerArgument.IntegerParser<C>(
|
||||
new IntegerArgument.IntegerParser<>(
|
||||
(int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
|
||||
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)
|
||||
));
|
||||
this.registerParserSupplier(TypeToken.get(Float.class), options ->
|
||||
new FloatArgument.FloatParser<C>(
|
||||
new FloatArgument.FloatParser<>(
|
||||
(float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
|
||||
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)
|
||||
));
|
||||
this.registerParserSupplier(TypeToken.get(Double.class), options ->
|
||||
new DoubleArgument.DoubleParser<C>(
|
||||
new DoubleArgument.DoubleParser<>(
|
||||
(double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE),
|
||||
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)
|
||||
));
|
||||
this.registerParserSupplier(TypeToken.get(Character.class), options -> new CharArgument.CharacterParser<C>());
|
||||
this.registerParserSupplier(TypeToken.get(Character.class), options -> new CharArgument.CharacterParser<>());
|
||||
this.registerParserSupplier(TypeToken.get(String[].class), options -> new StringArrayArgument.StringArrayParser<>());
|
||||
/* Make this one less awful */
|
||||
this.registerParserSupplier(TypeToken.get(String.class), options -> {
|
||||
|
|
@ -125,7 +129,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
final StringArgument.StringMode stringMode = greedy
|
||||
? StringArgument.StringMode.GREEDY
|
||||
: StringArgument.StringMode.SINGLE;
|
||||
return new StringArgument.StringParser<C>(
|
||||
return new StringArgument.StringParser<>(
|
||||
stringMode,
|
||||
(context, s) -> Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))
|
||||
);
|
||||
|
|
@ -167,6 +171,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public @NonNull ParserParameters parseAnnotations(
|
||||
final @NonNull TypeToken<?> parsingType,
|
||||
final @NonNull Collection<@NonNull ? extends Annotation> annotations
|
||||
|
|
@ -186,6 +191,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(
|
||||
final @NonNull TypeToken<T> type,
|
||||
final @NonNull ParserParameters parserParameters
|
||||
|
|
@ -200,9 +206,9 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
if (producer == null) {
|
||||
/* Give enums special treatment */
|
||||
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
|
||||
@SuppressWarnings("all") final EnumArgument.EnumParser enumArgument
|
||||
= new EnumArgument.EnumParser((Class<Enum>) GenericTypeReflector.erase(actualType.getType()));
|
||||
// noinspection all
|
||||
@SuppressWarnings("rawtypes")
|
||||
final EnumArgument.EnumParser enumArgument
|
||||
= new EnumArgument.EnumParser(GenericTypeReflector.erase(actualType.getType()));
|
||||
return Optional.of(enumArgument);
|
||||
}
|
||||
return Optional.empty();
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import java.util.regex.Pattern;
|
|||
*
|
||||
* @param <C> Command sender type
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class RegexPreprocessor<C> implements BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>,
|
||||
@NonNull ArgumentParseResult<Boolean>> {
|
||||
|
||||
|
|
@ -114,6 +115,7 @@ public final class RegexPreprocessor<C> implements BiFunction<@NonNull CommandCo
|
|||
*/
|
||||
public static final class RegexValidationException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = 747826566058072233L;
|
||||
private final String pattern;
|
||||
private final String failedString;
|
||||
private final Caption failureCaption;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
|||
|
||||
private boolean liberal = false;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Boolean.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -231,6 +231,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
|||
*/
|
||||
public static final class BooleanParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = -2688852086944850025L;
|
||||
private final String input;
|
||||
private final boolean liberal;
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
|||
private byte min = Byte.MIN_VALUE;
|
||||
private byte max = Byte.MAX_VALUE;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Byte.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -258,6 +258,8 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
|||
*/
|
||||
public static final class ByteParseException extends NumberParseException {
|
||||
|
||||
private static final long serialVersionUID = -4724241304872989208L;
|
||||
|
||||
/**
|
||||
* Construct a new byte parse exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
|||
|
||||
public static final class Builder<C> extends CommandArgument.Builder<C, Character> {
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Character.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -156,6 +156,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
|||
*/
|
||||
public static final class CharParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = 6458851071584278854L;
|
||||
private final String input;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
|||
private double min = Double.NEGATIVE_INFINITY;
|
||||
private double max = Double.POSITIVE_INFINITY;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Double.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -245,6 +245,8 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
|||
|
||||
public static final class DoubleParseException extends NumberParseException {
|
||||
|
||||
private static final long serialVersionUID = 1764554911581976586L;
|
||||
|
||||
/**
|
||||
* Construct a new double parse exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
|||
|
||||
private final Class<E> enumClass;
|
||||
|
||||
protected Builder(final @NonNull String name, final @NonNull Class<E> enumClass) {
|
||||
private Builder(final @NonNull String name, final @NonNull Class<E> enumClass) {
|
||||
super(enumClass, name);
|
||||
this.enumClass = enumClass;
|
||||
}
|
||||
|
|
@ -202,6 +202,7 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
|||
|
||||
public static final class EnumParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = 3465389578951428862L;
|
||||
private final String input;
|
||||
private final Class<? extends Enum<?>> enumClass;
|
||||
|
||||
|
|
@ -228,7 +229,7 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
|||
this.enumClass = enumClass;
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static @NonNull String join(final @NonNull Class<? extends Enum> clazz) {
|
||||
final EnumSet<?> enumSet = EnumSet.allOf(clazz);
|
||||
return enumSet.stream()
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
|||
private float min = Float.NEGATIVE_INFINITY;
|
||||
private float max = Float.POSITIVE_INFINITY;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Float.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -245,6 +245,8 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
|||
|
||||
public static final class FloatParseException extends NumberParseException {
|
||||
|
||||
private static final long serialVersionUID = -1162983846751812292L;
|
||||
|
||||
/**
|
||||
* Construct a new float parse exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
|||
private int min = Integer.MIN_VALUE;
|
||||
private int max = Integer.MAX_VALUE;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Integer.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -198,6 +198,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
|||
* @param input Input
|
||||
* @return List of suggestions
|
||||
*/
|
||||
@SuppressWarnings("MixedMutabilityReturnType")
|
||||
public static @NonNull List<@NonNull String> getSuggestions(
|
||||
final long min,
|
||||
final long max,
|
||||
|
|
@ -302,6 +303,8 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
|||
|
||||
public static final class IntegerParseException extends NumberParseException {
|
||||
|
||||
private static final long serialVersionUID = -6933923056628373853L;
|
||||
|
||||
/**
|
||||
* Construct a new integer parse exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
|||
private long min = Long.MIN_VALUE;
|
||||
private long max = Long.MAX_VALUE;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Long.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -229,6 +229,8 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
|||
|
||||
public static final class LongParseException extends NumberParseException {
|
||||
|
||||
private static final long serialVersionUID = 4366856282301198232L;
|
||||
|
||||
/**
|
||||
* Construct a new long parse exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
|||
private short min = Short.MIN_VALUE;
|
||||
private short max = Short.MAX_VALUE;
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(Short.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -253,6 +253,8 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
|||
|
||||
public static final class ShortParseException extends NumberParseException {
|
||||
|
||||
private static final long serialVersionUID = -478674263339091032L;
|
||||
|
||||
/**
|
||||
* Construct a new short parse exception
|
||||
*
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
|||
private StringMode stringMode = StringMode.SINGLE;
|
||||
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(String.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -248,6 +248,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
|||
* @param suggestionsProvider Suggestions provider
|
||||
* @return Builder instance
|
||||
*/
|
||||
@Override
|
||||
public @NonNull Builder<C> withSuggestionsProvider(
|
||||
final @NonNull BiFunction<@NonNull CommandContext<C>,
|
||||
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
|
||||
|
|
@ -410,6 +411,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
|||
|
||||
public static final class StringParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = -8903115465005472945L;
|
||||
private final String input;
|
||||
private final StringMode stringMode;
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
|||
|
||||
public static final class Builder<C> extends CommandArgument.Builder<C, UUID> {
|
||||
|
||||
protected Builder(final @NonNull String name) {
|
||||
private Builder(final @NonNull String name) {
|
||||
super(UUID.class, name);
|
||||
}
|
||||
|
||||
|
|
@ -154,6 +154,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
|||
|
||||
public static final class UUIDParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = 6399602590976540023L;
|
||||
private final String input;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public final class CommandContext<C> {
|
|||
public <T> @NonNull Optional<T> getOptional(final @NonNull String key) {
|
||||
final Object value = this.internalStorage.get(key);
|
||||
if (value != null) {
|
||||
@SuppressWarnings("ALL") final T castedValue = (T) value;
|
||||
@SuppressWarnings("unchecked") final T castedValue = (T) value;
|
||||
return Optional.of(castedValue);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
|
|
@ -155,10 +155,11 @@ public final class CommandContext<C> {
|
|||
* @param <T> Value type
|
||||
* @return Value
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public <T> @NonNull Optional<T> getOptional(final @NonNull CommandArgument<C, T> argument) {
|
||||
final Object value = this.internalStorage.get(argument.getName());
|
||||
if (value != null) {
|
||||
@SuppressWarnings("ALL") final T castedValue = (T) value;
|
||||
@SuppressWarnings("unchecked") final T castedValue = (T) value;
|
||||
return Optional.of(castedValue);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
|
|
@ -183,7 +184,7 @@ public final class CommandContext<C> {
|
|||
* @return Argument
|
||||
* @throws NullPointerException If no such argument is stored
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
|
||||
public <T> @NonNull T get(final @NonNull String key) {
|
||||
final Object value = this.internalStorage.get(key);
|
||||
if (value == null) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.List;
|
|||
@SuppressWarnings("unused")
|
||||
public final class AmbiguousNodeException extends IllegalStateException {
|
||||
|
||||
private static final long serialVersionUID = -200207173805584709L;
|
||||
private final CommandArgument<?, ?> parentNode;
|
||||
private final CommandArgument<?, ?> ambiguousNode;
|
||||
private final List<CommandArgument<?, ?>> children;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
|
||||
public class ArgumentParseException extends CommandParseException {
|
||||
|
||||
private static final long serialVersionUID = -4385446899439587461L;
|
||||
private final Throwable cause;
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +54,8 @@ public class ArgumentParseException extends CommandParseException {
|
|||
*
|
||||
* @return Cause
|
||||
*/
|
||||
public @NonNull Throwable getCause() {
|
||||
@Override
|
||||
public synchronized @NonNull Throwable getCause() {
|
||||
return this.cause;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
@SuppressWarnings("unused")
|
||||
public class CommandParseException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = -2415981126382517435L;
|
||||
private final Object commandSender;
|
||||
private final List<CommandArgument<?, ?>> currentChain;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||
*/
|
||||
public final class InvalidCommandSenderException extends CommandParseException {
|
||||
|
||||
private static final long serialVersionUID = 7372142477529875598L;
|
||||
private final Class<?> requiredSender;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.List;
|
|||
@SuppressWarnings("unused")
|
||||
public class InvalidSyntaxException extends CommandParseException {
|
||||
|
||||
private static final long serialVersionUID = -4183356059293785202L;
|
||||
private final String correctSyntax;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
@SuppressWarnings("unused")
|
||||
public final class NoCommandInLeafException extends IllegalStateException {
|
||||
|
||||
private static final long serialVersionUID = 3373529875213310821L;
|
||||
private final CommandArgument<?, ?> commandArgument;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import java.util.List;
|
|||
@SuppressWarnings("unused")
|
||||
public class NoPermissionException extends CommandParseException {
|
||||
|
||||
private static final long serialVersionUID = 7103413337750692843L;
|
||||
private final CommandPermission missingPermission;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
@SuppressWarnings("unused")
|
||||
public final class NoSuchCommandException extends CommandParseException {
|
||||
|
||||
private static final long serialVersionUID = -7775865652882764771L;
|
||||
private final String suppliedCommand;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
*/
|
||||
public class NoInputProvidedException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = 3485754951593709559L;
|
||||
|
||||
/**
|
||||
* Construct a new NoInputProvidedException
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
|
||||
public abstract class NumberParseException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = 3018775374056029797L;
|
||||
private final String input;
|
||||
private final Number min;
|
||||
private final Number max;
|
||||
|
|
@ -43,7 +44,7 @@ public abstract class NumberParseException extends ParserException {
|
|||
* @param parserClass Parser class
|
||||
* @param context Command context
|
||||
*/
|
||||
public NumberParseException(
|
||||
protected NumberParseException(
|
||||
final @NonNull String input,
|
||||
final @NonNull Number min,
|
||||
final @NonNull Number max,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
|
||||
public class ParserException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = -4409795575435072170L;
|
||||
private final Class<?> argumentParser;
|
||||
private final CommandContext<?> context;
|
||||
private final Caption errorCaption;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import cloud.commandframework.types.tuples.Pair;
|
|||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
|
@ -52,7 +53,7 @@ public abstract class CommandExecutionCoordinator<C> {
|
|||
*
|
||||
* @param commandTree Command tree
|
||||
*/
|
||||
public CommandExecutionCoordinator(final @NonNull CommandTree<C> commandTree) {
|
||||
protected CommandExecutionCoordinator(final @NonNull CommandTree<C> commandTree) {
|
||||
this.commandTree = commandTree;
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +114,7 @@ public abstract class CommandExecutionCoordinator<C> {
|
|||
if (pair.getSecond() != null) {
|
||||
completableFuture.completeExceptionally(pair.getSecond());
|
||||
} else {
|
||||
final Command<C> command = pair.getFirst();
|
||||
final Command<C> command = Objects.requireNonNull(pair.getFirst());
|
||||
if (this.getCommandTree().getCommandManager().postprocessContext(commandContext, command) == State.ACCEPTED) {
|
||||
command.getCommandExecutionHandler().execute(commandContext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ package cloud.commandframework.permission;
|
|||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -84,7 +86,9 @@ public final class OrPermission implements CommandPermission {
|
|||
return false;
|
||||
}
|
||||
final OrPermission that = (OrPermission) o;
|
||||
return Objects.equals(getPermissions(), that.getPermissions());
|
||||
final List<CommandPermission> local = new ArrayList<>(this.getPermissions());
|
||||
final List<CommandPermission> foreign = new ArrayList<>(that.getPermissions());
|
||||
return local.equals(foreign);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ParserRegistryTest {
|
||||
|
||||
|
|
@ -61,6 +62,20 @@ public class ParserRegistryTest {
|
|||
public String max() {
|
||||
return Integer.toString(RANGE_MAX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof Range)) {
|
||||
return false;
|
||||
}
|
||||
final Range range = (Range) obj;
|
||||
return this.min().equals(range.min()) && this.max().equals(range.max());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.min(), this.max());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue