Improve YMLWrapper

This commit is contained in:
2025-10-25 22:08:58 +02:00
parent e6dea72024
commit 4405d9c25d
3 changed files with 19 additions and 30 deletions
@@ -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);
}
}