Fix defaults not being added properly

This commit is contained in:
Frank van der Heijden 2020-06-27 10:58:44 +02:00
parent 83401bf622
commit 522f20702d
No known key found for this signature in database
GPG key ID: 26DA56488D314D11

View file

@ -13,15 +13,14 @@ public class YamlUtils {
} }
private static void addDefaults(MemorySection defaults, YamlConfiguration yml, String root) { private static void addDefaults(MemorySection defaults, YamlConfiguration yml, String root) {
MemorySection section = (MemorySection) defaults.get(root); if (defaults == null) return;
if (section == null) return; for (String key : defaults.getKeys(false)) {
for (String key : section.getKeys(false)) {
String newKey = (root.isEmpty() ? "" : root + ".") + key; String newKey = (root.isEmpty() ? "" : root + ".") + key;
Object value = defaults.get(key); Object value = defaults.get(key);
if (value instanceof MemorySection) { if (value instanceof MemorySection) {
addDefaults((MemorySection) value, yml, newKey); addDefaults((MemorySection) value, yml, newKey);
} else if (yml.get(key) == null) { } else if (yml.get(newKey) == null) {
yml.set(key, value); yml.set(newKey, value);
} }
} }
} }