Ignore commented lines on dump imports & add annotations to export files - closes #169

This commit is contained in:
Luck 2017-02-05 09:58:00 +00:00
parent 0982154a15
commit 0d1f3b855f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 30 additions and 3 deletions

View File

@ -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<UUID> 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()) {

View File

@ -75,9 +75,12 @@ public class Importer {
public void start(Sender executor, List<String> 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<>();