From 296a27dc6304fe941d867102ca04778f2235a16f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 17 Jan 2019 11:33:43 +0200 Subject: [PATCH] Reorder config to the default sections on boot --- .../plan/system/settings/ConfigSystem.java | 5 +++++ .../plan/system/settings/config/ConfigNode.java | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ConfigSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ConfigSystem.java index 5d10049cd..6572b8ca3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ConfigSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/ConfigSystem.java @@ -31,6 +31,7 @@ import com.djrapitops.plugin.utilities.Verify; import javax.inject.Singleton; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -73,6 +74,10 @@ public abstract class ConfigSystem implements SubSystem { public void enable() throws EnableException { try { copyDefaults(); + config.reorder(Arrays.asList( + "Server", "Network", "Plugin", "Database", "Webserver", + "Data_gathering", "Time", "Display_options", "Formatting", "World_aliases", "Export", "Plugins" + )); config.save(); if (logger.getDebugLogger() instanceof CombineDebugLogger) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java index a43d5f904..7d20a7b2b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java @@ -192,12 +192,17 @@ public class ConfigNode { Collections.sort(nodeOrder); } - public boolean reorder(List newOrder) { - if (nodeOrder.containsAll(newOrder)) { - nodeOrder = newOrder; - return true; + public void reorder(List newOrder) { + List oldOrder = nodeOrder; + nodeOrder = new ArrayList<>(); + for (String key : newOrder) { + if (childNodes.containsKey(key)) { + nodeOrder.add(key); + } } - return false; + // Add those that were not in the new order, but are in the old order. + oldOrder.removeAll(nodeOrder); + nodeOrder.addAll(oldOrder); } /**