Rename ArgumentUtils.ofEnum
Remove Argument.BOOLEAN
Dieser Commit ist enthalten in:
Ursprung
03bdb926ca
Commit
215db51837
@ -45,7 +45,6 @@ public class Argument<T> {
|
||||
numbers.add(Float.class);
|
||||
}
|
||||
|
||||
public static final Argument<Boolean> BOOLEAN = new Argument<>(Boolean::parseBoolean, bool -> true, "true", "false");
|
||||
public static final Argument<Integer> INT = new Argument<>(Integer::parseInt, integer -> true);
|
||||
public static final Argument<Double> DOUBLE = new Argument<>(Double::parseDouble, d -> true);
|
||||
public static final Argument<String> STRING = new Argument<>(s -> s, string -> true);
|
||||
|
@ -21,6 +21,7 @@
|
||||
package de.steamwar.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
@ -52,17 +53,6 @@ public class ArgumentUtils {
|
||||
return new Argument<>(s -> s, string -> contains(commands, string, String::equals), s -> supply(s, tabCompletes, commands));
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> Argument<T> enumValue(Class<T> enumClass) {
|
||||
T[] enumValues = enumClass.getEnumConstants();
|
||||
String[] strings = Arrays.stream(enumValues).map(Enum::name).toArray(String[]::new);
|
||||
return new Argument<>((s, sender) -> {
|
||||
for (T enumValue : enumValues) {
|
||||
if (enumValue.name().startsWith(s)) return enumValue;
|
||||
}
|
||||
return null;
|
||||
}, Objects::nonNull, s -> strings);
|
||||
}
|
||||
|
||||
public static Argument<String> ofIgnoreCase(String... arguments) {
|
||||
return new Argument<>(s -> s, string -> contains(arguments, string, String::equals), arguments);
|
||||
}
|
||||
@ -81,4 +71,13 @@ public class ArgumentUtils {
|
||||
return new Argument<>(Double::parseDouble, predicate, tabCompletes(Arrays.stream(tabValues).boxed(), predicate));
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> Argument<T> ofEnum(Class<T> enumClass) {
|
||||
T[] enumValues = enumClass.getEnumConstants();
|
||||
String[] strings = Arrays.stream(enumValues).map(Enum::name).toArray(String[]::new);
|
||||
return new Argument<>((s, sender) -> {
|
||||
for (T enumValue : enumValues) if (enumValue.name().startsWith(s)) return enumValue;
|
||||
return null;
|
||||
}, Objects::nonNull, s -> strings);
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren