Add better boolean handling for StaticValue annotation
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
47bd9af03e
Commit
5050580774
@ -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)
|
||||
|
@ -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) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren