Reorder config to the default sections on boot

This commit is contained in:
Rsl1122 2019-01-17 11:33:43 +02:00
parent c011bb6be0
commit 296a27dc63
2 changed files with 15 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -73,6 +74,10 @@ public abstract class ConfigSystem implements SubSystem {
public void enable() throws EnableException { public void enable() throws EnableException {
try { try {
copyDefaults(); copyDefaults();
config.reorder(Arrays.asList(
"Server", "Network", "Plugin", "Database", "Webserver",
"Data_gathering", "Time", "Display_options", "Formatting", "World_aliases", "Export", "Plugins"
));
config.save(); config.save();
if (logger.getDebugLogger() instanceof CombineDebugLogger) { if (logger.getDebugLogger() instanceof CombineDebugLogger) {

View File

@ -192,12 +192,17 @@ public class ConfigNode {
Collections.sort(nodeOrder); Collections.sort(nodeOrder);
} }
public boolean reorder(List<String> newOrder) { public void reorder(List<String> newOrder) {
if (nodeOrder.containsAll(newOrder)) { List<String> oldOrder = nodeOrder;
nodeOrder = newOrder; nodeOrder = new ArrayList<>();
return true; 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);
} }
/** /**