✨ 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
20
build.gradle
20
build.gradle
|
|
@ -15,6 +15,7 @@ plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
id 'com.github.johnrengelman.shadow' version '6.1.0'
|
id 'com.github.johnrengelman.shadow' version '6.1.0'
|
||||||
id 'de.marcphilipp.nexus-publish' version '0.4.0'
|
id 'de.marcphilipp.nexus-publish' version '0.4.0'
|
||||||
|
id 'net.ltgt.errorprone' version '1.3.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: 'scripts/dependencies.gradle'
|
apply from: 'scripts/dependencies.gradle'
|
||||||
|
|
@ -59,6 +60,7 @@ subprojects {
|
||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
apply plugin: 'signing'
|
apply plugin: 'signing'
|
||||||
apply plugin: 'de.marcphilipp.nexus-publish'
|
apply plugin: 'de.marcphilipp.nexus-publish'
|
||||||
|
apply plugin: 'net.ltgt.errorprone'
|
||||||
|
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
|
@ -69,6 +71,21 @@ subprojects {
|
||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.compilerArgs << "-Xlint:all" << "-Xlint:-processing" << "-Werror"
|
||||||
|
options.errorprone {
|
||||||
|
/* These are just annoying */
|
||||||
|
disable(
|
||||||
|
"JdkObsolete",
|
||||||
|
"FutureReturnValueIgnored",
|
||||||
|
"ImmutableEnumChecker",
|
||||||
|
"StringSplitter",
|
||||||
|
"EqualsGetClass",
|
||||||
|
"CatchAndPrintStackTrace"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
@ -115,6 +132,8 @@ subprojects {
|
||||||
compileOnly "org.checkerframework:checker-qual:${vers['checker-qual']}"
|
compileOnly "org.checkerframework:checker-qual:${vers['checker-qual']}"
|
||||||
api "io.leangen.geantyref:geantyref:${vers['geantyref']}"
|
api "io.leangen.geantyref:geantyref:${vers['geantyref']}"
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-engine:${vers['jupiter-engine']}"
|
testImplementation "org.junit.jupiter:junit-jupiter-engine:${vers['jupiter-engine']}"
|
||||||
|
errorprone "com.google.errorprone:error_prone_core:${vers['errorprone']}"
|
||||||
|
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
nexusPublishing {
|
nexusPublishing {
|
||||||
|
|
@ -180,4 +199,3 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ public final class AnnotationParser<C> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static <A extends Annotation> @Nullable A getMethodOrClassAnnotation(
|
static <A extends Annotation> @Nullable A getMethodOrClassAnnotation(
|
||||||
final @NonNull Method method,
|
final @NonNull Method method,
|
||||||
final @NonNull Class<A> clazz
|
final @NonNull Class<A> clazz
|
||||||
) {
|
) {
|
||||||
|
|
@ -118,7 +118,7 @@ public final class AnnotationParser<C> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static <A extends Annotation> boolean methodOrClassHasAnnotation(
|
static <A extends Annotation> boolean methodOrClassHasAnnotation(
|
||||||
final @NonNull Method method,
|
final @NonNull Method method,
|
||||||
final @NonNull Class<A> clazz
|
final @NonNull Class<A> clazz
|
||||||
) {
|
) {
|
||||||
|
|
@ -163,6 +163,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
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"deprecation", "unchecked", "rawtypes"})
|
||||||
public <T> @NonNull Collection<@NonNull Command<C>> parse(final @NonNull T instance) {
|
public <T> @NonNull Collection<@NonNull Command<C>> parse(final @NonNull 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<>();
|
||||||
|
|
@ -184,9 +185,7 @@ public final class AnnotationParser<C> {
|
||||||
}
|
}
|
||||||
final Collection<Command<C>> commands = this.construct(instance, commandMethodPairs);
|
final Collection<Command<C>> commands = this.construct(instance, commandMethodPairs);
|
||||||
for (final Command<C> command : commands) {
|
for (final Command<C> command : commands) {
|
||||||
@SuppressWarnings("ALL") final CommandManager commandManager = this.manager;
|
((CommandManager) this.manager).command(command);
|
||||||
//noinspection all
|
|
||||||
commandManager.command(command);
|
|
||||||
}
|
}
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
@ -203,14 +202,14 @@ public final class AnnotationParser<C> {
|
||||||
final LinkedHashMap<String, SyntaxFragment> tokens = this.syntaxParser.apply(commandMethod.value());
|
final LinkedHashMap<String, SyntaxFragment> tokens = this.syntaxParser.apply(commandMethod.value());
|
||||||
/* Determine command name */
|
/* Determine command name */
|
||||||
final String commandToken = commandMethod.value().split(" ")[0].split("\\|")[0];
|
final String commandToken = commandMethod.value().split(" ")[0].split("\\|")[0];
|
||||||
@SuppressWarnings("ALL") final CommandManager manager = this.manager;
|
@SuppressWarnings("rawtypes") final CommandManager manager = this.manager;
|
||||||
final SimpleCommandMeta.Builder metaBuilder = SimpleCommandMeta.builder()
|
final SimpleCommandMeta.Builder metaBuilder = SimpleCommandMeta.builder()
|
||||||
.with(this.metaFactory.apply(method));
|
.with(this.metaFactory.apply(method));
|
||||||
if (methodOrClassHasAnnotation(method, Confirmation.class)) {
|
if (methodOrClassHasAnnotation(method, Confirmation.class)) {
|
||||||
metaBuilder.with(CommandConfirmationManager.CONFIRMATION_REQUIRED_META, "true");
|
metaBuilder.with(CommandConfirmationManager.CONFIRMATION_REQUIRED_META, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("rawtypes")
|
||||||
Command.Builder builder = manager.commandBuilder(
|
Command.Builder builder = manager.commandBuilder(
|
||||||
commandToken,
|
commandToken,
|
||||||
tokens.get(commandToken).getMinor(),
|
tokens.get(commandToken).getMinor(),
|
||||||
|
|
@ -353,7 +352,7 @@ public final class AnnotationParser<C> {
|
||||||
}
|
}
|
||||||
final Argument argument = argumentPair.getArgument();
|
final Argument argument = argumentPair.getArgument();
|
||||||
/* Create the argument builder */
|
/* Create the argument builder */
|
||||||
@SuppressWarnings("ALL") final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
|
@SuppressWarnings("rawtypes") final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
|
||||||
parameter.getType(),
|
parameter.getType(),
|
||||||
argument.value()
|
argument.value()
|
||||||
);
|
);
|
||||||
|
|
@ -384,7 +383,7 @@ public final class AnnotationParser<C> {
|
||||||
final CommandArgument<C, ?> builtArgument = argumentBuilder.manager(this.manager).withParser(parser).build();
|
final CommandArgument<C, ?> builtArgument = argumentBuilder.manager(this.manager).withParser(parser).build();
|
||||||
/* Add preprocessors */
|
/* Add preprocessors */
|
||||||
for (final Annotation annotation : annotations) {
|
for (final Annotation annotation : annotations) {
|
||||||
@SuppressWarnings("ALL") final Function preprocessorMapper =
|
@SuppressWarnings("rawtypes") final Function preprocessorMapper =
|
||||||
this.preprocessorMappers.get(annotation.annotationType());
|
this.preprocessorMappers.get(annotation.annotationType());
|
||||||
if (preprocessorMapper != null) {
|
if (preprocessorMapper != null) {
|
||||||
final BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>,
|
final BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public @NonNull Collection<@NonNull CommandFlag<?>> apply(final @NonNull Method method) {
|
public @NonNull Collection<@NonNull CommandFlag<?>> apply(final @NonNull Method method) {
|
||||||
final Collection<CommandFlag<?>> flags = new LinkedList<>();
|
final Collection<CommandFlag<?>> flags = new LinkedList<>();
|
||||||
for (final Parameter parameter : method.getParameters()) {
|
for (final Parameter parameter : method.getParameters()) {
|
||||||
|
|
@ -77,15 +78,14 @@ final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNu
|
||||||
parameter.getType().getCanonicalName(), flag.value(), method.getName()
|
parameter.getType().getCanonicalName(), flag.value(), method.getName()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@SuppressWarnings("ALL") final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
|
final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
|
||||||
parameter.getType(),
|
parameter.getType(),
|
||||||
flag.value()
|
flag.value()
|
||||||
);
|
);
|
||||||
@SuppressWarnings("ALL") final CommandArgument argument = argumentBuilder.asRequired()
|
final CommandArgument argument = argumentBuilder.asRequired()
|
||||||
.manager(this.commandManager)
|
.manager(this.commandManager)
|
||||||
.withParser(parser)
|
.withParser(parser)
|
||||||
.build();
|
.build();
|
||||||
// noinspection unchecked
|
|
||||||
flags.add(builder.withArgument(argument).build());
|
flags.add(builder.withArgument(argument).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,16 +45,15 @@ class MetaFactory implements Function<@NonNull Method, @NonNull CommandMeta> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public @NonNull CommandMeta apply(final @NonNull Method method) {
|
public @NonNull CommandMeta apply(final @NonNull Method method) {
|
||||||
final ParserParameters parameters = ParserParameters.empty();
|
final ParserParameters parameters = ParserParameters.empty();
|
||||||
this.annotationParser.getAnnotationMappers().forEach(((annotationClass, mapper) -> {
|
this.annotationParser.getAnnotationMappers().forEach((annotationClass, mapper) -> {
|
||||||
final Annotation annotation = AnnotationParser.getMethodOrClassAnnotation(method, annotationClass);
|
final Annotation annotation = AnnotationParser.getMethodOrClassAnnotation(method, annotationClass);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
@SuppressWarnings("ALL") final Function function = (Function) mapper;
|
parameters.merge((ParserParameters) ((Function) mapper).apply(annotation));
|
||||||
//noinspection unchecked
|
|
||||||
parameters.merge((ParserParameters) function.apply(annotation));
|
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
return this.metaMapper.apply(parameters);
|
return this.metaMapper.apply(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ public abstract class CommandManager<C> {
|
||||||
* registered to the command manager. This may be used to forward command registration
|
* registered to the command manager. This may be used to forward command registration
|
||||||
* to the platform.
|
* to the platform.
|
||||||
*/
|
*/
|
||||||
public CommandManager(
|
protected CommandManager(
|
||||||
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
final @NonNull CommandRegistrationHandler commandRegistrationHandler
|
final @NonNull CommandRegistrationHandler commandRegistrationHandler
|
||||||
) {
|
) {
|
||||||
|
|
@ -307,6 +307,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param captionRegistry Caption registry to use
|
* @param captionRegistry Caption registry to use
|
||||||
* @deprecated Use {@link #setCaptionRegistry(CaptionRegistry)} These methods are identical.
|
* @deprecated Use {@link #setCaptionRegistry(CaptionRegistry)} These methods are identical.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final void registerDefaultCaptions(final @NonNull CaptionRegistry<C> captionRegistry) {
|
public final void registerDefaultCaptions(final @NonNull CaptionRegistry<C> captionRegistry) {
|
||||||
this.captionRegistry = captionRegistry;
|
this.captionRegistry = captionRegistry;
|
||||||
}
|
}
|
||||||
|
|
@ -669,13 +670,13 @@ public abstract class CommandManager<C> {
|
||||||
* @return Exception handler, or {@code null}
|
* @return Exception handler, or {@code null}
|
||||||
* @see #registerCommandPreProcessor(CommandPreprocessor) Registering an exception handler
|
* @see #registerCommandPreProcessor(CommandPreprocessor) Registering an exception handler
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final <E extends Exception> @Nullable BiConsumer<@NonNull C, @NonNull E>
|
public final <E extends Exception> @Nullable BiConsumer<@NonNull C, @NonNull E>
|
||||||
getExceptionHandler(final @NonNull Class<E> clazz) {
|
getExceptionHandler(final @NonNull Class<E> clazz) {
|
||||||
final BiConsumer<C, ? extends Exception> consumer = this.exceptionHandlers.get(clazz);
|
final BiConsumer<C, ? extends Exception> consumer = this.exceptionHandlers.get(clazz);
|
||||||
if (consumer == null) {
|
if (consumer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//noinspection unchecked
|
|
||||||
return (BiConsumer<C, E>) consumer;
|
return (BiConsumer<C, E>) consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -434,6 +434,7 @@ public final class CommandTree<C> {
|
||||||
return getSuggestions(context, commandQueue, this.internalTree);
|
return getSuggestions(context, commandQueue, this.internalTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("MixedMutabilityReturnType")
|
||||||
private @NonNull List<@NonNull String> getSuggestions(
|
private @NonNull List<@NonNull String> getSuggestions(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull Queue<@NonNull String> commandQueue,
|
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
|
* @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
|
* 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 Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
final @NonNull CommandRegistrationHandler commandRegistrationHandler
|
final @NonNull CommandRegistrationHandler commandRegistrationHandler
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final @NonNull String apply(
|
public final @NonNull String apply(
|
||||||
final @NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
|
final @NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
|
||||||
final CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node
|
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 mapper Mapper that maps the sub-arguments to the output type
|
||||||
* @param valueType The output type
|
* @param valueType The output type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected ArgumentPair(
|
protected ArgumentPair(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
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 mapper Mapper that maps the sub-arguments to the output type
|
||||||
* @param valueType The output type
|
* @param valueType The output type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected ArgumentTriplet(
|
protected ArgumentTriplet(
|
||||||
final boolean required,
|
final boolean required,
|
||||||
final @NonNull String name,
|
final @NonNull String name,
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,7 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public @NonNull List<@NonNull String> suggestions(
|
public @NonNull List<@NonNull String> suggestions(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull String input
|
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
|
in the context, so we can then extract that number and forward the request
|
||||||
*/
|
*/
|
||||||
final int argument = commandContext.getOrDefault("__parsing_argument__", 1) - 1;
|
final int argument = commandContext.getOrDefault("__parsing_argument__", 1) - 1;
|
||||||
//noinspection all
|
|
||||||
return ((ArgumentParser<C, ?>) this.parsers[argument]).suggestions(commandContext, input);
|
return ((ArgumentParser<C, ?>) this.parsers[argument]).suggestions(commandContext, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public @NonNull ArgumentParseResult<@NonNull Object> parse(
|
public @NonNull ArgumentParseResult<@NonNull Object> parse(
|
||||||
final @NonNull CommandContext<@NonNull C> commandContext,
|
final @NonNull CommandContext<@NonNull C> commandContext,
|
||||||
final @NonNull Queue<@NonNull String> inputQueue
|
final @NonNull Queue<@NonNull String> inputQueue
|
||||||
|
|
@ -207,11 +208,13 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
||||||
);
|
);
|
||||||
if (result.getFailure().isPresent()) {
|
if (result.getFailure().isPresent()) {
|
||||||
return ArgumentParseResult.failure(result.getFailure().get());
|
return ArgumentParseResult.failure(result.getFailure().get());
|
||||||
} else {
|
} else if (result.getParsedValue().isPresent()) {
|
||||||
final CommandFlag erasedFlag = currentFlag;
|
final CommandFlag erasedFlag = currentFlag;
|
||||||
final Object value = result.getParsedValue().get();
|
final Object value = result.getParsedValue().get();
|
||||||
commandContext.flags().addValueFlag(erasedFlag, value);
|
commandContext.flags().addValueFlag(erasedFlag, value);
|
||||||
currentFlag = null;
|
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
|
@Override
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public @NonNull List<@NonNull String> suggestions(
|
public @NonNull List<@NonNull String> suggestions(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
|
|
@ -330,7 +334,6 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentFlag != null && currentFlag.getCommandArgument() != null) {
|
if (currentFlag != null && currentFlag.getCommandArgument() != null) {
|
||||||
// noinspection all
|
|
||||||
return (List<String>) ((BiFunction) currentFlag.getCommandArgument().getSuggestionsProvider())
|
return (List<String>) ((BiFunction) currentFlag.getCommandArgument().getSuggestionsProvider())
|
||||||
.apply(commandContext, input);
|
.apply(commandContext, input);
|
||||||
}
|
}
|
||||||
|
|
@ -346,6 +349,7 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
|
||||||
*/
|
*/
|
||||||
public static final class FlagParseException extends ParserException {
|
public static final class FlagParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7725389394142868549L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,13 @@ import java.util.function.Function;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"unused", "unchecked", "rawtypes"})
|
||||||
public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
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 Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = new HashMap<Class<?>, Class<?>>() {
|
||||||
|
private static final long serialVersionUID = 958977651563195489L;
|
||||||
|
|
||||||
{
|
{
|
||||||
put(char.class, Character.class);
|
put(char.class, Character.class);
|
||||||
put(int.class, Integer.class);
|
put(int.class, Integer.class);
|
||||||
|
|
@ -93,31 +97,31 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
|
|
||||||
/* Register standard types */
|
/* Register standard types */
|
||||||
this.registerParserSupplier(TypeToken.get(Byte.class), options ->
|
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_MIN, Byte.MIN_VALUE),
|
||||||
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)
|
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)
|
||||||
));
|
));
|
||||||
this.registerParserSupplier(TypeToken.get(Short.class), options ->
|
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_MIN, Short.MIN_VALUE),
|
||||||
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)
|
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)
|
||||||
));
|
));
|
||||||
this.registerParserSupplier(TypeToken.get(Integer.class), options ->
|
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_MIN, Integer.MIN_VALUE),
|
||||||
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)
|
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)
|
||||||
));
|
));
|
||||||
this.registerParserSupplier(TypeToken.get(Float.class), options ->
|
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_MIN, Float.MIN_VALUE),
|
||||||
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)
|
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)
|
||||||
));
|
));
|
||||||
this.registerParserSupplier(TypeToken.get(Double.class), options ->
|
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_MIN, Double.MIN_VALUE),
|
||||||
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_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<>());
|
this.registerParserSupplier(TypeToken.get(String[].class), options -> new StringArrayArgument.StringArrayParser<>());
|
||||||
/* Make this one less awful */
|
/* Make this one less awful */
|
||||||
this.registerParserSupplier(TypeToken.get(String.class), options -> {
|
this.registerParserSupplier(TypeToken.get(String.class), options -> {
|
||||||
|
|
@ -125,7 +129,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
final StringArgument.StringMode stringMode = greedy
|
final StringArgument.StringMode stringMode = greedy
|
||||||
? StringArgument.StringMode.GREEDY
|
? StringArgument.StringMode.GREEDY
|
||||||
: StringArgument.StringMode.SINGLE;
|
: StringArgument.StringMode.SINGLE;
|
||||||
return new StringArgument.StringParser<C>(
|
return new StringArgument.StringParser<>(
|
||||||
stringMode,
|
stringMode,
|
||||||
(context, s) -> Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))
|
(context, s) -> Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))
|
||||||
);
|
);
|
||||||
|
|
@ -167,6 +171,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public @NonNull ParserParameters parseAnnotations(
|
public @NonNull ParserParameters parseAnnotations(
|
||||||
final @NonNull TypeToken<?> parsingType,
|
final @NonNull TypeToken<?> parsingType,
|
||||||
final @NonNull Collection<@NonNull ? extends Annotation> annotations
|
final @NonNull Collection<@NonNull ? extends Annotation> annotations
|
||||||
|
|
@ -186,6 +191,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(
|
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(
|
||||||
final @NonNull TypeToken<T> type,
|
final @NonNull TypeToken<T> type,
|
||||||
final @NonNull ParserParameters parserParameters
|
final @NonNull ParserParameters parserParameters
|
||||||
|
|
@ -200,9 +206,9 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
if (producer == null) {
|
if (producer == null) {
|
||||||
/* Give enums special treatment */
|
/* Give enums special treatment */
|
||||||
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
|
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
|
||||||
@SuppressWarnings("all") final EnumArgument.EnumParser enumArgument
|
@SuppressWarnings("rawtypes")
|
||||||
= new EnumArgument.EnumParser((Class<Enum>) GenericTypeReflector.erase(actualType.getType()));
|
final EnumArgument.EnumParser enumArgument
|
||||||
// noinspection all
|
= new EnumArgument.EnumParser(GenericTypeReflector.erase(actualType.getType()));
|
||||||
return Optional.of(enumArgument);
|
return Optional.of(enumArgument);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ import java.util.regex.Pattern;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public final class RegexPreprocessor<C> implements BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>,
|
public final class RegexPreprocessor<C> implements BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>,
|
||||||
@NonNull ArgumentParseResult<Boolean>> {
|
@NonNull ArgumentParseResult<Boolean>> {
|
||||||
|
|
||||||
|
|
@ -114,6 +115,7 @@ public final class RegexPreprocessor<C> implements BiFunction<@NonNull CommandCo
|
||||||
*/
|
*/
|
||||||
public static final class RegexValidationException extends IllegalArgumentException {
|
public static final class RegexValidationException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 747826566058072233L;
|
||||||
private final String pattern;
|
private final String pattern;
|
||||||
private final String failedString;
|
private final String failedString;
|
||||||
private final Caption failureCaption;
|
private final Caption failureCaption;
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
|
|
||||||
private boolean liberal = false;
|
private boolean liberal = false;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Boolean.class, 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 {
|
public static final class BooleanParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2688852086944850025L;
|
||||||
private final String input;
|
private final String input;
|
||||||
private final boolean liberal;
|
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 min = Byte.MIN_VALUE;
|
||||||
private byte max = Byte.MAX_VALUE;
|
private byte max = Byte.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Byte.class, 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 {
|
public static final class ByteParseException extends NumberParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4724241304872989208L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new byte parse exception
|
* 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> {
|
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);
|
super(Character.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,6 +156,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
*/
|
*/
|
||||||
public static final class CharParseException extends ParserException {
|
public static final class CharParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 6458851071584278854L;
|
||||||
private final String input;
|
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 min = Double.NEGATIVE_INFINITY;
|
||||||
private double max = Double.POSITIVE_INFINITY;
|
private double max = Double.POSITIVE_INFINITY;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Double.class, 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 {
|
public static final class DoubleParseException extends NumberParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1764554911581976586L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new double parse exception
|
* 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;
|
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);
|
super(enumClass, name);
|
||||||
this.enumClass = enumClass;
|
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 {
|
public static final class EnumParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3465389578951428862L;
|
||||||
private final String input;
|
private final String input;
|
||||||
private final Class<? extends Enum<?>> enumClass;
|
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;
|
this.enumClass = enumClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
private static @NonNull String join(final @NonNull Class<? extends Enum> clazz) {
|
private static @NonNull String join(final @NonNull Class<? extends Enum> clazz) {
|
||||||
final EnumSet<?> enumSet = EnumSet.allOf(clazz);
|
final EnumSet<?> enumSet = EnumSet.allOf(clazz);
|
||||||
return enumSet.stream()
|
return enumSet.stream()
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
private float min = Float.NEGATIVE_INFINITY;
|
private float min = Float.NEGATIVE_INFINITY;
|
||||||
private float max = Float.POSITIVE_INFINITY;
|
private float max = Float.POSITIVE_INFINITY;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Float.class, 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 {
|
public static final class FloatParseException extends NumberParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1162983846751812292L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new float parse exception
|
* 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 min = Integer.MIN_VALUE;
|
||||||
private int max = Integer.MAX_VALUE;
|
private int max = Integer.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Integer.class, name);
|
super(Integer.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,6 +198,7 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
* @param input Input
|
* @param input Input
|
||||||
* @return List of suggestions
|
* @return List of suggestions
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("MixedMutabilityReturnType")
|
||||||
public static @NonNull List<@NonNull String> getSuggestions(
|
public static @NonNull List<@NonNull String> getSuggestions(
|
||||||
final long min,
|
final long min,
|
||||||
final long max,
|
final long max,
|
||||||
|
|
@ -302,6 +303,8 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
|
|
||||||
public static final class IntegerParseException extends NumberParseException {
|
public static final class IntegerParseException extends NumberParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6933923056628373853L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new integer parse exception
|
* 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 min = Long.MIN_VALUE;
|
||||||
private long max = Long.MAX_VALUE;
|
private long max = Long.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Long.class, 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 {
|
public static final class LongParseException extends NumberParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 4366856282301198232L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new long parse exception
|
* 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 min = Short.MIN_VALUE;
|
||||||
private short max = Short.MAX_VALUE;
|
private short max = Short.MAX_VALUE;
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Short.class, 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 {
|
public static final class ShortParseException extends NumberParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -478674263339091032L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new short parse exception
|
* 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 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(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(String.class, name);
|
super(String.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,6 +248,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param suggestionsProvider Suggestions provider
|
* @param suggestionsProvider Suggestions provider
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public @NonNull Builder<C> withSuggestionsProvider(
|
public @NonNull Builder<C> withSuggestionsProvider(
|
||||||
final @NonNull BiFunction<@NonNull CommandContext<C>,
|
final @NonNull BiFunction<@NonNull CommandContext<C>,
|
||||||
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
|
@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 {
|
public static final class StringParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8903115465005472945L;
|
||||||
private final String input;
|
private final String input;
|
||||||
private final StringMode stringMode;
|
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> {
|
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);
|
super(UUID.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,6 +154,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
||||||
|
|
||||||
public static final class UUIDParseException extends ParserException {
|
public static final class UUIDParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 6399602590976540023L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ public final class CommandContext<C> {
|
||||||
public <T> @NonNull Optional<T> getOptional(final @NonNull String key) {
|
public <T> @NonNull Optional<T> getOptional(final @NonNull String key) {
|
||||||
final Object value = this.internalStorage.get(key);
|
final Object value = this.internalStorage.get(key);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
@SuppressWarnings("ALL") final T castedValue = (T) value;
|
@SuppressWarnings("unchecked") final T castedValue = (T) value;
|
||||||
return Optional.of(castedValue);
|
return Optional.of(castedValue);
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
@ -155,10 +155,11 @@ public final class CommandContext<C> {
|
||||||
* @param <T> Value type
|
* @param <T> Value type
|
||||||
* @return Value
|
* @return Value
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public <T> @NonNull Optional<T> getOptional(final @NonNull CommandArgument<C, T> argument) {
|
public <T> @NonNull Optional<T> getOptional(final @NonNull CommandArgument<C, T> argument) {
|
||||||
final Object value = this.internalStorage.get(argument.getName());
|
final Object value = this.internalStorage.get(argument.getName());
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
@SuppressWarnings("ALL") final T castedValue = (T) value;
|
@SuppressWarnings("unchecked") final T castedValue = (T) value;
|
||||||
return Optional.of(castedValue);
|
return Optional.of(castedValue);
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
@ -183,7 +184,7 @@ public final class CommandContext<C> {
|
||||||
* @return Argument
|
* @return Argument
|
||||||
* @throws NullPointerException If no such argument is stored
|
* @throws NullPointerException If no such argument is stored
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
|
||||||
public <T> @NonNull T get(final @NonNull String key) {
|
public <T> @NonNull T get(final @NonNull String key) {
|
||||||
final Object value = this.internalStorage.get(key);
|
final Object value = this.internalStorage.get(key);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class AmbiguousNodeException extends IllegalStateException {
|
public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -200207173805584709L;
|
||||||
private final CommandArgument<?, ?> parentNode;
|
private final CommandArgument<?, ?> parentNode;
|
||||||
private final CommandArgument<?, ?> ambiguousNode;
|
private final CommandArgument<?, ?> ambiguousNode;
|
||||||
private final List<CommandArgument<?, ?>> children;
|
private final List<CommandArgument<?, ?>> children;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class ArgumentParseException extends CommandParseException {
|
public class ArgumentParseException extends CommandParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4385446899439587461L;
|
||||||
private final Throwable cause;
|
private final Throwable cause;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,7 +54,8 @@ public class ArgumentParseException extends CommandParseException {
|
||||||
*
|
*
|
||||||
* @return Cause
|
* @return Cause
|
||||||
*/
|
*/
|
||||||
public @NonNull Throwable getCause() {
|
@Override
|
||||||
|
public synchronized @NonNull Throwable getCause() {
|
||||||
return this.cause;
|
return this.cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class CommandParseException extends IllegalArgumentException {
|
public class CommandParseException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2415981126382517435L;
|
||||||
private final Object commandSender;
|
private final Object commandSender;
|
||||||
private final List<CommandArgument<?, ?>> currentChain;
|
private final List<CommandArgument<?, ?>> currentChain;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public final class InvalidCommandSenderException extends CommandParseException {
|
public final class InvalidCommandSenderException extends CommandParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7372142477529875598L;
|
||||||
private final Class<?> requiredSender;
|
private final Class<?> requiredSender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class InvalidSyntaxException extends CommandParseException {
|
public class InvalidSyntaxException extends CommandParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4183356059293785202L;
|
||||||
private final String correctSyntax;
|
private final String correctSyntax;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class NoCommandInLeafException extends IllegalStateException {
|
public final class NoCommandInLeafException extends IllegalStateException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3373529875213310821L;
|
||||||
private final CommandArgument<?, ?> commandArgument;
|
private final CommandArgument<?, ?> commandArgument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NoPermissionException extends CommandParseException {
|
public class NoPermissionException extends CommandParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7103413337750692843L;
|
||||||
private final CommandPermission missingPermission;
|
private final CommandPermission missingPermission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class NoSuchCommandException extends CommandParseException {
|
public final class NoSuchCommandException extends CommandParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7775865652882764771L;
|
||||||
private final String suppliedCommand;
|
private final String suppliedCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
*/
|
*/
|
||||||
public class NoInputProvidedException extends ParserException {
|
public class NoInputProvidedException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3485754951593709559L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NoInputProvidedException
|
* Construct a new NoInputProvidedException
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public abstract class NumberParseException extends ParserException {
|
public abstract class NumberParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3018775374056029797L;
|
||||||
private final String input;
|
private final String input;
|
||||||
private final Number min;
|
private final Number min;
|
||||||
private final Number max;
|
private final Number max;
|
||||||
|
|
@ -43,7 +44,7 @@ public abstract class NumberParseException extends ParserException {
|
||||||
* @param parserClass Parser class
|
* @param parserClass Parser class
|
||||||
* @param context Command context
|
* @param context Command context
|
||||||
*/
|
*/
|
||||||
public NumberParseException(
|
protected NumberParseException(
|
||||||
final @NonNull String input,
|
final @NonNull String input,
|
||||||
final @NonNull Number min,
|
final @NonNull Number min,
|
||||||
final @NonNull Number max,
|
final @NonNull Number max,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class ParserException extends IllegalArgumentException {
|
public class ParserException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4409795575435072170L;
|
||||||
private final Class<?> argumentParser;
|
private final Class<?> argumentParser;
|
||||||
private final CommandContext<?> context;
|
private final CommandContext<?> context;
|
||||||
private final Caption errorCaption;
|
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.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -52,7 +53,7 @@ public abstract class CommandExecutionCoordinator<C> {
|
||||||
*
|
*
|
||||||
* @param commandTree Command tree
|
* @param commandTree Command tree
|
||||||
*/
|
*/
|
||||||
public CommandExecutionCoordinator(final @NonNull CommandTree<C> commandTree) {
|
protected CommandExecutionCoordinator(final @NonNull CommandTree<C> commandTree) {
|
||||||
this.commandTree = commandTree;
|
this.commandTree = commandTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +114,7 @@ public abstract class CommandExecutionCoordinator<C> {
|
||||||
if (pair.getSecond() != null) {
|
if (pair.getSecond() != null) {
|
||||||
completableFuture.completeExceptionally(pair.getSecond());
|
completableFuture.completeExceptionally(pair.getSecond());
|
||||||
} else {
|
} else {
|
||||||
final Command<C> command = pair.getFirst();
|
final Command<C> command = Objects.requireNonNull(pair.getFirst());
|
||||||
if (this.getCommandTree().getCommandManager().postprocessContext(commandContext, command) == State.ACCEPTED) {
|
if (this.getCommandTree().getCommandManager().postprocessContext(commandContext, command) == State.ACCEPTED) {
|
||||||
command.getCommandExecutionHandler().execute(commandContext);
|
command.getCommandExecutionHandler().execute(commandContext);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ package cloud.commandframework.permission;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
@ -84,7 +86,9 @@ public final class OrPermission implements CommandPermission {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final OrPermission that = (OrPermission) o;
|
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
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ParserRegistryTest {
|
public class ParserRegistryTest {
|
||||||
|
|
||||||
|
|
@ -61,6 +62,20 @@ public class ParserRegistryTest {
|
||||||
public String max() {
|
public String max() {
|
||||||
return Integer.toString(RANGE_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());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,19 +46,17 @@ public class JavacordCommand<C> implements MessageCreateListener {
|
||||||
|
|
||||||
private final JavacordCommandManager<C> manager;
|
private final JavacordCommandManager<C> manager;
|
||||||
private final CommandArgument<C, ?> command;
|
private final CommandArgument<C, ?> command;
|
||||||
private final cloud.commandframework.Command<C> cloudCommand;
|
|
||||||
|
|
||||||
JavacordCommand(
|
JavacordCommand(
|
||||||
final cloud.commandframework.@NonNull Command<C> cloudCommand,
|
|
||||||
final @NonNull CommandArgument<C, ?> command,
|
final @NonNull CommandArgument<C, ?> command,
|
||||||
final @NonNull JavacordCommandManager<C> manager
|
final @NonNull JavacordCommandManager<C> manager
|
||||||
) {
|
) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.cloudCommand = cloudCommand;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final void onMessageCreate(final @NonNull MessageCreateEvent event) {
|
public final void onMessageCreate(final @NonNull MessageCreateEvent event) {
|
||||||
MessageAuthor messageAuthor = event.getMessageAuthor();
|
MessageAuthor messageAuthor = event.getMessageAuthor();
|
||||||
|
|
||||||
|
|
@ -85,7 +83,6 @@ public class JavacordCommand<C> implements MessageCreateListener {
|
||||||
messageContent = messageContent.replaceFirst(commandPrefix, "");
|
messageContent = messageContent.replaceFirst(commandPrefix, "");
|
||||||
|
|
||||||
final String finalContent = messageContent;
|
final String finalContent = messageContent;
|
||||||
//noinspection unchecked
|
|
||||||
if (((StaticArgument<C>) command).getAliases()
|
if (((StaticArgument<C>) command).getAliases()
|
||||||
.stream()
|
.stream()
|
||||||
.map(String::toLowerCase)
|
.map(String::toLowerCase)
|
||||||
|
|
@ -94,7 +91,7 @@ public class JavacordCommand<C> implements MessageCreateListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.executeCommand(sender, finalContent)
|
manager.executeCommand(sender, finalContent)
|
||||||
.whenComplete(((commandResult, throwable) -> {
|
.whenComplete((commandResult, throwable) -> {
|
||||||
if (throwable == null) {
|
if (throwable == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +155,7 @@ public class JavacordCommand<C> implements MessageCreateListener {
|
||||||
|
|
||||||
commandSender.sendErrorMessage(throwable.getMessage());
|
commandSender.sendErrorMessage(throwable.getMessage());
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link Object}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link Object}
|
||||||
* @param commandPrefixMapper Function that maps the command sender type to the command prefix
|
* @param commandPrefixMapper Function that maps the command sender type to the command prefix
|
||||||
* @param commandPermissionMapper Function used to check if a command sender has the permission to execute a command
|
* @param commandPermissionMapper Function used to check if a command sender has the permission to execute a command
|
||||||
* @throws Exception If the construction of the manager fails
|
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public JavacordCommandManager(
|
public JavacordCommandManager(
|
||||||
final @NonNull DiscordApi discordApi,
|
final @NonNull DiscordApi discordApi,
|
||||||
final @NonNull Function<@NonNull CommandTree<C>,
|
final @NonNull Function<@NonNull CommandTree<C>,
|
||||||
|
|
@ -69,8 +69,7 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
|
||||||
final @NonNull Function<@NonNull C, @NonNull String> commandPrefixMapper,
|
final @NonNull Function<@NonNull C, @NonNull String> commandPrefixMapper,
|
||||||
final @Nullable BiFunction<@NonNull C,
|
final @Nullable BiFunction<@NonNull C,
|
||||||
@NonNull String, @NonNull Boolean> commandPermissionMapper
|
@NonNull String, @NonNull Boolean> commandPermissionMapper
|
||||||
)
|
) {
|
||||||
throws Exception {
|
|
||||||
super(commandExecutionCoordinator, new JavacordRegistrationHandler<>());
|
super(commandExecutionCoordinator, new JavacordRegistrationHandler<>());
|
||||||
((JavacordRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
((JavacordRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||||
this.discordApi = discordApi;
|
this.discordApi = discordApi;
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ final class JavacordRegistrationHandler<C> implements CommandRegistrationHandler
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked") final JavacordCommand<C> javacordCommand = new JavacordCommand<>(
|
@SuppressWarnings("unchecked") final JavacordCommand<C> javacordCommand = new JavacordCommand<>(
|
||||||
(Command<C>) command,
|
|
||||||
(CommandArgument<C, ?>) commandArgument,
|
(CommandArgument<C, ?>) commandArgument,
|
||||||
this.javacordCommandManager
|
this.javacordCommandManager
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -25,20 +25,20 @@ package cloud.commandframework.jda;
|
||||||
|
|
||||||
import cloud.commandframework.CommandTree;
|
import cloud.commandframework.CommandTree;
|
||||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
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;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command manager for use with JDA 4
|
* Command manager for use with JDA 4
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class JDA4CommandManager<C> extends JDACommandManager<C> {
|
public class JDA4CommandManager<C> extends JDACommandManager<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class JDACommandListener<C> extends ListenerAdapter {
|
public class JDACommandListener<C> extends ListenerAdapter {
|
||||||
|
|
||||||
private static final String MESSAGE_INVALID_SYNTAX = "Invalid Command Syntax. Correct command syntax is: ";
|
private static final String MESSAGE_INVALID_SYNTAX = "Invalid Command Syntax. Correct command syntax is: ";
|
||||||
|
|
@ -59,7 +60,6 @@ public class JDACommandListener<C> extends ListenerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public final void onMessageReceived(final @NonNull MessageReceivedEvent event) {
|
public final void onMessageReceived(final @NonNull MessageReceivedEvent event) {
|
||||||
final Message message = event.getMessage();
|
final Message message = event.getMessage();
|
||||||
final JDACommandSender jdaCommandSender = JDACommandSender.of(event);
|
|
||||||
final C sender = this.commandManager.getCommandSenderMapper().apply(event);
|
final C sender = this.commandManager.getCommandSenderMapper().apply(event);
|
||||||
|
|
||||||
if (this.commandManager.getBotId() == event.getAuthor().getIdLong()) {
|
if (this.commandManager.getBotId() == event.getAuthor().getIdLong()) {
|
||||||
|
|
@ -84,13 +84,11 @@ public class JDACommandListener<C> extends ListenerAdapter {
|
||||||
if (throwable instanceof InvalidSyntaxException) {
|
if (throwable instanceof InvalidSyntaxException) {
|
||||||
this.commandManager.handleException(sender,
|
this.commandManager.handleException(sender,
|
||||||
InvalidSyntaxException.class,
|
InvalidSyntaxException.class,
|
||||||
(InvalidSyntaxException) throwable, (c, e) -> {
|
(InvalidSyntaxException) throwable, (c, e) -> this.sendMessage(
|
||||||
this.sendMessage(
|
|
||||||
event,
|
event,
|
||||||
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
|
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
|
||||||
.getCorrectSyntax()
|
.getCorrectSyntax()
|
||||||
);
|
)
|
||||||
}
|
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||||
this.commandManager.handleException(sender,
|
this.commandManager.handleException(sender,
|
||||||
|
|
@ -112,13 +110,11 @@ public class JDACommandListener<C> extends ListenerAdapter {
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof ArgumentParseException) {
|
} else if (throwable instanceof ArgumentParseException) {
|
||||||
this.commandManager.handleException(sender, ArgumentParseException.class,
|
this.commandManager.handleException(sender, ArgumentParseException.class,
|
||||||
(ArgumentParseException) throwable, (c, e) -> {
|
(ArgumentParseException) throwable, (c, e) -> this.sendMessage(
|
||||||
this.sendMessage(
|
|
||||||
event,
|
event,
|
||||||
"Invalid Command Argument: " + throwable.getCause()
|
"Invalid Command Argument: " + throwable.getCause()
|
||||||
.getMessage()
|
.getMessage()
|
||||||
);
|
)
|
||||||
}
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.sendMessage(event, throwable.getMessage());
|
this.sendMessage(event, throwable.getMessage());
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
||||||
* with Bukkit specific objects
|
* with Bukkit specific objects
|
||||||
*
|
*
|
||||||
* @param <C>
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
final class JDACommandPreprocessor<C> implements CommandPreprocessor<C> {
|
final class JDACommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||||
|
|
||||||
private final JDACommandManager<C> mgr;
|
private final JDACommandManager<C> mgr;
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ public final class ChannelArgument<C> extends CommandArgument<C, MessageChannel>
|
||||||
|
|
||||||
private List<ParserMode> modes = new ArrayList<>();
|
private List<ParserMode> modes = new ArrayList<>();
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(MessageChannel.class, name);
|
super(MessageChannel.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,6 +228,7 @@ public final class ChannelArgument<C> extends CommandArgument<C, MessageChannel>
|
||||||
|
|
||||||
public static class ChannelParseException extends IllegalArgumentException {
|
public static class ChannelParseException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2724288304060572202L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -253,6 +254,8 @@ public final class ChannelArgument<C> extends CommandArgument<C, MessageChannel>
|
||||||
|
|
||||||
public static final class TooManyChannelsFoundParseException extends ChannelParseException {
|
public static final class TooManyChannelsFoundParseException extends ChannelParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -507783063742841507L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new channel parse exception
|
* Construct a new channel parse exception
|
||||||
*
|
*
|
||||||
|
|
@ -272,6 +275,8 @@ public final class ChannelArgument<C> extends CommandArgument<C, MessageChannel>
|
||||||
|
|
||||||
public static final class ChannelNotFoundException extends ChannelParseException {
|
public static final class ChannelNotFoundException extends ChannelParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8299458048947528494L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new channel parse exception
|
* Construct a new channel parse exception
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
private Set<ParserMode> modes = new HashSet<>();
|
private Set<ParserMode> modes = new HashSet<>();
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(User.class, name);
|
super(User.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,6 +244,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
public static class UserParseException extends IllegalArgumentException {
|
public static class UserParseException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6728909884195850077L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -269,6 +270,8 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
public static final class TooManyUsersFoundParseException extends UserParseException {
|
public static final class TooManyUsersFoundParseException extends UserParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7222089412615886672L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new user parse exception
|
* Construct a new user parse exception
|
||||||
*
|
*
|
||||||
|
|
@ -288,6 +291,8 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
public static final class UserNotFoundParseException extends UserParseException {
|
public static final class UserNotFoundParseException extends UserParseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3689949065073643826L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new user parse exception
|
* Construct a new user parse exception
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,8 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
|
||||||
|
|
||||||
public static final class UserParseException extends ParserException {
|
public static final class UserParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1758590697299611905L;
|
||||||
|
|
||||||
private UserParseException(
|
private UserParseException(
|
||||||
final @NonNull CommandContext<?> context,
|
final @NonNull CommandContext<?> context,
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ import java.util.function.Supplier;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <S> Brigadier sender type
|
* @param <S> Brigadier sender type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public final class CloudBrigadierManager<C, S> {
|
public final class CloudBrigadierManager<C, S> {
|
||||||
|
|
||||||
private final Map<Class<?>, Pair<Function<? extends ArgumentParser<C, ?>, ? extends ArgumentType<?>>, Boolean>> mappers;
|
private final Map<Class<?>, Pair<Function<? extends ArgumentParser<C, ?>, ? extends ArgumentType<?>>, Boolean>> mappers;
|
||||||
|
|
@ -232,7 +233,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
||||||
final Pair pair = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
|
final Pair pair = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
|
||||||
if (pair == null || pair.getFirst() == null) {
|
if (pair == null || pair.getFirst() == null) {
|
||||||
return this.createDefaultMapper(valueType, commandArgument);
|
return this.createDefaultMapper(valueType);
|
||||||
}
|
}
|
||||||
return Pair.of(
|
return Pair.of(
|
||||||
(ArgumentType<?>) ((Function) pair.getFirst()).apply(commandArgument),
|
(ArgumentType<?>) ((Function) pair.getFirst()).apply(commandArgument),
|
||||||
|
|
@ -241,8 +242,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, K extends ArgumentParser<C, T>> @NonNull Pair<@NonNull ArgumentType<?>, @NonNull Boolean> createDefaultMapper(
|
private <T, K extends ArgumentParser<C, T>> @NonNull Pair<@NonNull ArgumentType<?>, @NonNull Boolean> createDefaultMapper(
|
||||||
final @NonNull TypeToken<?> clazz,
|
final @NonNull TypeToken<?> clazz
|
||||||
final @NonNull ArgumentParser<C, T> argument
|
|
||||||
) {
|
) {
|
||||||
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers
|
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers
|
||||||
.get(GenericTypeReflector.erase(clazz.getType()));
|
.get(GenericTypeReflector.erase(clazz.getType()));
|
||||||
|
|
@ -278,7 +278,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
) {
|
) {
|
||||||
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(), builder);
|
||||||
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder
|
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder
|
||||||
.<S>literal(label)
|
.<S>literal(label)
|
||||||
.requires(sender -> permissionChecker.test(sender, (CommandPermission) node.getNodeMeta()
|
.requires(sender -> permissionChecker.test(sender, (CommandPermission) node.getNodeMeta()
|
||||||
|
|
@ -375,7 +375,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
));
|
));
|
||||||
argumentBuilders[i] = fragmentBuilder;
|
argumentBuilders[i] = fragmentBuilder;
|
||||||
|
|
||||||
if (forceExecutor || (i == parsers.length - 1) && (root.isLeaf() || !root.getValue().isRequired())) {
|
if (forceExecutor || ((i == parsers.length - 1) && (root.isLeaf() || !root.getValue().isRequired()))) {
|
||||||
fragmentBuilder.executes(executor);
|
fragmentBuilder.executes(executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,7 +410,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
final SuggestionProvider<S> provider = pair.getSecond()
|
final SuggestionProvider<S> provider = pair.getSecond()
|
||||||
? null
|
? null
|
||||||
: (context, builder) -> this.buildSuggestions(root.getValue(),
|
: (context, builder) -> this.buildSuggestions(root.getValue(),
|
||||||
context, builder
|
builder
|
||||||
);
|
);
|
||||||
argumentBuilder = RequiredArgumentBuilder
|
argumentBuilder = RequiredArgumentBuilder
|
||||||
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getFirst())
|
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getFirst())
|
||||||
|
|
@ -438,7 +438,6 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
|
|
||||||
private @NonNull CompletableFuture<Suggestions> buildSuggestions(
|
private @NonNull CompletableFuture<Suggestions> buildSuggestions(
|
||||||
final @NonNull CommandArgument<C, ?> argument,
|
final @NonNull CommandArgument<C, ?> argument,
|
||||||
final com.mojang.brigadier.context.@NonNull CommandContext<S> s,
|
|
||||||
final @NonNull SuggestionsBuilder builder
|
final @NonNull SuggestionsBuilder builder
|
||||||
) {
|
) {
|
||||||
final CommandContext<C> commandContext = this.dummyContextProvider.get();
|
final CommandContext<C> commandContext = this.dummyContextProvider.get();
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,6 @@ dependencies {
|
||||||
api project(':cloud-tasks')
|
api project(':cloud-tasks')
|
||||||
compileOnly "org.bukkit:bukkit:${vers['bukkit']}"
|
compileOnly "org.bukkit:bukkit:${vers['bukkit']}"
|
||||||
compileOnly "me.lucko:commodore:${vers['commodore']}"
|
compileOnly "me.lucko:commodore:${vers['commodore']}"
|
||||||
|
compileOnly "org.jetbrains:annotations:${vers['jb-annotations']}"
|
||||||
|
compileOnly "com.google.guava:guava:${vers['guava']}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ import java.util.logging.Level;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public final class BukkitBrigadierMapper<C> {
|
public final class BukkitBrigadierMapper<C> {
|
||||||
|
|
||||||
private static final int UUID_ARGUMENT_VERSION = 16;
|
private static final int UUID_ARGUMENT_VERSION = 16;
|
||||||
|
|
@ -115,6 +116,7 @@ public final class BukkitBrigadierMapper<C> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnnecessaryLambda")
|
||||||
private Supplier<ArgumentType<?>> getArgumentVec3() {
|
private Supplier<ArgumentType<?>> getArgumentVec3() {
|
||||||
return () -> {
|
return () -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -152,7 +154,7 @@ public final class BukkitBrigadierMapper<C> {
|
||||||
try {
|
try {
|
||||||
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, () -> {
|
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, () -> {
|
||||||
try {
|
try {
|
||||||
return (ArgumentType<?>) constructor.newInstance();
|
return constructor.newInstance();
|
||||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
sender,
|
sender,
|
||||||
builder.toString()
|
builder.toString()
|
||||||
)
|
)
|
||||||
.whenComplete(((commandResult, throwable) -> {
|
.whenComplete((commandResult, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
if (throwable instanceof CompletionException) {
|
if (throwable instanceof CompletionException) {
|
||||||
throwable = throwable.getCause();
|
throwable = throwable.getCause();
|
||||||
|
|
@ -138,7 +138,7 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
private final Function<CommandSender, C> commandSenderMapper;
|
private final Function<CommandSender, C> commandSenderMapper;
|
||||||
private final Function<C, CommandSender> backwardsCommandSenderMapper;
|
private final Function<C, CommandSender> backwardsCommandSenderMapper;
|
||||||
|
|
||||||
private final BukkitSynchronizer bukkitSynchronizer;
|
|
||||||
private final TaskFactory taskFactory;
|
private final TaskFactory taskFactory;
|
||||||
|
|
||||||
private boolean splitAliases = false;
|
private boolean splitAliases = false;
|
||||||
|
|
@ -109,6 +108,7 @@ 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
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public BukkitCommandManager(
|
public BukkitCommandManager(
|
||||||
final @NonNull Plugin owningPlugin,
|
final @NonNull Plugin owningPlugin,
|
||||||
final @NonNull Function<@NonNull CommandTree<C>,
|
final @NonNull Function<@NonNull CommandTree<C>,
|
||||||
|
|
@ -123,8 +123,8 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
this.commandSenderMapper = commandSenderMapper;
|
this.commandSenderMapper = commandSenderMapper;
|
||||||
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
|
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
|
||||||
|
|
||||||
this.bukkitSynchronizer = new BukkitSynchronizer(owningPlugin);
|
final BukkitSynchronizer bukkitSynchronizer = new BukkitSynchronizer(owningPlugin);
|
||||||
this.taskFactory = new TaskFactory(this.bukkitSynchronizer);
|
this.taskFactory = new TaskFactory(bukkitSynchronizer);
|
||||||
|
|
||||||
/* Try to determine the Minecraft version */
|
/* Try to determine the Minecraft version */
|
||||||
int version = -1;
|
int version = -1;
|
||||||
|
|
@ -148,6 +148,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
Class.forName("com.destroystokyo.paper.PaperConfig");
|
Class.forName("com.destroystokyo.paper.PaperConfig");
|
||||||
paper = true;
|
paper = true;
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
|
// This is fine
|
||||||
}
|
}
|
||||||
this.paper = paper;
|
this.paper = paper;
|
||||||
|
|
||||||
|
|
@ -183,7 +184,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
this.owningPlugin
|
this.owningPlugin
|
||||||
);
|
);
|
||||||
|
|
||||||
this.registerDefaultCaptions(new BukkitCaptionRegistryFactory<C>().create());
|
this.setCaptionRegistry(new BukkitCaptionRegistryFactory<C>().create());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -363,6 +364,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
||||||
|
|
||||||
public static final class BrigadierFailureException extends IllegalStateException {
|
public static final class BrigadierFailureException extends IllegalStateException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7816660840063155703L;
|
||||||
private final BrigadierFailureReason reason;
|
private final BrigadierFailureReason reason;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
||||||
* with Bukkit specific objects
|
* with Bukkit specific objects
|
||||||
*
|
*
|
||||||
* @param <C>
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
*/
|
||||||
public abstract class BukkitCommandSender {
|
public abstract class BukkitCommandSender {
|
||||||
|
|
||||||
|
|
@ -40,7 +39,7 @@ public abstract class BukkitCommandSender {
|
||||||
*
|
*
|
||||||
* @param internalSender Bukkit command sender
|
* @param internalSender Bukkit command sender
|
||||||
*/
|
*/
|
||||||
public BukkitCommandSender(final org.bukkit.command.@NonNull CommandSender internalSender) {
|
protected BukkitCommandSender(final org.bukkit.command.@NonNull CommandSender internalSender) {
|
||||||
this.internalSender = internalSender;
|
this.internalSender = internalSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
||||||
this.commandMap = (CommandMap) getCommandMap.invoke(Bukkit.getServer());
|
this.commandMap = (CommandMap) getCommandMap.invoke(Bukkit.getServer());
|
||||||
final Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
final Field knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||||
knownCommands.setAccessible(true);
|
knownCommands.setAccessible(true);
|
||||||
@SuppressWarnings("ALL") final Map<String, org.bukkit.command.Command> bukkitCommands =
|
@SuppressWarnings("unchecked") final Map<String, org.bukkit.command.Command> bukkitCommands =
|
||||||
(Map<String, org.bukkit.command.Command>) knownCommands.get(commandMap);
|
(Map<String, org.bukkit.command.Command>) knownCommands.get(commandMap);
|
||||||
this.bukkitCommands = bukkitCommands;
|
this.bukkitCommands = bukkitCommands;
|
||||||
this.bukkitCommandManager = bukkitCommandManager;
|
this.bukkitCommandManager = bukkitCommandManager;
|
||||||
|
|
@ -83,7 +83,7 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") final BukkitCommand<C> bukkitCommand = new BukkitCommand<>(
|
@SuppressWarnings("unchecked") final BukkitCommand<C> bukkitCommand = new BukkitCommand<>(
|
||||||
label,
|
label,
|
||||||
(this.bukkitCommandManager.getSplitAliases() ? Collections.<String>emptyList() : aliases),
|
(this.bukkitCommandManager.getSplitAliases() ? Collections.emptyList() : aliases),
|
||||||
(Command<C>) command,
|
(Command<C>) command,
|
||||||
(CommandArgument<C, ?>) commandArgument,
|
(CommandArgument<C, ?>) commandArgument,
|
||||||
this.bukkitCommandManager
|
this.bukkitCommandManager
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
||||||
|
|
||||||
private final BukkitCommandManager<C> commandManager;
|
private final BukkitCommandManager<C> commandManager;
|
||||||
|
|
@ -77,7 +77,7 @@ class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
||||||
) {
|
) {
|
||||||
final com.mojang.brigadier.Command<?> cmd = o -> 1;
|
final com.mojang.brigadier.Command<?> cmd = o -> 1;
|
||||||
final LiteralCommandNode<?> literalCommandNode = this.brigadierManager
|
final LiteralCommandNode<?> literalCommandNode = this.brigadierManager
|
||||||
.<Object>createLiteralCommandNode(label, command, (o, p) -> {
|
.createLiteralCommandNode(label, command, (o, p) -> {
|
||||||
final CommandSender sender = this.commodore.getBukkitSender(o);
|
final CommandSender sender = this.commodore.getBukkitSender(o);
|
||||||
return this.commandManager.hasPermission(
|
return this.commandManager.hasPermission(
|
||||||
this.commandManager.getCommandSenderMapper().apply(sender),
|
this.commandManager.getCommandSenderMapper().apply(sender),
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public abstract class EntitySelector {
|
||||||
* @param selector The input string used to create this selector
|
* @param selector The input string used to create this selector
|
||||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||||
*/
|
*/
|
||||||
public EntitySelector(
|
protected EntitySelector(
|
||||||
final @NonNull String selector,
|
final @NonNull String selector,
|
||||||
final @NonNull List<@NonNull Entity> entities
|
final @NonNull List<@NonNull Entity> entities
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ public class EnchantmentArgument<C> extends CommandArgument<C, Enchantment> {
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, Enchantment> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Enchantment> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Enchantment.class, name);
|
super(Enchantment.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,6 +127,7 @@ public class EnchantmentArgument<C> extends CommandArgument<C, Enchantment> {
|
||||||
public static final class EnchantmentParser<C> implements ArgumentParser<C, Enchantment> {
|
public static final class EnchantmentParser<C> implements ArgumentParser<C, Enchantment> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public @NonNull ArgumentParseResult<Enchantment> parse(
|
public @NonNull ArgumentParseResult<Enchantment> parse(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull Queue<@NonNull String> inputQueue
|
final @NonNull Queue<@NonNull String> inputQueue
|
||||||
|
|
@ -142,7 +143,6 @@ public class EnchantmentArgument<C> extends CommandArgument<C, Enchantment> {
|
||||||
final NamespacedKey key;
|
final NamespacedKey key;
|
||||||
if (input.contains(":")) {
|
if (input.contains(":")) {
|
||||||
final String[] splitInput = input.split(":");
|
final String[] splitInput = input.split(":");
|
||||||
//noinspection deprecation
|
|
||||||
key = new NamespacedKey(splitInput[0], splitInput[1]);
|
key = new NamespacedKey(splitInput[0], splitInput[1]);
|
||||||
} else {
|
} else {
|
||||||
key = NamespacedKey.minecraft(input);
|
key = NamespacedKey.minecraft(input);
|
||||||
|
|
@ -177,6 +177,7 @@ public class EnchantmentArgument<C> extends CommandArgument<C, Enchantment> {
|
||||||
|
|
||||||
public static final class EnchantmentParseException extends ParserException {
|
public static final class EnchantmentParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1415174766296065151L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, Material> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Material> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Material.class, name);
|
super(Material.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,6 +164,7 @@ public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
||||||
|
|
||||||
public static final class MaterialParseException extends ParserException {
|
public static final class MaterialParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1615554107385965610L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, OfflinePlayer> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, OfflinePlayer> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(OfflinePlayer.class, name);
|
super(OfflinePlayer.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,6 +136,7 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
||||||
public static final class OfflinePlayerParser<C> implements ArgumentParser<C, OfflinePlayer> {
|
public static final class OfflinePlayerParser<C> implements ArgumentParser<C, OfflinePlayer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public @NonNull ArgumentParseResult<OfflinePlayer> parse(
|
public @NonNull ArgumentParseResult<OfflinePlayer> parse(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull Queue<String> inputQueue
|
final @NonNull Queue<String> inputQueue
|
||||||
|
|
@ -149,10 +150,9 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
||||||
}
|
}
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
|
|
||||||
//noinspection deprecation
|
final OfflinePlayer player = Bukkit.getOfflinePlayer(input);
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(input);
|
|
||||||
|
|
||||||
if (player == null || (!player.hasPlayedBefore() && !player.isOnline())) {
|
if (!player.hasPlayedBefore() && !player.isOnline()) {
|
||||||
return ArgumentParseResult.failure(new OfflinePlayerParseException(input, commandContext));
|
return ArgumentParseResult.failure(new OfflinePlayerParseException(input, commandContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,6 +181,7 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
||||||
*/
|
*/
|
||||||
public static final class OfflinePlayerParseException extends ParserException {
|
public static final class OfflinePlayerParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7632293268451349508L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, Player> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Player> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(Player.class, name);
|
super(Player.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,6 +130,7 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
||||||
public static final class PlayerParser<C> implements ArgumentParser<C, Player> {
|
public static final class PlayerParser<C> implements ArgumentParser<C, Player> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public @NonNull ArgumentParseResult<Player> parse(
|
public @NonNull ArgumentParseResult<Player> parse(
|
||||||
final @NonNull CommandContext<C> commandContext,
|
final @NonNull CommandContext<C> commandContext,
|
||||||
final @NonNull Queue<@NonNull String> inputQueue
|
final @NonNull Queue<@NonNull String> inputQueue
|
||||||
|
|
@ -143,7 +144,6 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
||||||
}
|
}
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
|
|
||||||
//noinspection deprecation
|
|
||||||
Player player = Bukkit.getPlayer(input);
|
Player player = Bukkit.getPlayer(input);
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
|
@ -175,6 +175,7 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
||||||
*/
|
*/
|
||||||
public static final class PlayerParseException extends ParserException {
|
public static final class PlayerParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 927476591631527552L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ public class WorldArgument<C> extends CommandArgument<C, World> {
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, World> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, World> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(World.class, name);
|
super(World.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,6 +154,7 @@ public class WorldArgument<C> extends CommandArgument<C, World> {
|
||||||
|
|
||||||
public static final class WorldParseException extends ParserException {
|
public static final class WorldParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 561648144491587450L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -289,6 +289,8 @@ public final class LocationArgument<C> extends CommandArgument<C, Location> {
|
||||||
|
|
||||||
private static class LocationParseException extends ParserException {
|
private static class LocationParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3261835227265878218L;
|
||||||
|
|
||||||
protected LocationParseException(
|
protected LocationParseException(
|
||||||
final @NonNull CommandContext<?> context,
|
final @NonNull CommandContext<?> context,
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, MultipleEntitySelector> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, MultipleEntitySelector> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(MultipleEntitySelector.class, name);
|
super(MultipleEntitySelector.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, MultiplePlayerSelector> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, MultiplePlayerSelector> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(MultiplePlayerSelector.class, name);
|
super(MultiplePlayerSelector.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
*/
|
*/
|
||||||
public final class SelectorParseException extends ParserException {
|
public final class SelectorParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1900826717897819065L;
|
||||||
private final String input;
|
private final String input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, SingleEntitySelector> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, SingleEntitySelector> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(SingleEntitySelector.class, name);
|
super(SingleEntitySelector.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
||||||
|
|
||||||
public static final class Builder<C> extends CommandArgument.Builder<C, SinglePlayerSelector> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, SinglePlayerSelector> {
|
||||||
|
|
||||||
protected Builder(final @NonNull String name) {
|
private Builder(final @NonNull String name) {
|
||||||
super(SinglePlayerSelector.class, name);
|
super(SinglePlayerSelector.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||||
|
|
||||||
private final BungeeCommandManager<C> manager;
|
private final BungeeCommandManager<C> manager;
|
||||||
private final CommandArgument<C, ?> command;
|
private final CommandArgument<C, ?> command;
|
||||||
private final cloud.commandframework.Command<C> cloudCommand;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
BungeeCommand(
|
BungeeCommand(
|
||||||
|
|
@ -63,7 +62,6 @@ public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||||
);
|
);
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.cloudCommand = cloudCommand;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -78,7 +76,7 @@ public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||||
sender,
|
sender,
|
||||||
builder.toString()
|
builder.toString()
|
||||||
)
|
)
|
||||||
.whenComplete(((commandResult, throwable) -> {
|
.whenComplete((commandResult, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
if (throwable instanceof CompletionException) {
|
if (throwable instanceof CompletionException) {
|
||||||
throwable = throwable.getCause();
|
throwable = throwable.getCause();
|
||||||
|
|
@ -154,7 +152,7 @@ public final class BungeeCommand<C> extends Command implements TabExecutor {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ public class BungeeCommandManager<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}
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public BungeeCommandManager(
|
public BungeeCommandManager(
|
||||||
final @NonNull Plugin owningPlugin,
|
final @NonNull Plugin owningPlugin,
|
||||||
final @NonNull Function<@NonNull CommandTree<C>,
|
final @NonNull Function<@NonNull CommandTree<C>,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
||||||
* with Bungee specific objects
|
* with Bungee specific objects
|
||||||
*
|
*
|
||||||
* @param <C>
|
* @param <C> Command sender type
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
final class BungeeCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
final class BungeeCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,8 @@ public final class PlayerArgument<C> extends CommandArgument<C, ProxiedPlayer> {
|
||||||
|
|
||||||
public static final class PlayerParseException extends ParserException {
|
public static final class PlayerParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2685136673577959929L;
|
||||||
|
|
||||||
private PlayerParseException(
|
private PlayerParseException(
|
||||||
final @NonNull String input,
|
final @NonNull String input,
|
||||||
final @NonNull CommandContext<?> context
|
final @NonNull CommandContext<?> context
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,8 @@ public final class ServerArgument<C> extends CommandArgument<C, ServerInfo> {
|
||||||
|
|
||||||
public static final class ServerParseException extends ParserException {
|
public static final class ServerParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3825941611365494659L;
|
||||||
|
|
||||||
private ServerParseException(
|
private ServerParseException(
|
||||||
final @NonNull String input,
|
final @NonNull String input,
|
||||||
final @NonNull CommandContext<?> context
|
final @NonNull CommandContext<?> context
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ final class CloudburstCommand<C> extends PluginCommand<Plugin> {
|
||||||
|
|
||||||
private final CommandArgument<C, ?> command;
|
private final CommandArgument<C, ?> command;
|
||||||
private final CloudburstCommandManager<C> manager;
|
private final CloudburstCommandManager<C> manager;
|
||||||
private final Command<C> cloudCommand;
|
|
||||||
|
|
||||||
CloudburstCommand(
|
CloudburstCommand(
|
||||||
final @NonNull String label,
|
final @NonNull String label,
|
||||||
|
|
@ -64,7 +63,6 @@ final class CloudburstCommand<C> extends PluginCommand<Plugin> {
|
||||||
.build());
|
.build());
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.cloudCommand = cloudCommand;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -83,7 +81,7 @@ final class CloudburstCommand<C> extends PluginCommand<Plugin> {
|
||||||
sender,
|
sender,
|
||||||
builder.toString()
|
builder.toString()
|
||||||
)
|
)
|
||||||
.whenComplete(((commandResult, throwable) -> {
|
.whenComplete((commandResult, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
if (throwable instanceof CompletionException) {
|
if (throwable instanceof CompletionException) {
|
||||||
throwable = throwable.getCause();
|
throwable = throwable.getCause();
|
||||||
|
|
@ -131,7 +129,7 @@ final class CloudburstCommand<C> extends PluginCommand<Plugin> {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ 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}
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public CloudburstCommandManager(
|
public CloudburstCommandManager(
|
||||||
final @NonNull Plugin owningPlugin,
|
final @NonNull Plugin owningPlugin,
|
||||||
final @NonNull Function<@NonNull CommandTree<C>,
|
final @NonNull Function<@NonNull CommandTree<C>,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ class CloudburstPluginRegistrationHandler<C> implements CommandRegistrationHandl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final boolean registerCommand(final @NonNull Command<?> command) {
|
public final boolean registerCommand(final @NonNull 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);
|
||||||
|
|
|
||||||
|
|
@ -588,6 +588,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the configured primary color
|
||||||
|
*
|
||||||
* @return The primary color for the color scheme
|
* @return The primary color for the color scheme
|
||||||
*/
|
*/
|
||||||
public @NonNull TextColor primary() {
|
public @NonNull TextColor primary() {
|
||||||
|
|
@ -595,6 +597,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the configured highlight color
|
||||||
|
*
|
||||||
* @return The primary color used to highlight commands and queries
|
* @return The primary color used to highlight commands and queries
|
||||||
*/
|
*/
|
||||||
public @NonNull TextColor highlight() {
|
public @NonNull TextColor highlight() {
|
||||||
|
|
@ -602,6 +606,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the configured alternate highlight color
|
||||||
|
*
|
||||||
* @return The secondary color used to highlight commands and queries
|
* @return The secondary color used to highlight commands and queries
|
||||||
*/
|
*/
|
||||||
public @NonNull TextColor alternateHighlight() {
|
public @NonNull TextColor alternateHighlight() {
|
||||||
|
|
@ -609,6 +615,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the configured text color
|
||||||
|
*
|
||||||
* @return The color used for description text
|
* @return The color used for description text
|
||||||
*/
|
*/
|
||||||
public @NonNull TextColor text() {
|
public @NonNull TextColor text() {
|
||||||
|
|
@ -616,6 +624,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the configured accent color
|
||||||
|
*
|
||||||
* @return The color used for accents and symbols
|
* @return The color used for accents and symbols
|
||||||
*/
|
*/
|
||||||
public @NonNull TextColor accent() {
|
public @NonNull TextColor accent() {
|
||||||
|
|
@ -623,6 +633,8 @@ public final class MinecraftHelp<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Create a new {@link HelpColors} instance
|
||||||
|
*
|
||||||
* @param primary The primary color for the color scheme
|
* @param primary The primary color for the color scheme
|
||||||
* @param highlight The primary color used to highlight commands and queries
|
* @param highlight The primary color used to highlight commands and queries
|
||||||
* @param alternateHighlight The secondary color used to highlight commands and queries
|
* @param alternateHighlight The secondary color used to highlight commands and queries
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ final class Pagination<T> {
|
||||||
this.outOfRangeRenderer = outOfRangeRenderer;
|
this.outOfRangeRenderer = outOfRangeRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull List<Component> render(
|
@NonNull List<Component> render(
|
||||||
final @NonNull List<T> content,
|
final @NonNull List<T> content,
|
||||||
final int page,
|
final int page,
|
||||||
final int itemsPerPage
|
final int itemsPerPage
|
||||||
|
|
@ -73,7 +73,7 @@ final class Pagination<T> {
|
||||||
|
|
||||||
renderedContent.add(this.footerRenderer.apply(page, pages));
|
renderedContent.add(this.footerRenderer.apply(page, pages));
|
||||||
|
|
||||||
return renderedContent;
|
return Collections.unmodifiableList(renderedContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,8 @@ public final class TextColorArgument<C> extends CommandArgument<C, TextColor> {
|
||||||
|
|
||||||
private static final class TextColorParseException extends ParserException {
|
private static final class TextColorParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6236625328843879518L;
|
||||||
|
|
||||||
private TextColorParseException(
|
private TextColorParseException(
|
||||||
final @NonNull CommandContext<?> commandContext,
|
final @NonNull CommandContext<?> commandContext,
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,6 @@ dependencies {
|
||||||
api project(':cloud-bukkit')
|
api project(':cloud-bukkit')
|
||||||
compileOnly "com.destroystokyo.paper:paper-api:${vers['paper-api']}"
|
compileOnly "com.destroystokyo.paper:paper-api:${vers['paper-api']}"
|
||||||
compileOnly "com.destroystokyo.paper:paper-mojangapi:${vers['paper-api']}"
|
compileOnly "com.destroystokyo.paper:paper-mojangapi:${vers['paper-api']}"
|
||||||
|
compileOnly "org.jetbrains:annotations:${vers['jb-annotations']}"
|
||||||
|
compileOnly "com.google.guava:guava:${vers['guava']}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import cloud.commandframework.bukkit.BukkitBrigadierMapper;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.permission.CommandPermission;
|
import cloud.commandframework.permission.CommandPermission;
|
||||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||||
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
@ -60,7 +59,8 @@ class PaperBrigadierListener<C> implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onCommandRegister(final @NonNull CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
public void onCommandRegister(final com.destroystokyo.paper.event.brigadier
|
||||||
|
.@NonNull CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
||||||
if (!(event.getCommand() instanceof PluginIdentifiableCommand)) {
|
if (!(event.getCommand() instanceof PluginIdentifiableCommand)) {
|
||||||
return;
|
return;
|
||||||
} else if (!((PluginIdentifiableCommand) event.getCommand())
|
} else if (!((PluginIdentifiableCommand) event.getCommand())
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ public final class CloudInjectionModule<C> extends AbstractModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
final Type commandTreeType = Types.newParameterizedType(CommandTree.class, this.commandSenderType);
|
final Type commandTreeType = Types.newParameterizedType(CommandTree.class, this.commandSenderType);
|
||||||
final Type commandExecutionCoordinatorType = Types.newParameterizedType(CommandExecutionCoordinator.class,
|
final Type commandExecutionCoordinatorType = Types.newParameterizedType(CommandExecutionCoordinator.class,
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ public class VelocityCommandManager<C> extends CommandManager<C> {
|
||||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSource}
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSource}
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public VelocityCommandManager(
|
public VelocityCommandManager(
|
||||||
final @NonNull ProxyServer proxyServer,
|
final @NonNull ProxyServer proxyServer,
|
||||||
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
||||||
* with Velocity specific objects
|
* with Velocity specific objects
|
||||||
*
|
*
|
||||||
* @param <C>
|
* @param <C> Command sender type
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
final class VelocityCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
final class VelocityCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ final class VelocityPluginRegistrationHandler<C> implements CommandRegistrationH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public boolean registerCommand(final @NonNull Command<?> command) {
|
public boolean registerCommand(final @NonNull Command<?> command) {
|
||||||
final CommandArgument<?, ?> argument = command.getArguments().get(0);
|
final CommandArgument<?, ?> argument = command.getArguments().get(0);
|
||||||
final List<String> aliases = ((StaticArgument<C>) argument).getAlternativeAliases();
|
final List<String> aliases = ((StaticArgument<C>) argument).getAlternativeAliases();
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,8 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
||||||
|
|
||||||
public static final class PlayerParseException extends ParserException {
|
public static final class PlayerParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4839583631837040297L;
|
||||||
|
|
||||||
private PlayerParseException(
|
private PlayerParseException(
|
||||||
final @NonNull String input,
|
final @NonNull String input,
|
||||||
final @NonNull CommandContext<?> context
|
final @NonNull CommandContext<?> context
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,8 @@ public final class ServerArgument<C> extends CommandArgument<C, RegisteredServer
|
||||||
|
|
||||||
public static final class ServerParseException extends ParserException {
|
public static final class ServerParseException extends ParserException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 9168156226853233788L;
|
||||||
|
|
||||||
private ServerParseException(
|
private ServerParseException(
|
||||||
final @NonNull String input,
|
final @NonNull String input,
|
||||||
final @NonNull CommandContext<?> context
|
final @NonNull CommandContext<?> context
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
|
||||||
executionOrder = order.value();
|
executionOrder = order.value();
|
||||||
}
|
}
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
|
// This is fine
|
||||||
}
|
}
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.executionOrder = executionOrder;
|
this.executionOrder = executionOrder;
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
*/
|
*/
|
||||||
public final class PipelineException extends RuntimeException {
|
public final class PipelineException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7092487758537841656L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new pipeline exception
|
* Construct a new pipeline exception
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ public final class ServicePipeline {
|
||||||
* @return Service pipeline instance
|
* @return Service pipeline instance
|
||||||
* @throws Exception Any exceptions thrown during the registration process
|
* @throws Exception Any exceptions thrown during the registration process
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public <T> @NonNull ServicePipeline registerMethods(
|
public <T> @NonNull ServicePipeline registerMethods(
|
||||||
final @NonNull T instance
|
final @NonNull T instance
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ public interface ConsumerService<Context>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("FunctionalInterfaceMethodChanged")
|
||||||
default @NonNull State handle(final @NonNull Context context) {
|
default @NonNull State handle(final @NonNull Context context) {
|
||||||
try {
|
try {
|
||||||
this.accept(context);
|
this.accept(context);
|
||||||
|
|
@ -71,6 +72,8 @@ public interface ConsumerService<Context>
|
||||||
|
|
||||||
class PipeBurst extends RuntimeException {
|
class PipeBurst extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1143137258194595985L;
|
||||||
|
|
||||||
private PipeBurst() {
|
private PipeBurst() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ public interface Service<Context, Result> extends Function<@NonNull Context, @Nu
|
||||||
@Nullable Result handle(@NonNull Context context) throws Exception;
|
@Nullable Result handle(@NonNull Context context) throws Exception;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("FunctionalInterfaceMethodChanged")
|
||||||
default @Nullable Result apply(@NonNull Context context) {
|
default @Nullable Result apply(@NonNull Context context) {
|
||||||
try {
|
try {
|
||||||
return this.handle(context);
|
return this.handle(context);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.services.mock;
|
package cloud.commandframework.services.mock;
|
||||||
|
|
||||||
public class DefaultMockService implements MockService {
|
public final class DefaultMockService implements MockService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MockResult handle(final MockContext mockContext)
|
public MockResult handle(final MockContext mockContext)
|
||||||
|
|
@ -37,6 +37,8 @@ public class DefaultMockService implements MockService {
|
||||||
|
|
||||||
public static class TotallyIntentionalException extends Exception {
|
public static class TotallyIntentionalException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6277471288867949574L;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2020 Alexander Söderberg & Contributors
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock service files
|
||||||
|
*/
|
||||||
|
package cloud.commandframework.services.mock;
|
||||||
|
|
@ -35,7 +35,7 @@ import java.util.function.BiConsumer;
|
||||||
* A task recipe is a chain of tasks with optional synchronization steps,
|
* A task recipe is a chain of tasks with optional synchronization steps,
|
||||||
* that can be used to produce some sort of result from some input
|
* that can be used to produce some sort of result from some input
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings({"unchecked", "rawtypes", "unused", "overloads"})
|
||||||
public final class TaskRecipe {
|
public final class TaskRecipe {
|
||||||
|
|
||||||
private final TaskSynchronizer synchronizer;
|
private final TaskSynchronizer synchronizer;
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ import java.util.function.Function;
|
||||||
/**
|
/**
|
||||||
* Example plugin class
|
* Example plugin class
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public final class ExamplePlugin extends JavaPlugin {
|
public final class ExamplePlugin extends JavaPlugin {
|
||||||
|
|
||||||
private BukkitCommandManager<CommandSender> manager;
|
private BukkitCommandManager<CommandSender> manager;
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public abstract class CustomUser {
|
||||||
* @param user Sending user
|
* @param user Sending user
|
||||||
* @param channel Channel that the message was sent in
|
* @param channel Channel that the message was sent in
|
||||||
*/
|
*/
|
||||||
public CustomUser(final @NonNull User user, final @NonNull MessageChannel channel) {
|
protected CustomUser(final @NonNull User user, final @NonNull MessageChannel channel) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
@ -45,7 +44,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
@Plugin(
|
@Plugin(
|
||||||
id = "example-plugin",
|
id = "example-plugin",
|
||||||
|
|
@ -54,10 +52,6 @@ import java.util.logging.Logger;
|
||||||
)
|
)
|
||||||
public final class ExampleVelocityPlugin {
|
public final class ExampleVelocityPlugin {
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ProxyServer server;
|
|
||||||
@Inject
|
|
||||||
private Logger logger;
|
|
||||||
@Inject
|
@Inject
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue