Fix import/export handling - closes #159

This commit is contained in:
Luck 2017-02-02 15:13:44 +00:00
parent 9cee319ed9
commit ede413a213
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
14 changed files with 130 additions and 101 deletions

View File

@ -33,12 +33,12 @@ import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -71,7 +71,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("bPermissions"); ProgressLogger log = new ProgressLogger("bPermissions");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);
@ -186,7 +186,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
} }
} }
private static void migrateHolder(MigrationLogger log, World world, Calculable c, PermissionHolder holder) { private static void migrateHolder(ProgressLogger log, World world, Calculable c, PermissionHolder holder) {
// Migrate the groups permissions in this world // Migrate the groups permissions in this world
for (Permission p : c.getPermissions()) { for (Permission p : c.getPermissions()) {
try { try {

View File

@ -28,11 +28,11 @@ import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -62,7 +62,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("GroupManager"); ProgressLogger log = new ProgressLogger("GroupManager");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);

View File

@ -26,13 +26,13 @@ import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -59,7 +59,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("PermissionsEx"); ProgressLogger log = new ProgressLogger("PermissionsEx");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);

View File

@ -36,12 +36,12 @@ import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -144,7 +144,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
} }
private CommandResult run(LuckPermsPlugin plugin, Sender sender, List<String> args) { private CommandResult run(LuckPermsPlugin plugin, Sender sender, List<String> args) {
MigrationLogger log = new MigrationLogger("PowerfulPerms"); ProgressLogger log = new ProgressLogger("PowerfulPerms");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);
@ -421,7 +421,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
private void applyPerm(PermissionHolder holder, Permission p, MigrationLogger log) { private void applyPerm(PermissionHolder holder, Permission p, ProgressLogger log) {
String node = p.getPermissionString(); String node = p.getPermissionString();
boolean value = true; boolean value = true;
if (node.startsWith("!")) { if (node.startsWith("!")) {

View File

@ -25,7 +25,6 @@ package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory; import me.lucko.luckperms.common.core.NodeFactory;
@ -35,6 +34,7 @@ import me.lucko.luckperms.common.core.model.Track;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -58,7 +58,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("PermissionManager"); ProgressLogger log = new ProgressLogger("PermissionManager");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);

View File

@ -26,11 +26,11 @@ import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import net.alpenblock.bungeeperms.BungeePerms; import net.alpenblock.bungeeperms.BungeePerms;
import net.alpenblock.bungeeperms.Group; import net.alpenblock.bungeeperms.Group;
@ -49,7 +49,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("BungeePerms"); ProgressLogger log = new ProgressLogger("BungeePerms");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);

View File

@ -29,12 +29,14 @@ import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.Track;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.Storage;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -44,7 +46,7 @@ import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.concurrent.atomic.AtomicInteger;
public class ExportCommand extends SingleCommand { public class ExportCommand extends SingleCommand {
private static void write(BufferedWriter writer, String s) { private static void write(BufferedWriter writer, String s) {
@ -56,50 +58,6 @@ public class ExportCommand extends SingleCommand {
} }
} }
public static String nodeToString(Node node, String id, boolean group) {
StringBuilder sb = new StringBuilder();
sb.append("/luckperms ").append(group ? "group " : "user ").append(id).append(" ");
if (node.isGroupNode()) {
if (node.isTemporary()) {
sb.append("parent addtemp ");
sb.append(node.getGroupName());
sb.append(" ").append(node.getExpiryUnixTime());
} else {
sb.append("parent add ");
sb.append(node.getGroupName());
}
if (node.isWorldSpecific()) {
sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get());
} else if (node.isServerSpecific()) {
sb.append(" ").append(node.getServer().get());
}
return sb.toString();
}
sb.append(node.isTemporary() ? "permission settemp " : "permission set ");
if (node.getPermission().contains(" ")) {
sb.append("\"").append(node.getPermission()).append("\"");
} else {
sb.append(node.getPermission());
}
sb.append(" ").append(node.getValue());
if (node.isTemporary()) {
sb.append(" ").append(node.getExpiryUnixTime());
}
if (node.isWorldSpecific()) {
sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get());
} else if (node.isServerSpecific()) {
sb.append(" ").append(node.getServer().get());
}
return sb.toString();
}
public ExportCommand() { public ExportCommand() {
super("Export", "Export data to a file", "/%s export <file>", Permission.EXPORT, Predicates.not(1), super("Export", "Export data to a file", "/%s export <file>", Permission.EXPORT, Predicates.not(1),
Arg.list( Arg.list(
@ -110,12 +68,9 @@ public class ExportCommand extends SingleCommand {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Consumer<String> log = s -> { ProgressLogger log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
Message.EXPORT_LOG.send(sender, s); log.addListener(plugin.getConsoleSender());
if (!sender.isConsole()) { log.addListener(sender);
Message.EXPORT_LOG.send(plugin.getConsoleSender(), s);
}
};
File f = new File(plugin.getDataDirectory(), args.get(0)); File f = new File(plugin.getDataDirectory(), args.get(0));
if (f.exists()) { if (f.exists()) {
@ -137,51 +92,50 @@ public class ExportCommand extends SingleCommand {
} }
try (FileWriter fWriter = new FileWriter(f, true); BufferedWriter writer = new BufferedWriter(fWriter)) { try (FileWriter fWriter = new FileWriter(f, true); BufferedWriter writer = new BufferedWriter(fWriter)) {
log.accept("Starting export process."); log.log("Starting.");
// Export Groups // Export Groups
log.accept("Exporting all groups."); log.log("Starting group export.");
// Create the groups first // Create the actual groups first
for (Group group : plugin.getGroupManager().getAll().values()) { for (Group group : plugin.getGroupManager().getAll().values()) {
write(writer, "/luckperms creategroup " + group.getName()); write(writer, "/luckperms creategroup " + group.getName());
} }
int groupCount = 0; AtomicInteger groupCount = new AtomicInteger(0);
for (Group group : plugin.getGroupManager().getAll().values()) { for (Group group : plugin.getGroupManager().getAll().values()) {
groupCount++;
for (Node node : group.getNodes()) { for (Node node : group.getNodes()) {
write(writer, nodeToString(node, group.getName(), true)); write(writer, NodeFactory.nodeAsCommand(node, group.getName(), true));
} }
log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet());
} }
log.accept("Exported " + groupCount + " groups."); log.log("Exported " + groupCount.get() + " groups.");
// Export tracks // Export tracks
log.accept("Exporting all tracks."); log.log("Starting track export.");
// Create the tracks first // Create the actual tracks first
for (Track track : plugin.getTrackManager().getAll().values()) { for (Track track : plugin.getTrackManager().getAll().values()) {
write(writer, "/luckperms createtrack " + track.getName()); write(writer, "/luckperms createtrack " + track.getName());
} }
int trackCount = 0; AtomicInteger trackCount = new AtomicInteger(0);
for (Track track : plugin.getTrackManager().getAll().values()) { for (Track track : plugin.getTrackManager().getAll().values()) {
trackCount++;
for (String group : track.getGroups()) { for (String group : track.getGroups()) {
write(writer, "/luckperms track " + track.getName() + " append " + group); write(writer, "/luckperms track " + track.getName() + " append " + group);
} }
log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
} }
log.accept("Exported " + trackCount + " tracks."); log.log("Exported " + trackCount.get() + " tracks.");
// Export users // Export users
log.accept("Exporting all users. Finding a list of unique users to export."); log.log("Starting user export. Finding a list of unique users to export.");
Storage ds = plugin.getStorage(); Storage ds = plugin.getStorage();
Set<UUID> users = ds.getUniqueUsers().join(); Set<UUID> users = ds.getUniqueUsers().join();
log.accept("Found " + users.size() + " unique users to export."); log.log("Found " + users.size() + " unique users to export.");
int userCount = 0; AtomicInteger userCount = new AtomicInteger(0);
for (UUID uuid : users) { for (UUID uuid : users) {
userCount++;
plugin.getStorage().loadUser(uuid, "null").join(); plugin.getStorage().loadUser(uuid, "null").join();
User user = plugin.getUserManager().get(uuid); User user = plugin.getUserManager().get(uuid);
@ -192,11 +146,11 @@ public class ExportCommand extends SingleCommand {
continue; continue;
} }
write(writer, nodeToString(node, user.getUuid().toString(), false)); write(writer, NodeFactory.nodeAsCommand(node, user.getUuid().toString(), false));
} }
if (!user.getPrimaryGroup().equalsIgnoreCase("default")) { if (!user.getPrimaryGroup().equalsIgnoreCase("default")) {
write(writer, "/luckperms user " + user.getUuid().toString() + " setprimarygroup " + user.getPrimaryGroup()); write(writer, "/luckperms user " + user.getUuid().toString() + " switchprimarygroup " + user.getPrimaryGroup());
} }
if (!inDefault) { if (!inDefault) {
@ -204,8 +158,9 @@ public class ExportCommand extends SingleCommand {
} }
plugin.getUserManager().cleanup(user); plugin.getUserManager().cleanup(user);
log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
} }
log.accept("Exported " + userCount + " users."); log.log("Exported " + userCount.get() + " users.");
try { try {
writer.flush(); writer.flush();
@ -213,7 +168,7 @@ public class ExportCommand extends SingleCommand {
e.printStackTrace(); e.printStackTrace();
} }
Message.LOG_EXPORT_SUCCESS.send(sender, f.getAbsolutePath()); log.getListeners().forEach(l -> Message.LOG_EXPORT_SUCCESS.send(l, f.getAbsolutePath()));
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();

View File

@ -48,7 +48,10 @@ public enum Message {
OP_DISABLED("&bThe vanilla OP system is disabled on this server.", false), OP_DISABLED("&bThe vanilla OP system is disabled on this server.", false),
OP_DISABLED_SPONGE("&2Server Operator status has no effect when a permission plugin is installed. Please edit user data directly.", true), OP_DISABLED_SPONGE("&2Server Operator status has no effect when a permission plugin is installed. Please edit user data directly.", true),
LOG("&3LOG &3&l> {0}", true), LOG("&3LOG &3&l> {0}", true),
EXPORT_LOG("&3EXPORT &3&l> &f{0}", true), EXPORT_LOG("&3EXPORT &3&l> &f{0}", true),
EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{0}", true),
MIGRATION_LOG("&3MIGRATION &7[&3{0}&7] &3&l> &f{1}", true), MIGRATION_LOG("&3MIGRATION &7[&3{0}&7] &3&l> &f{1}", true),
MIGRATION_LOG_PROGRESS("&3MIGRATION &7[&3{0}&7] &3&l> &7{1}", true), MIGRATION_LOG_PROGRESS("&3MIGRATION &7[&3{0}&7] &3&l> &7{1}", true),

View File

@ -129,4 +129,48 @@ public class NodeFactory {
public static NodeBuilder makeSuffixNode(int priority, String suffix) { public static NodeBuilder makeSuffixNode(int priority, String suffix) {
return new NodeBuilder("suffix." + priority + "." + MetaUtils.escapeCharacters(suffix)); return new NodeBuilder("suffix." + priority + "." + MetaUtils.escapeCharacters(suffix));
} }
public static String nodeAsCommand(Node node, String id, boolean group) {
StringBuilder sb = new StringBuilder();
sb.append("/luckperms ").append(group ? "group " : "user ").append(id).append(" ");
if (node.isGroupNode()) {
if (node.isTemporary()) {
sb.append("parent addtemp ");
sb.append(node.getGroupName());
sb.append(" ").append(node.getExpiryUnixTime());
} else {
sb.append("parent add ");
sb.append(node.getGroupName());
}
if (node.isWorldSpecific()) {
sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get());
} else if (node.isServerSpecific()) {
sb.append(" ").append(node.getServer().get());
}
return sb.toString();
}
sb.append(node.isTemporary() ? "permission settemp " : "permission set ");
if (node.getPermission().contains(" ")) {
sb.append("\"").append(node.getPermission()).append("\"");
} else {
sb.append(node.getPermission());
}
sb.append(" ").append(node.getValue());
if (node.isTemporary()) {
sb.append(" ").append(node.getExpiryUnixTime());
}
if (node.isWorldSpecific()) {
sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get());
} else if (node.isServerSpecific()) {
sb.append(" ").append(node.getServer().get());
}
return sb.toString();
}
} }

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.data; package me.lucko.luckperms.common.data;
import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -34,6 +35,7 @@ import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Patterns;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -107,7 +109,11 @@ public class Importer {
executing = index; executing = index;
try { try {
CommandResult result = commandManager.onCommand(fake, "perms", Splitter.on(' ').splitToList(command)).get(); CommandResult result = commandManager.onCommand(
fake,
"lp",
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(command))
).get();
getResult(index, command).setResult(result); getResult(index, command).setResult(result);
} catch (Exception e) { } catch (Exception e) {
@ -230,14 +236,14 @@ public class Importer {
} }
} }
@Getter
@Setter
private static class Result { private static class Result {
@Getter
@Setter(AccessLevel.NONE)
private final List<String> output = new ArrayList<>(); private final List<String> output = new ArrayList<>();
@Getter
@Setter
private String command; private String command;
@Getter
@Setter
private CommandResult result = CommandResult.FAILURE; private CommandResult result = CommandResult.FAILURE;
private Result(String command) { private Result(String command) {

View File

@ -20,8 +20,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
package me.lucko.luckperms.common.commands.migration; package me.lucko.luckperms.common.utils;
import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
@ -33,26 +34,46 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
@RequiredArgsConstructor @RequiredArgsConstructor
public class MigrationLogger { public class ProgressLogger {
private static final int NOTIFY_FREQUENCY = 100; private static final int NOTIFY_FREQUENCY = 100;
private final String pluginName; private final String pluginName;
private final Message logMessage;
private final Message logProgressMessage;
@Getter
private final Set<Sender> listeners = new HashSet<>(); private final Set<Sender> listeners = new HashSet<>();
public ProgressLogger(String pluginName) {
this(pluginName, Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS);
}
public void addListener(Sender sender) { public void addListener(Sender sender) {
listeners.add(sender); listeners.add(sender);
} }
public void log(String msg) { public void log(String msg) {
listeners.forEach(s -> Message.MIGRATION_LOG.send(s, pluginName, msg)); if (pluginName == null) {
listeners.forEach(s -> logMessage.send(s, msg));
} else {
listeners.forEach(s -> logMessage.send(s, pluginName, msg));
}
} }
public void logErr(String msg) { public void logErr(String msg) {
listeners.forEach(s -> Message.MIGRATION_LOG.send(s, pluginName, "Error -> " + msg)); if (pluginName == null) {
listeners.forEach(s -> logMessage.send(s, "Error -> " + msg));
} else {
listeners.forEach(s -> logMessage.send(s, pluginName, "Error -> " + msg));
}
} }
public void logAllProgress(String msg, int amount) { public void logAllProgress(String msg, int amount) {
listeners.forEach(s -> Message.MIGRATION_LOG_PROGRESS.send(s, pluginName, msg.replace("{}", "" + amount))); if (pluginName == null) {
listeners.forEach(s -> logProgressMessage.send(s, msg.replace("{}", "" + amount)));
} else {
listeners.forEach(s -> logProgressMessage.send(s, pluginName, msg.replace("{}", "" + amount)));
}
} }
public void logProgress(String msg, int amount) { public void logProgress(String msg, int amount) {

View File

@ -58,7 +58,7 @@ class SpongeCommand extends CommandManager implements CommandCallable {
try (Timing ignored = plugin.getTimings().time(LPTiming.ON_COMMAND)) { try (Timing ignored = plugin.getTimings().time(LPTiming.ON_COMMAND)) {
onCommand( onCommand(
plugin.getSenderFactory().wrap(source), plugin.getSenderFactory().wrap(source),
"perms", "lp",
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(s)) Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(s))
); );
return CommandResult.success(); return CommandResult.success();

View File

@ -25,7 +25,6 @@ package me.lucko.luckperms.sponge.migration;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
@ -33,6 +32,7 @@ import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.LuckPermsService;
@ -58,7 +58,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("PermissionManager"); ProgressLogger log = new ProgressLogger("PermissionManager");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);

View File

@ -25,7 +25,6 @@ package me.lucko.luckperms.sponge.migration;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.migration.MigrationLogger;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
@ -34,6 +33,7 @@ import me.lucko.luckperms.common.core.model.Track;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.LuckPermsService;
@ -62,7 +62,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
MigrationLogger log = new MigrationLogger("PermissionsEx"); ProgressLogger log = new ProgressLogger("PermissionsEx");
log.addListener(plugin.getConsoleSender()); log.addListener(plugin.getConsoleSender());
log.addListener(sender); log.addListener(sender);