mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Fix import/export handling - closes #159
This commit is contained in:
parent
9cee319ed9
commit
ede413a213
@ -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<Object> {
|
||||
|
||||
@Override
|
||||
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(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
|
||||
for (Permission p : c.getPermissions()) {
|
||||
try {
|
||||
|
@ -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<Object> {
|
||||
|
||||
@Override
|
||||
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(sender);
|
||||
|
||||
|
@ -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<Object> {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
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(sender);
|
||||
|
||||
|
@ -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<Object> {
|
||||
}
|
||||
|
||||
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(sender);
|
||||
|
||||
@ -421,7 +421,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
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("!")) {
|
||||
|
@ -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<Object> {
|
||||
|
||||
@Override
|
||||
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(sender);
|
||||
|
||||
|
@ -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<Object> {
|
||||
|
||||
@Override
|
||||
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(sender);
|
||||
|
||||
|
@ -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 <file>", 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<String> args, String label) {
|
||||
Consumer<String> 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<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) {
|
||||
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();
|
||||
|
@ -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),
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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<String> output = new ArrayList<>();
|
||||
@Getter
|
||||
@Setter
|
||||
|
||||
private String command;
|
||||
@Getter
|
||||
@Setter
|
||||
private CommandResult result = CommandResult.FAILURE;
|
||||
|
||||
private Result(String command) {
|
||||
|
@ -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<Sender> 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) {
|
@ -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();
|
||||
|
@ -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<Object> {
|
||||
|
||||
@Override
|
||||
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(sender);
|
||||
|
||||
|
@ -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<Object> {
|
||||
|
||||
@Override
|
||||
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(sender);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user