Optimize SWCommandUtils
Dieser Commit ist enthalten in:
Ursprung
a45a83e2d5
Commit
9b01cbf7bf
@ -88,46 +88,25 @@ class SWCommandUtils {
|
|||||||
}));
|
}));
|
||||||
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(StringBuilder.class.getTypeName(), createMapper(StringBuilder::new, Collections::singletonList));
|
MAPPER_FUNCTIONS.put(StringBuilder.class.getTypeName(), createMapper(StringBuilder::new, Collections::singletonList));
|
||||||
MAPPER_FUNCTIONS.put(Player.class.getTypeName(), new TypeMapper<Player>() {
|
MAPPER_FUNCTIONS.put(Player.class.getTypeName(), createMapper(Bukkit::getPlayer, s -> {
|
||||||
@Override
|
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||||
public Player map(String s) {
|
}));
|
||||||
return Bukkit.getPlayer(s);
|
MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), createMapper(s -> {
|
||||||
|
s = s.toLowerCase();
|
||||||
|
if (s.equals("s") || s.equals("survival") || s.equals("0")) {
|
||||||
|
return GameMode.SURVIVAL;
|
||||||
}
|
}
|
||||||
|
if (s.equals("c") || s.equals("creative") || s.equals("1")) {
|
||||||
@Override
|
return GameMode.CREATIVE;
|
||||||
public List<String> tabCompletes(String s) {
|
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
});
|
if (s.equals("sp") || s.equals("spectator") || s.equals("3")) {
|
||||||
MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), new TypeMapper<GameMode>() {
|
return GameMode.SPECTATOR;
|
||||||
@Override
|
|
||||||
public GameMode map(String s) {
|
|
||||||
switch (s.toLowerCase()) {
|
|
||||||
case "s":
|
|
||||||
case "survival":
|
|
||||||
case "0":
|
|
||||||
return GameMode.SURVIVAL;
|
|
||||||
case "c":
|
|
||||||
case "creative":
|
|
||||||
case "1":
|
|
||||||
return GameMode.CREATIVE;
|
|
||||||
case "sp":
|
|
||||||
case "spectator":
|
|
||||||
case "3":
|
|
||||||
return GameMode.SPECTATOR;
|
|
||||||
case "a":
|
|
||||||
case "adventure":
|
|
||||||
case "2":
|
|
||||||
return GameMode.ADVENTURE;
|
|
||||||
}
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
}
|
||||||
|
if (s.equals("a") || s.equals("adventure") || s.equals("2")) {
|
||||||
@Override
|
return GameMode.ADVENTURE;
|
||||||
public List<String> tabCompletes(String s) {
|
|
||||||
return Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "specator", "3", "a", "adventure", "2");
|
|
||||||
}
|
}
|
||||||
});
|
throw new SecurityException();
|
||||||
|
}, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "specator", "3", "a", "adventure", "2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, TypeMapper<?> mapper) {
|
private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, TypeMapper<?> mapper) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren