diff --git a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java index 9ccf0700..c7813b12 100644 --- a/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java +++ b/CommonCore/Data/src/de/steamwar/data/YMLWrapper.java @@ -83,9 +83,15 @@ public abstract class YMLWrapper { return materialMapper.apply(getString(path, defaultValue).toUpperCase()); } - public abstract List getStringList(String path); + public abstract List get(String path, Function> mapper); - public abstract List getIntList(String path); + public List getStringList(String path) { + return get(path, o -> (List) o); + } + + public List getIntList(String path) { + return get(path, o -> (List) o); + } public final List getSchematicTypeList(String path) { List list = getStringList(path); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java index 2f07b6b2..55b749bb 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/data/YMLWrapperImpl.java @@ -111,24 +111,16 @@ public class YMLWrapperImpl extends YMLWrapper { } @Override - public List getStringList(String path) { + public List get(String path, Function> mapper) { if (config == null) return Collections.emptyList(); - List 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 getIntList(String path) { - if (config == null) return Collections.emptyList(); - List 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); } } diff --git a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java index c58c4708..b5dc7a60 100644 --- a/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java +++ b/VelocityCore/src/de/steamwar/data/YMLWrapperImpl.java @@ -99,21 +99,12 @@ public class YMLWrapperImpl extends YMLWrapper { } @Override - public List getStringList(String path) { + public List get(String path, Function> mapper) { Object value = this.document.get(path); - if (value instanceof List) { - return Collections.unmodifiableList((List) value); - } else { - return Collections.emptyList(); - } - } - - @Override - public List getIntList(String path) { - Object value = this.document.get(path); - if (value instanceof List) { - return Collections.unmodifiableList((List) value); - } else { + if (value == null) return Collections.emptyList(); + try { + return Collections.unmodifiableList(mapper.apply(value)); + } catch (ClassCastException e) { return Collections.emptyList(); } }