SteamWar/SpigotCore
Archiviert
13
0

Optimize SWCommandUtils

Dieser Commit ist enthalten in:
yoyosource 2021-03-26 08:40:05 +01:00
Ursprung a45a83e2d5
Commit 9b01cbf7bf

Datei anzeigen

@ -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
public Player map(String s) {
return Bukkit.getPlayer(s);
}
@Override
public List<String> tabCompletes(String s) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
} }));
}); MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), createMapper(s -> {
MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), new TypeMapper<GameMode>() { s = s.toLowerCase();
@Override if (s.equals("s") || s.equals("survival") || s.equals("0")) {
public GameMode map(String s) {
switch (s.toLowerCase()) {
case "s":
case "survival":
case "0":
return GameMode.SURVIVAL; return GameMode.SURVIVAL;
case "c": }
case "creative": if (s.equals("c") || s.equals("creative") || s.equals("1")) {
case "1":
return GameMode.CREATIVE; return GameMode.CREATIVE;
case "sp": }
case "spectator": if (s.equals("sp") || s.equals("spectator") || s.equals("3")) {
case "3":
return GameMode.SPECTATOR; return GameMode.SPECTATOR;
case "a": }
case "adventure": if (s.equals("a") || s.equals("adventure") || s.equals("2")) {
case "2":
return GameMode.ADVENTURE; return GameMode.ADVENTURE;
} }
throw new SecurityException(); throw new SecurityException();
} }, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "specator", "3", "a", "adventure", "2")));
@Override
public List<String> tabCompletes(String s) {
return 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) {