forked from SteamWar/SteamWar
Improve YMLWrapper
This commit is contained in:
@@ -111,24 +111,16 @@ public class YMLWrapperImpl<M, ST, W> extends YMLWrapper<M, ST, W> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String path) {
|
||||
public <T> List<T> get(String path, Function<Object, List<T>> mapper) {
|
||||
if (config == null) return Collections.emptyList();
|
||||
List<String> list = config.getStringList(pathPrefix + path);
|
||||
if (list.isEmpty()) {
|
||||
List<?> list = config.getList(pathPrefix + path);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getIntList(String path) {
|
||||
if (config == null) return Collections.emptyList();
|
||||
List<Integer> list = config.getIntegerList(pathPrefix + path);
|
||||
if (list.isEmpty()) {
|
||||
try {
|
||||
return Collections.unmodifiableList(mapper.apply(list));
|
||||
} catch (ClassCastException e) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user