SteamWar/SpigotCore
Archiviert
13
0

Optimize SWCommandUtils

Dieser Commit ist enthalten in:
yoyosource 2021-03-26 09:09:39 +01:00
Ursprung ccb63e1613
Commit d0186a43d1

Datei anzeigen

@ -40,17 +40,9 @@ public class SWCommandUtils {
static final Map<String, TypeMapper<?>> MAPPER_FUNCTIONS = new HashMap<>(); static final Map<String, TypeMapper<?>> MAPPER_FUNCTIONS = new HashMap<>();
static final TypeMapper<?> ERROR_FUNCTION = new TypeMapper<Object>() { static final TypeMapper<?> ERROR_FUNCTION = createMapper(s -> {
@Override throw new SecurityException();
public Object map(String s) { }, s -> Collections.emptyList());
throw new SecurityException();
}
@Override
public List<String> tabCompletes(String s) {
return Collections.emptyList();
}
};
static final BiFunction<Class<Enum<?>>, String, Enum<?>> ENUM_MAPPER = (enumClass, s) -> { static final BiFunction<Class<Enum<?>>, String, Enum<?>> ENUM_MAPPER = (enumClass, s) -> {
Enum<?>[] enums = enumClass.getEnumConstants(); Enum<?>[] enums = enumClass.getEnumConstants();
@ -67,23 +59,13 @@ public class SWCommandUtils {
addMapper(int.class, Integer.class, createMapper(Integer::parseInt, numberCompleter(Integer::parseInt))); addMapper(int.class, Integer.class, createMapper(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(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(), createMapper(Bukkit::getPlayer, s -> { MAPPER_FUNCTIONS.put(Player.class.getTypeName(), createMapper(Bukkit::getPlayer, s -> 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(), createMapper(s -> {
s = s.toLowerCase(); s = s.toLowerCase();
if (s.equals("s") || s.equals("survival") || s.equals("0")) { if (s.equals("s") || s.equals("survival") || s.equals("0")) return GameMode.SURVIVAL;
return GameMode.SURVIVAL; 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("c") || s.equals("creative") || s.equals("1")) { if (s.equals("a") || s.equals("adventure") || s.equals("2")) return GameMode.ADVENTURE;
return GameMode.CREATIVE;
}
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;
}
throw new SecurityException(); throw new SecurityException();
}, 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")));
} }