✨ Throw an exception when trying to parse a static method with the @CommandMethod annotation
This commit is contained in:
parent
f8235a4ed1
commit
e241420ee9
2 changed files with 8 additions and 1 deletions
|
|
@ -49,6 +49,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -243,6 +244,12 @@ public final class AnnotationParser<C> {
|
||||||
method.getName()
|
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));
|
commandMethodPairs.add(new CommandMethodPair(method, commandMethod));
|
||||||
}
|
}
|
||||||
final Collection<Command<C>> commands = this.construct(instance, commandMethodPairs);
|
final Collection<Command<C>> commands = this.construct(instance, commandMethodPairs);
|
||||||
|
|
|
||||||
|
|
@ -639,7 +639,7 @@ public class Command<C> {
|
||||||
* Specify a required sender type
|
* Specify a required sender type
|
||||||
*
|
*
|
||||||
* @param senderType 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) {
|
public @NonNull Builder<C> senderType(final @NonNull Class<? extends C> senderType) {
|
||||||
return new Builder<>(
|
return new Builder<>(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue