forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -182,8 +182,9 @@ public abstract class AbstractSWCommand<T> {
|
||||
if (!checkType(method.getAnnotations(), method.getReturnType(), false, annotation -> {
|
||||
CommandMetaData.Method methodMetaData = annotation.annotationType().getAnnotation(CommandMetaData.Method.class);
|
||||
if (methodMetaData == null) return (aClass, varArg) -> true;
|
||||
if (method.getParameterCount() > methodMetaData.maxParameterCount() || method.getParameterCount() < methodMetaData.minParameterCount())
|
||||
if (method.getParameterCount() > methodMetaData.maxParameterCount() || method.getParameterCount() < methodMetaData.minParameterCount()) {
|
||||
return (aClass, varArg) -> false;
|
||||
}
|
||||
return (aClass, varArg) -> {
|
||||
Class<?>[] types = methodMetaData.value();
|
||||
if (types == null) return true;
|
||||
|
||||
@@ -31,8 +31,8 @@ public interface AbstractValidator<K, T> {
|
||||
/**
|
||||
* Validates the given value.
|
||||
*
|
||||
* @param sender The sender of the command.
|
||||
* @param value The value to validate or null if mapping returned null.
|
||||
* @param sender The sender of the command.
|
||||
* @param value The value to validate or null if mapping returned null.
|
||||
* @param messageSender The message sender to send messages to the player. Never send messages directly to the player.
|
||||
* @return The result of the validation.
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,9 @@ public @interface CommandMetaData {
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@interface Method {
|
||||
Class<?>[] value();
|
||||
|
||||
int minParameterCount() default 0;
|
||||
|
||||
int maxParameterCount() default Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@@ -44,6 +46,7 @@ public @interface CommandMetaData {
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@interface Parameter {
|
||||
Class<?>[] value() default {};
|
||||
|
||||
Class<?> handler() default void.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,8 @@ class CommandPart<T> {
|
||||
List<Object> currentArgs = new ArrayList<>(mappedArgs);
|
||||
List<Object> varArgs = new ArrayList<>();
|
||||
for (int i = startIndex; i < args.length - 1; i++) {
|
||||
CheckArgumentResult validArgument = checkArgument((ignore) -> {}, sender, args, mappedArgs, i);
|
||||
CheckArgumentResult validArgument = checkArgument((ignore) -> {
|
||||
}, sender, args, mappedArgs, i);
|
||||
if (!validArgument.success) return;
|
||||
varArgs.add(validArgument.value);
|
||||
}
|
||||
@@ -162,7 +163,8 @@ class CommandPart<T> {
|
||||
}
|
||||
|
||||
if (args.length - 1 > startIndex) {
|
||||
CheckArgumentResult checkArgumentResult = checkArgument((ignore) -> {}, sender, args, mappedArgs, startIndex);
|
||||
CheckArgumentResult checkArgumentResult = checkArgument((ignore) -> {
|
||||
}, sender, args, mappedArgs, startIndex);
|
||||
if (checkArgumentResult.success && next != null) {
|
||||
if (!ignoreAsArgument) {
|
||||
mappedArgs.add(checkArgumentResult.value);
|
||||
|
||||
@@ -138,7 +138,8 @@ public class SubCommand<T> implements Comparable<SubCommand<T>> {
|
||||
}
|
||||
|
||||
List<String> tabComplete(T sender, String[] args) {
|
||||
if (validator != null && !validator.validate(sender, sender, (s, objects) -> {})) {
|
||||
if (validator != null && !validator.validate(sender, sender, (s, objects) -> {
|
||||
})) {
|
||||
return null;
|
||||
}
|
||||
if (commandPart == null) {
|
||||
|
||||
Reference in New Issue
Block a user