Check if config values aren't null before attempting to set them.

This commit is contained in:
extendedclip 2019-05-10 20:36:43 -04:00
parent 9377129554
commit f367abbdfa

View File

@ -20,11 +20,6 @@
*/ */
package me.clip.placeholderapi.expansion; package me.clip.placeholderapi.expansion;
import java.io.File;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.PlaceholderHook; import me.clip.placeholderapi.PlaceholderHook;
@ -34,6 +29,12 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.io.File;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public final class ExpansionManager { public final class ExpansionManager {
private PlaceholderAPIPlugin plugin; private PlaceholderAPIPlugin plugin;
@ -65,19 +66,21 @@ public final class ExpansionManager {
String pre = "expansions." + expansion.getIdentifier() + "."; String pre = "expansions." + expansion.getIdentifier() + ".";
FileConfiguration cfg = plugin.getConfig(); FileConfiguration cfg = plugin.getConfig();
boolean save = false; boolean save = false;
for (Entry<String, Object> entries : defaults.entrySet()) { if (defaults != null) {
if (entries.getKey() == null || entries.getKey().isEmpty()) { for (Entry<String, Object> entries : defaults.entrySet()) {
continue; if (entries.getKey() == null || entries.getKey().isEmpty()) {
} continue;
if (entries.getValue() == null) {
if (cfg.contains(pre + entries.getKey())) {
save = true;
cfg.set(pre + entries.getKey(), null);
} }
} else { if (entries.getValue() == null) {
if (!cfg.contains(pre + entries.getKey())) { if (cfg.contains(pre + entries.getKey())) {
save = true; save = true;
cfg.set(pre + entries.getKey(), entries.getValue()); cfg.set(pre + entries.getKey(), null);
}
} else {
if (!cfg.contains(pre + entries.getKey())) {
save = true;
cfg.set(pre + entries.getKey(), entries.getValue());
}
} }
} }
} }