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 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) {

View File

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