Add better boolean handling for StaticValue annotation
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-08-16 17:11:16 +02:00
Ursprung 47bd9af03e
Commit 5050580774
2 geänderte Dateien mit 8 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -371,10 +371,12 @@ public abstract class AbstractSWCommand<T> {
* and can be set to true if you want to allow int as well as boolean as annotated parameter types.
* The value array needs to be at least 2 long for this flag to be considered.
* While using an int, the value will represent the index into the value array.
* While using a boolean, the value array must only be 2 long and the value will be {@code false}
* for the first index and {@code true} for the second index.
* While using a boolean, the {@link #falseValues()} defines which indices are
* considered {@code false} or {@code true}.
*/
boolean allowISE() default false;
int[] falseValues() default { 0 };
}
@Retention(RetentionPolicy.RUNTIME)

Datei anzeigen

@ -136,11 +136,13 @@ public class SWCommandUtils {
return createMapper(staticValue.value());
}
if (staticValue.allowISE()) {
if ((parameter.getType() == boolean.class || parameter.getType() == Boolean.class) && staticValue.value().length == 2) {
if ((parameter.getType() == boolean.class || parameter.getType() == Boolean.class)) {
List<String> tabCompletes = new ArrayList<>(Arrays.asList(staticValue.value()));
Set<Integer> trueValues = new HashSet<>();
for (int i : staticValue.falseValues()) trueValues.add(i);
return createMapper(s -> {
int index = tabCompletes.indexOf(s);
return index == -1 ? null : index != 0;
return index == -1 ? null : !trueValues.contains(index);
}, (commandSender, s) -> tabCompletes);
}
if ((parameter.getType() == int.class || parameter.getType() == Integer.class) && staticValue.value().length >= 2) {