Merge pull request 'Add better boolean handling for StaticValue annotation' (#11) from CMDAPIOptimizeISEForBoolean into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #11
Dieser Commit ist enthalten in:
YoyoNow 2022-08-16 17:53:06 +02:00
Commit 23a72f2acf
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> falseValues = new HashSet<>();
for (int i : staticValue.falseValues()) falseValues.add(i);
return createMapper(s -> {
int index = tabCompletes.indexOf(s);
return index == -1 ? null : index != 0;
return index == -1 ? null : !falseValues.contains(index);
}, (commandSender, s) -> tabCompletes);
}
if ((parameter.getType() == int.class || parameter.getType() == Integer.class) && staticValue.value().length >= 2) {