Dieser Commit ist enthalten in:
Ursprung
c4ed8948ad
Commit
4e46e05a3b
@ -381,5 +381,10 @@ public abstract class AbstractSWCommand<T> {
|
||||
* Error message to be displayed when the parameter is invalid.
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* This is the short form for 'allowEmptyArrays'.
|
||||
*/
|
||||
boolean allowEAs() default true;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
@ -187,8 +188,12 @@ public class SWCommandUtils {
|
||||
|
||||
AbstractSWCommand.ErrorMessage errorMessage = parameter.getAnnotation(AbstractSWCommand.ErrorMessage.class);
|
||||
if (errorMessage != null) {
|
||||
return (AbstractValidator<T, String>) (sender, value, messageSender) -> {
|
||||
if (value == null) messageSender.send(errorMessage.value(), new Object[0]);
|
||||
return (AbstractValidator<T, Object>) (sender, value, messageSender) -> {
|
||||
if (value == null) messageSender.send(errorMessage.value());
|
||||
if (!errorMessage.allowEAs() && value != null && value.getClass().isArray() && Array.getLength(value) == 0) {
|
||||
messageSender.send(errorMessage.value());
|
||||
return false;
|
||||
}
|
||||
return value != null;
|
||||
};
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren