Fix SWCommandUtils for Number mapping
Dieser Commit ist enthalten in:
Ursprung
9a9e337706
Commit
a35c42faa2
@ -58,9 +58,9 @@ public class SWCommandUtils {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
addMapper(boolean.class, Boolean.class, createMapper(Boolean::parseBoolean, s -> Arrays.asList("true", "false")));
|
addMapper(boolean.class, Boolean.class, createMapper(Boolean::parseBoolean, s -> Arrays.asList("true", "false")));
|
||||||
addMapper(float.class, Float.class, createMapper(Float::parseFloat, numberCompleter(Float::parseFloat)));
|
addMapper(float.class, Float.class, createMapper(numberMapper(Float::parseFloat), numberCompleter(Float::parseFloat)));
|
||||||
addMapper(double.class, Double.class, createMapper(Double::parseDouble, numberCompleter(Double::parseDouble)));
|
addMapper(double.class, Double.class, createMapper(numberMapper(Double::parseDouble), numberCompleter(Double::parseDouble)));
|
||||||
addMapper(int.class, Integer.class, createMapper(Integer::parseInt, numberCompleter(Integer::parseInt)));
|
addMapper(int.class, Integer.class, createMapper(numberMapper(Integer::parseInt), numberCompleter(Integer::parseInt)));
|
||||||
MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList));
|
MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList));
|
||||||
MAPPER_FUNCTIONS.put(Player.class.getTypeName(), createMapper(Bukkit::getPlayer, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())));
|
MAPPER_FUNCTIONS.put(Player.class.getTypeName(), createMapper(Bukkit::getPlayer, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())));
|
||||||
MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), createMapper(s -> {
|
MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), createMapper(s -> {
|
||||||
@ -69,7 +69,7 @@ public class SWCommandUtils {
|
|||||||
if (s.equals("c") || s.equals("creative") || s.equals("1")) return GameMode.CREATIVE;
|
if (s.equals("c") || s.equals("creative") || s.equals("1")) return GameMode.CREATIVE;
|
||||||
if (s.equals("sp") || s.equals("spectator") || s.equals("3")) return GameMode.SPECTATOR;
|
if (s.equals("sp") || s.equals("spectator") || s.equals("3")) return GameMode.SPECTATOR;
|
||||||
if (s.equals("a") || s.equals("adventure") || s.equals("2")) return GameMode.ADVENTURE;
|
if (s.equals("a") || s.equals("adventure") || s.equals("2")) return GameMode.ADVENTURE;
|
||||||
throw new SecurityException();
|
return null;
|
||||||
}, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "specator", "3", "a", "adventure", "2")));
|
}, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "specator", "3", "a", "adventure", "2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,6 +167,16 @@ public class SWCommandUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> Function<String, T> numberMapper(Function<String, T> mapper) {
|
||||||
|
return s -> {
|
||||||
|
try {
|
||||||
|
return mapper.apply(s);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private static Function<String, List<String>> numberCompleter(Function<String, ?> mapper) {
|
private static Function<String, List<String>> numberCompleter(Function<String, ?> mapper) {
|
||||||
return s -> {
|
return s -> {
|
||||||
try {
|
try {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren