From 770db2fee00f54c71618ac8abed7cff7a6f4f684 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 30 Jun 2017 19:43:45 +0100 Subject: [PATCH] Export groups in order of weight, then alphabetically --- .../lucko/luckperms/common/data/Exporter.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java b/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java index db859ba3d..a10b90973 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.core.NodeFactory; -import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.locale.Message; @@ -110,20 +109,35 @@ public class Exporter implements Runnable { // Create the actual groups first write(writer, "# Create groups"); - for (Group group : plugin.getGroupManager().getAll().values()) { - write(writer, "/luckperms creategroup " + group.getName()); - } + plugin.getGroupManager().getAll().values().stream() + .sorted((o1, o2) -> { + int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0)); + return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName()); + }) + .filter(g -> !g.getName().equals("default")) + .forEach(group -> { + write(writer, "/luckperms creategroup " + group.getName()); + }); + write(writer, ""); AtomicInteger groupCount = new AtomicInteger(0); - for (Group group : plugin.getGroupManager().getAll().values()) { - write(writer, "# Export group: " + group.getName()); - for (Node node : group.getNodes().values()) { - write(writer, NodeFactory.nodeAsCommand(node, group.getName(), true)); - } - write(writer, ""); - log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet()); - } + + // export groups in order of weight + plugin.getGroupManager().getAll().values().stream() + .sorted((o1, o2) -> { + int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0)); + return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName()); + }) + .forEach(group -> { + write(writer, "# Export group: " + group.getName()); + for (Node node : group.getNodes().values()) { + write(writer, NodeFactory.nodeAsCommand(node, group.getName(), true)); + } + write(writer, ""); + log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet()); + }); + log.log("Exported " + groupCount.get() + " groups."); write(writer, "");