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