From ede413a213212004c2fef43320897f4c0e9a1a95 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 2 Feb 2017 15:13:44 +0000 Subject: [PATCH] Fix import/export handling - closes #159 --- .../migration/MigrationBPermissions.java | 6 +- .../migration/MigrationGroupManager.java | 4 +- .../migration/MigrationPermissionsEx.java | 4 +- .../migration/MigrationPowerfulPerms.java | 6 +- .../migration/MigrationZPermissions.java | 4 +- .../migration/MigrationBungeePerms.java | 4 +- .../common/commands/misc/ExportCommand.java | 97 +++++-------------- .../luckperms/common/constants/Message.java | 3 + .../luckperms/common/core/NodeFactory.java | 44 +++++++++ .../lucko/luckperms/common/data/Importer.java | 18 ++-- .../ProgressLogger.java} | 31 +++++- .../lucko/luckperms/sponge/SpongeCommand.java | 2 +- .../migration/MigrationPermissionManager.java | 4 +- .../migration/MigrationPermissionsEx.java | 4 +- 14 files changed, 130 insertions(+), 101 deletions(-) rename common/src/main/java/me/lucko/luckperms/common/{commands/migration/MigrationLogger.java => utils/ProgressLogger.java} (69%) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index d2f8ff072..6a7e47e68 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -33,12 +33,12 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -71,7 +71,7 @@ public class MigrationBPermissions extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("bPermissions"); + ProgressLogger log = new ProgressLogger("bPermissions"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); @@ -186,7 +186,7 @@ public class MigrationBPermissions extends SubCommand { } } - 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 for (Permission p : c.getPermissions()) { try { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index f4664b306..ecc11b920 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -28,11 +28,11 @@ import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.constants.Permission; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; 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.ObjectLacksException; @@ -62,7 +62,7 @@ public class MigrationGroupManager extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("GroupManager"); + ProgressLogger log = new ProgressLogger("GroupManager"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 7ab7a879c..bb737f249 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -26,13 +26,13 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; 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.ObjectLacksException; @@ -59,7 +59,7 @@ public class MigrationPermissionsEx extends SubCommand { @SuppressWarnings("deprecation") @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("PermissionsEx"); + ProgressLogger log = new ProgressLogger("PermissionsEx"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index 55ae9a477..732fd538d 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -36,12 +36,12 @@ import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import org.bukkit.Bukkit; @@ -144,7 +144,7 @@ public class MigrationPowerfulPerms extends SubCommand { } private CommandResult run(LuckPermsPlugin plugin, Sender sender, List args) { - MigrationLogger log = new MigrationLogger("PowerfulPerms"); + ProgressLogger log = new ProgressLogger("PowerfulPerms"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); @@ -421,7 +421,7 @@ public class MigrationPowerfulPerms extends SubCommand { 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(); boolean value = true; if (node.startsWith("!")) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index cb8e31bbe..6bad52a04 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.bukkit.migration; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.constants.Permission; 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.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import org.bukkit.Bukkit; @@ -58,7 +58,7 @@ public class MigrationZPermissions extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("PermissionManager"); + ProgressLogger log = new ProgressLogger("PermissionManager"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 52b4ac396..47785a34a 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -26,11 +26,11 @@ import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.constants.Permission; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import net.alpenblock.bungeeperms.BungeePerms; import net.alpenblock.bungeeperms.Group; @@ -49,7 +49,7 @@ public class MigrationBungeePerms extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("BungeePerms"); + ProgressLogger log = new ProgressLogger("BungeePerms"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); 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 c0aaa98ed..22e0faf1b 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 @@ -29,12 +29,14 @@ import me.lucko.luckperms.common.commands.SingleCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Message; 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.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import java.io.BufferedWriter; import java.io.File; @@ -44,7 +46,7 @@ import java.nio.file.Files; import java.util.List; import java.util.Set; import java.util.UUID; -import java.util.function.Consumer; +import java.util.concurrent.atomic.AtomicInteger; public class ExportCommand extends SingleCommand { 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() { super("Export", "Export data to a file", "/%s export ", Permission.EXPORT, Predicates.not(1), Arg.list( @@ -110,12 +68,9 @@ public class ExportCommand extends SingleCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - Consumer log = s -> { - Message.EXPORT_LOG.send(sender, s); - if (!sender.isConsole()) { - Message.EXPORT_LOG.send(plugin.getConsoleSender(), s); - } - }; + ProgressLogger log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS); + log.addListener(plugin.getConsoleSender()); + log.addListener(sender); File f = new File(plugin.getDataDirectory(), args.get(0)); if (f.exists()) { @@ -137,51 +92,50 @@ public class ExportCommand extends SingleCommand { } try (FileWriter fWriter = new FileWriter(f, true); BufferedWriter writer = new BufferedWriter(fWriter)) { - log.accept("Starting export process."); + log.log("Starting."); // 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()) { write(writer, "/luckperms creategroup " + group.getName()); } - int groupCount = 0; + AtomicInteger groupCount = new AtomicInteger(0); for (Group group : plugin.getGroupManager().getAll().values()) { - groupCount++; 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 - 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()) { write(writer, "/luckperms createtrack " + track.getName()); } - int trackCount = 0; + AtomicInteger trackCount = new AtomicInteger(0); for (Track track : plugin.getTrackManager().getAll().values()) { - trackCount++; for (String group : track.getGroups()) { 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 - 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(); Set 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) { - userCount++; plugin.getStorage().loadUser(uuid, "null").join(); User user = plugin.getUserManager().get(uuid); @@ -192,11 +146,11 @@ public class ExportCommand extends SingleCommand { continue; } - write(writer, nodeToString(node, user.getUuid().toString(), false)); + write(writer, NodeFactory.nodeAsCommand(node, user.getUuid().toString(), false)); } 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) { @@ -204,8 +158,9 @@ public class ExportCommand extends SingleCommand { } plugin.getUserManager().cleanup(user); + log.logProgress("Exported {} users so far.", userCount.incrementAndGet()); } - log.accept("Exported " + userCount + " users."); + log.log("Exported " + userCount.get() + " users."); try { writer.flush(); @@ -213,7 +168,7 @@ public class ExportCommand extends SingleCommand { 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; } catch (Throwable t) { t.printStackTrace(); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 46f68f88f..99984e4f2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -48,7 +48,10 @@ public enum Message { 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), LOG("&3LOG &3&l> {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_PROGRESS("&3MIGRATION &7[&3{0}&7] &3&l> &7{1}", true), diff --git a/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java b/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java index 3c569eed6..528a0c372 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java @@ -129,4 +129,48 @@ public class NodeFactory { public static NodeBuilder makeSuffixNode(int priority, String 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(); + } } 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 b20fdc424..2cd2fef0e 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 @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.data; +import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; 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.constants.Constants; 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.plugin.LuckPermsPlugin; @@ -107,7 +109,11 @@ public class Importer { executing = index; 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); } catch (Exception e) { @@ -230,14 +236,14 @@ public class Importer { } } + @Getter + @Setter private static class Result { - @Getter + + @Setter(AccessLevel.NONE) private final List output = new ArrayList<>(); - @Getter - @Setter + private String command; - @Getter - @Setter private CommandResult result = CommandResult.FAILURE; private Result(String command) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationLogger.java b/common/src/main/java/me/lucko/luckperms/common/utils/ProgressLogger.java similarity index 69% rename from common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationLogger.java rename to common/src/main/java/me/lucko/luckperms/common/utils/ProgressLogger.java index f08996265..f5bfd5331 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ProgressLogger.java @@ -20,8 +20,9 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.commands.migration; +package me.lucko.luckperms.common.utils; +import lombok.Getter; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.common.commands.sender.Sender; @@ -33,26 +34,46 @@ import java.util.HashSet; import java.util.Set; @RequiredArgsConstructor -public class MigrationLogger { +public class ProgressLogger { private static final int NOTIFY_FREQUENCY = 100; private final String pluginName; + private final Message logMessage; + private final Message logProgressMessage; + + @Getter private final Set listeners = new HashSet<>(); + public ProgressLogger(String pluginName) { + this(pluginName, Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS); + } + public void addListener(Sender sender) { listeners.add(sender); } 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) { - 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) { - 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) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java index c83937b40..9bb9ba3b3 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java @@ -58,7 +58,7 @@ class SpongeCommand extends CommandManager implements CommandCallable { try (Timing ignored = plugin.getTimings().time(LPTiming.ON_COMMAND)) { onCommand( plugin.getSenderFactory().wrap(source), - "perms", + "lp", Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(s)) ); return CommandResult.success(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java index 9b678aad4..9d2164b8e 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.sponge.migration; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.utils.Util; 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.plugin.LuckPermsPlugin; 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.service.LuckPermsService; @@ -58,7 +58,7 @@ public class MigrationPermissionManager extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("PermissionManager"); + ProgressLogger log = new ProgressLogger("PermissionManager"); log.addListener(plugin.getConsoleSender()); log.addListener(sender); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java index 2e677840c..5cfa70bda 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.sponge.migration; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; 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.utils.Util; 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.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.common.utils.ProgressLogger; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.service.LuckPermsService; @@ -62,7 +62,7 @@ public class MigrationPermissionsEx extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - MigrationLogger log = new MigrationLogger("PermissionsEx"); + ProgressLogger log = new ProgressLogger("PermissionsEx"); log.addListener(plugin.getConsoleSender()); log.addListener(sender);