Merge pull request 'Add better boolean handling for StaticValue annotation' (#11) from CMDAPIOptimizeISEForBoolean into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #11
Dieser Commit ist enthalten in:
Commit
23a72f2acf
@ -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.
|
* 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.
|
* 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 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}
|
* While using a boolean, the {@link #falseValues()} defines which indices are
|
||||||
* for the first index and {@code true} for the second index.
|
* considered {@code false} or {@code true}.
|
||||||
*/
|
*/
|
||||||
boolean allowISE() default false;
|
boolean allowISE() default false;
|
||||||
|
|
||||||
|
int[] falseValues() default { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@ -136,11 +136,13 @@ public class SWCommandUtils {
|
|||||||
return createMapper(staticValue.value());
|
return createMapper(staticValue.value());
|
||||||
}
|
}
|
||||||
if (staticValue.allowISE()) {
|
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()));
|
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 -> {
|
return createMapper(s -> {
|
||||||
int index = tabCompletes.indexOf(s);
|
int index = tabCompletes.indexOf(s);
|
||||||
return index == -1 ? null : index != 0;
|
return index == -1 ? null : !falseValues.contains(index);
|
||||||
}, (commandSender, s) -> tabCompletes);
|
}, (commandSender, s) -> tabCompletes);
|
||||||
}
|
}
|
||||||
if ((parameter.getType() == int.class || parameter.getType() == Integer.class) && staticValue.value().length >= 2) {
|
if ((parameter.getType() == int.class || parameter.getType() == Integer.class) && staticValue.value().length >= 2) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren