Throw an exception when trying to parse a static method with the @CommandMethod annotation

This commit is contained in:
jmp 2020-12-13 01:42:27 -08:00 committed by Alexander Söderberg
parent f8235a4ed1
commit e241420ee9
2 changed files with 8 additions and 1 deletions

View file

@ -49,6 +49,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
@ -243,6 +244,12 @@ public final class AnnotationParser<C> {
method.getName()
));
}
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalArgumentException(String.format(
"@CommandMethod annotated method '%s' is static! @CommandMethod annotated methods should not be static.",
method.getName()
));
}
commandMethodPairs.add(new CommandMethodPair(method, commandMethod));
}
final Collection<Command<C>> commands = this.construct(instance, commandMethodPairs);

View file

@ -639,7 +639,7 @@ public class Command<C> {
* Specify a required sender type
*
* @param senderType Required sender type
* @return New builder instance using the command execution handler
* @return New builder instance using the required sender type
*/
public @NonNull Builder<C> senderType(final @NonNull Class<? extends C> senderType) {
return new Builder<>(