diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java index 22e0faf1b..d65d7a2d1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java @@ -43,12 +43,16 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; public class ExportCommand extends SingleCommand { + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + private static void write(BufferedWriter writer, String s) { try { writer.write(s); @@ -94,50 +98,70 @@ public class ExportCommand extends SingleCommand { try (FileWriter fWriter = new FileWriter(f, true); BufferedWriter writer = new BufferedWriter(fWriter)) { log.log("Starting."); + write(writer, "# LuckPerms Export File"); + write(writer, "# Generated by " + sender.getName() + " at " + DATE_FORMAT.format(new Date(System.currentTimeMillis()))); + write(writer, ""); + // Export Groups log.log("Starting group export."); // Create the actual groups first + write(writer, "# Create groups"); for (Group group : plugin.getGroupManager().getAll().values()) { 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()) { 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, ""); + write(writer, ""); + // Export tracks log.log("Starting track export."); // Create the actual tracks first + write(writer, "# Create tracks"); for (Track track : plugin.getTrackManager().getAll().values()) { write(writer, "/luckperms createtrack " + track.getName()); } AtomicInteger trackCount = new AtomicInteger(0); for (Track track : plugin.getTrackManager().getAll().values()) { + write(writer, "# Export track: " + track.getName()); for (String group : track.getGroups()) { write(writer, "/luckperms track " + track.getName() + " append " + group); } + write(writer, ""); log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet()); } log.log("Exported " + trackCount.get() + " tracks."); + write(writer, ""); + write(writer, ""); + // Export users log.log("Starting user export. Finding a list of unique users to export."); Storage ds = plugin.getStorage(); Set users = ds.getUniqueUsers().join(); log.log("Found " + users.size() + " unique users to export."); + write(writer, "# Export users"); + AtomicInteger userCount = new AtomicInteger(0); for (UUID uuid : users) { plugin.getStorage().loadUser(uuid, "null").join(); User user = plugin.getUserManager().get(uuid); + write(writer, "# Export user: " + user.getUuid().toString() + " - " + user.getName()); boolean inDefault = false; for (Node node : user.getNodes()) { diff --git a/common/src/main/java/me/lucko/luckperms/common/data/Importer.java b/common/src/main/java/me/lucko/luckperms/common/data/Importer.java index 2cd2fef0e..811fe4419 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/Importer.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/Importer.java @@ -75,9 +75,12 @@ public class Importer { public void start(Sender executor, List commands) { this.executor = executor; this.commands = commands.stream() - .map(s -> s.startsWith("/") ? s.substring(1) : s) - .map(s -> s.startsWith("perms ") ? s.substring(6) : s) - .map(s -> s.startsWith("luckperms ") ? s.substring(10) : s) + .filter(s -> !s.isEmpty()) + .filter(s -> !s.startsWith("#")) + .filter(s -> !s.startsWith("//")) + .map(s -> s.startsWith("/") ? s.substring("/".length()) : s) + .map(s -> s.startsWith("perms ") ? s.substring("perms ".length()) : s) + .map(s -> s.startsWith("luckperms ") ? s.substring("luckperms ".length()) : s) .collect(Collectors.toList()); cmdResult = new HashMap<>();