mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Add logging for the migration processes
This commit is contained in:
parent
9cd4e01d8e
commit
e89444141b
@ -28,7 +28,9 @@ import me.lucko.luckperms.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.commands.Predicate;
|
import me.lucko.luckperms.commands.Predicate;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.commands.SubCommand;
|
import me.lucko.luckperms.commands.SubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Constants;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.data.LogEntry;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||||
import net.alpenblock.bungeeperms.*;
|
import net.alpenblock.bungeeperms.*;
|
||||||
@ -55,103 +57,90 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate all users.
|
|
||||||
log.info("BungeePerms Migration: Starting user migration.");
|
|
||||||
int userCount = 0;
|
|
||||||
for (User u : bp.getPermissionsManager().getBackEnd().loadUsers()) {
|
|
||||||
if (u.getUUID() == null) continue;
|
|
||||||
|
|
||||||
userCount++;
|
|
||||||
plugin.getDatastore().loadOrCreateUser(u.getUUID(), "null");
|
|
||||||
me.lucko.luckperms.users.User user = plugin.getUserManager().get(u.getUUID());
|
|
||||||
|
|
||||||
for (String perm : u.getPerms()) {
|
|
||||||
try {
|
|
||||||
user.setPermission(perm, true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, Server> e : u.getServers().entrySet()) {
|
|
||||||
for (String perm : e.getValue().getPerms()) {
|
|
||||||
try {
|
|
||||||
user.setPermission(perm, true, e.getKey());
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
|
|
||||||
for (String perm : we.getValue().getPerms()) {
|
|
||||||
try {
|
|
||||||
user.setPermission(perm, true, e.getKey(), we.getKey());
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String group : u.getGroupsString()) {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + group, true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
String prefix = u.getPrefix();
|
|
||||||
String suffix = u.getSuffix();
|
|
||||||
|
|
||||||
if (prefix != null && !prefix.equals("")) {
|
|
||||||
prefix = ArgumentChecker.escapeCharacters(prefix);
|
|
||||||
try {
|
|
||||||
user.setPermission("prefix.100." + prefix, true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
|
||||||
suffix = ArgumentChecker.escapeCharacters(suffix);
|
|
||||||
try {
|
|
||||||
user.setPermission("suffix.100." + suffix, true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getDatastore().saveUser(user);
|
|
||||||
plugin.getUserManager().cleanup(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("BungeePerms Migration: Migrated " + userCount + " users.");
|
|
||||||
|
|
||||||
// Migrate all groups.
|
// Migrate all groups.
|
||||||
log.info("BungeePerms Migration: Starting group migration.");
|
log.info("BungeePerms Migration: Starting group migration.");
|
||||||
int groupCount = 0;
|
int groupCount = 0;
|
||||||
for (Group g : bp.getPermissionsManager().getBackEnd().loadGroups()) {
|
for (Group g : bp.getPermissionsManager().getBackEnd().loadGroups()) {
|
||||||
groupCount ++;
|
groupCount ++;
|
||||||
|
|
||||||
|
// Make a LuckPerms group for the one being migrated
|
||||||
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
||||||
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Migrate global perms
|
||||||
for (String perm : g.getPerms()) {
|
for (String perm : g.getPerms()) {
|
||||||
try {
|
try {
|
||||||
group.setPermission(perm, true);
|
group.setPermission(perm, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + perm + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate per-server perms
|
||||||
for (Map.Entry<String, Server> e : g.getServers().entrySet()) {
|
for (Map.Entry<String, Server> e : g.getServers().entrySet()) {
|
||||||
for (String perm : e.getValue().getPerms()) {
|
for (String perm : e.getValue().getPerms()) {
|
||||||
try {
|
try {
|
||||||
group.setPermission(perm, true, e.getKey());
|
group.setPermission(perm, true, e.getKey());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + perm + " true " + e.getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate per-world perms
|
||||||
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
|
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
|
||||||
for (String perm : we.getValue().getPerms()) {
|
for (String perm : we.getValue().getPerms()) {
|
||||||
try {
|
try {
|
||||||
group.setPermission(perm, true, e.getKey(), we.getKey());
|
group.setPermission(perm, true, e.getKey(), we.getKey());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + perm + " true " + e.getKey() + " " + we.getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate any parent groups
|
||||||
for (String inherit : g.getInheritances()) {
|
for (String inherit : g.getInheritances()) {
|
||||||
try {
|
try {
|
||||||
group.setPermission("group." + inherit, true);
|
group.setPermission("group." + inherit, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("setinherit " + group)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate prefix and suffix
|
||||||
String prefix = g.getPrefix();
|
String prefix = g.getPrefix();
|
||||||
String suffix = g.getSuffix();
|
String suffix = g.getSuffix();
|
||||||
|
|
||||||
@ -159,22 +148,152 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
prefix = ArgumentChecker.escapeCharacters(prefix);
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
try {
|
try {
|
||||||
group.setPermission("prefix.50." + prefix, true);
|
group.setPermission("prefix.50." + prefix, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set prefix.50." + prefix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
if (suffix != null && !suffix.equals("")) {
|
||||||
suffix = ArgumentChecker.escapeCharacters(suffix);
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
try {
|
try {
|
||||||
group.setPermission("suffix.50." + suffix, true);
|
group.setPermission("suffix.50." + suffix, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set suffix.50." + suffix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
plugin.getDatastore().saveGroup(group);
|
plugin.getDatastore().saveGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("BungeePerms Migration: Migrated " + groupCount + " groups");
|
log.info("BungeePerms Migration: Migrated " + groupCount + " groups");
|
||||||
|
|
||||||
|
// Migrate all users.
|
||||||
|
log.info("BungeePerms Migration: Starting user migration.");
|
||||||
|
int userCount = 0;
|
||||||
|
for (User u : bp.getPermissionsManager().getBackEnd().loadUsers()) {
|
||||||
|
if (u.getUUID() == null) continue;
|
||||||
|
|
||||||
|
userCount++;
|
||||||
|
|
||||||
|
// Make a LuckPerms user for the one being migrated.
|
||||||
|
plugin.getDatastore().loadOrCreateUser(u.getUUID(), "null");
|
||||||
|
me.lucko.luckperms.users.User user = plugin.getUserManager().get(u.getUUID());
|
||||||
|
|
||||||
|
// Migrate global perms
|
||||||
|
for (String perm : u.getPerms()) {
|
||||||
|
try {
|
||||||
|
user.setPermission(perm, true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set " + perm + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate per-server perms
|
||||||
|
for (Map.Entry<String, Server> e : u.getServers().entrySet()) {
|
||||||
|
for (String perm : e.getValue().getPerms()) {
|
||||||
|
try {
|
||||||
|
user.setPermission(perm, true, e.getKey());
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set " + perm + " true " + e.getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate per-world perms
|
||||||
|
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
|
||||||
|
for (String perm : we.getValue().getPerms()) {
|
||||||
|
try {
|
||||||
|
user.setPermission(perm, true, e.getKey(), we.getKey());
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set " + perm + " true " + e.getKey() + " " + we.getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate groups
|
||||||
|
for (String group : u.getGroupsString()) {
|
||||||
|
try {
|
||||||
|
user.setPermission("group." + group, true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + group)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate prefix & suffix
|
||||||
|
String prefix = u.getPrefix();
|
||||||
|
String suffix = u.getSuffix();
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
user.setPermission("prefix.100." + prefix, true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set prefix.100." + prefix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
user.setPermission("suffix.100." + suffix, true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set suffix.100." + suffix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().saveUser(user);
|
||||||
|
plugin.getUserManager().cleanup(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("BungeePerms Migration: Migrated " + userCount + " users.");
|
||||||
log.info("BungeePerms Migration: Success! Completed without any errors.");
|
log.info("BungeePerms Migration: Success! Completed without any errors.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ import me.lucko.luckperms.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.commands.Predicate;
|
import me.lucko.luckperms.commands.Predicate;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.commands.SubCommand;
|
import me.lucko.luckperms.commands.SubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Constants;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.data.LogEntry;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import org.anjocaido.groupmanager.GlobalGroups;
|
import org.anjocaido.groupmanager.GlobalGroups;
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
@ -38,10 +40,7 @@ import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
|||||||
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MigrationGroupManager extends SubCommand<Object> {
|
public class MigrationGroupManager extends SubCommand<Object> {
|
||||||
@ -78,29 +77,56 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
for (Group g : gg.getGroupList()) {
|
for (Group g : gg.getGroupList()) {
|
||||||
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
||||||
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
for (String node : g.getPermissionList()) {
|
for (String node : g.getPermissionList()) {
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
if (node.startsWith("!")) {
|
if (node.startsWith("!") || node.startsWith("-")) {
|
||||||
node = node.substring(1);
|
node = node.substring(1);
|
||||||
value = false;
|
value = false;
|
||||||
|
} else if (node.startsWith("+")) {
|
||||||
|
node = node.substring(1);
|
||||||
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
group.setPermission(node, value);
|
group.setPermission(node, value);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + node + " " + value)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : g.getInherits()) {
|
for (String s : g.getInherits()) {
|
||||||
try {
|
try {
|
||||||
group.setPermission("group." + s.toLowerCase(), true);
|
group.setPermission("group." + s.toLowerCase(), true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("setinherit " + s.toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<UUID, Map<String, Boolean>> users = new HashMap<>();
|
Map<UUID, Map<Map.Entry<String, String>, Boolean>> users = new HashMap<>();
|
||||||
Map<String, Map<String, Boolean>> groups = new HashMap<>();
|
Map<String, Map<Map.Entry<String, String>, Boolean>> groups = new HashMap<>();
|
||||||
|
|
||||||
WorldsHolder wh;
|
WorldsHolder wh;
|
||||||
try {
|
try {
|
||||||
@ -129,16 +155,19 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
for (String node : g.getPermissionList()) {
|
for (String node : g.getPermissionList()) {
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
if (node.startsWith("!")) {
|
if (node.startsWith("!") || node.startsWith("-")) {
|
||||||
node = node.substring(1);
|
node = node.substring(1);
|
||||||
value = false;
|
value = false;
|
||||||
|
} else if (node.startsWith("+")) {
|
||||||
|
node = node.substring(1);
|
||||||
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.get(g.getName().toLowerCase()).put("global-" + world + "/" + node, value);
|
groups.get(g.getName().toLowerCase()).put(new AbstractMap.SimpleEntry<>(world, node), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : g.getInherits()) {
|
for (String s : g.getInherits()) {
|
||||||
groups.get(g.getName().toLowerCase()).put("global-" + world + "/group." + s.toLowerCase(), true);
|
groups.get(g.getName().toLowerCase()).put(new AbstractMap.SimpleEntry<>(world, "group." + s.toLowerCase()), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,15 +183,18 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
for (String node : user.getPermissionList()) {
|
for (String node : user.getPermissionList()) {
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
if (node.startsWith("!")) {
|
if (node.startsWith("!") || node.startsWith("-")) {
|
||||||
node = node.substring(1);
|
node = node.substring(1);
|
||||||
value = false;
|
value = false;
|
||||||
|
} else if (node.startsWith("+")) {
|
||||||
|
node = node.substring(1);
|
||||||
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
users.get(uuid).put("global-" + world + "/" + node, value);
|
users.get(uuid).put(new AbstractMap.SimpleEntry<>(world, node), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
users.get(uuid).put("global-" + world + "/group." + user.getGroupName().toLowerCase(), true);
|
users.get(uuid).put(new AbstractMap.SimpleEntry<>(world, "group." + user.getGroupName().toLowerCase()), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -170,33 +202,84 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
|
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
|
||||||
log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
||||||
|
|
||||||
for (Map.Entry<UUID, Map<String, Boolean>> e : users.entrySet()) {
|
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) {
|
||||||
|
plugin.getDatastore().createAndLoadGroup(e.getKey());
|
||||||
|
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(e.getKey());
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
||||||
|
// n.key.key = world
|
||||||
|
// n.key.value = node
|
||||||
|
// n.value = true/false
|
||||||
|
try {
|
||||||
|
group.setPermission("global-" + n.getKey().getKey() + "/" + n.getKey().getValue(), n.getValue());
|
||||||
|
|
||||||
|
if (n.getKey().getValue().startsWith("group.")) {
|
||||||
|
String groupName = n.getKey().getValue().substring(6);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("setinherit " + groupName + " global " + n.getKey().getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} else {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + n.getKey().getValue() + " " + n.getValue() + " global " + n.getKey().getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().saveGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, Map<Map.Entry<String, String>, Boolean>> e : users.entrySet()) {
|
||||||
plugin.getDatastore().loadOrCreateUser(e.getKey(), "null");
|
plugin.getDatastore().loadOrCreateUser(e.getKey(), "null");
|
||||||
me.lucko.luckperms.users.User user = plugin.getUserManager().get(e.getKey());
|
me.lucko.luckperms.users.User user = plugin.getUserManager().get(e.getKey());
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> n : e.getValue().entrySet()) {
|
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
||||||
|
// n.key.key = world
|
||||||
|
// n.key.value = node
|
||||||
|
// n.value = true/false
|
||||||
try {
|
try {
|
||||||
user.setPermission(n.getKey(), n.getValue());
|
user.setPermission("global-" + n.getKey().getKey() + "/" + n.getKey().getValue(), n.getValue());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
|
if (n.getKey().getValue().startsWith("group.")) {
|
||||||
|
String group = n.getKey().getValue().substring(6);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + group + " global " + n.getKey().getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} else {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set " + n.getKey().getValue() + " " + n.getValue() + " global " + n.getKey().getKey())
|
||||||
|
.build().submit(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getDatastore().saveUser(user);
|
plugin.getDatastore().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Boolean>> e : groups.entrySet()) {
|
|
||||||
plugin.getDatastore().createAndLoadGroup(e.getKey());
|
|
||||||
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(e.getKey());
|
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> n : e.getValue().entrySet()) {
|
|
||||||
try {
|
|
||||||
group.setPermission(n.getKey(), n.getValue());
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getDatastore().saveGroup(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("GroupManager Migration: Success! Completed without any errors.");
|
log.info("GroupManager Migration: Success! Completed without any errors.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ import me.lucko.luckperms.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.commands.Predicate;
|
import me.lucko.luckperms.commands.Predicate;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.commands.SubCommand;
|
import me.lucko.luckperms.commands.SubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Constants;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.data.LogEntry;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
@ -119,6 +121,140 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
return CommandResult.FAILURE;
|
return CommandResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate all groups.
|
||||||
|
log.info("PermissionsEx Migration: Starting group migration.");
|
||||||
|
int groupCount = 0;
|
||||||
|
for (PermissionGroup group : manager.getGroupList()) {
|
||||||
|
groupCount ++;
|
||||||
|
final String name = group.getName().toLowerCase();
|
||||||
|
plugin.getDatastore().createAndLoadGroup(name);
|
||||||
|
Group lpGroup = plugin.getGroupManager().get(name);
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (String node : group.getOwnPermissions(null)) {
|
||||||
|
boolean value = true;
|
||||||
|
if (node.startsWith("!")) {
|
||||||
|
node = node.substring(1);
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission(node, value);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("set " + node + " " + value)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
|
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worlds != null && !worlds.isEmpty()) {
|
||||||
|
for (String world : worlds) {
|
||||||
|
for (String node : group.getOwnPermissions(world)) {
|
||||||
|
boolean value = true;
|
||||||
|
if (node.startsWith("!")) {
|
||||||
|
node = node.substring(1);
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission(node, value, "global", world);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("set " + node + " " + value + " global " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PermissionGroup g : group.getParents()) {
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission("group." + g.getName().toLowerCase(), true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("setinherit " + g.getName().toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worlds != null && !worlds.isEmpty()) {
|
||||||
|
for (String world : worlds) {
|
||||||
|
for (PermissionGroup g : group.getParents(world)) {
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission("group." + g.getName().toLowerCase(), true, "global", world);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("setinherit " + g.getName().toLowerCase() + " global " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String prefix = group.getOwnPrefix();
|
||||||
|
String suffix = group.getOwnSuffix();
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission("prefix.50." + prefix, true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("set prefix.50." + prefix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission("suffix.50." + suffix, true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpGroup).action("set suffix.50." + suffix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("PermissionsEx Migration: Migrated " + groupCount + " groups");
|
||||||
|
|
||||||
// Migrate all users
|
// Migrate all users
|
||||||
log.info("PermissionsEx Migration: Starting user migration.");
|
log.info("PermissionsEx Migration: Starting user migration.");
|
||||||
int userCount = 0;
|
int userCount = 0;
|
||||||
@ -163,7 +299,15 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission(node, value);
|
lpUser.setPermission(node, value);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpUser).action("set " + node + " " + value)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
||||||
@ -180,7 +324,15 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission(node, value, "global", world);
|
lpUser.setPermission(node, value, "global", world);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpUser).action("set " + node + " " + value + " global " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +340,15 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
for (String s : user.getGroupNames()) {
|
for (String s : user.getGroupNames()) {
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("group." + s.toLowerCase(), true);
|
lpUser.setPermission("group." + s.toLowerCase(), true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpUser).action("addgroup " + s.toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
if (worlds != null && !worlds.isEmpty()) {
|
||||||
@ -196,7 +356,15 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
for (String s : user.getGroupNames(world)) {
|
for (String s : user.getGroupNames(world)) {
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("group." + s.toLowerCase(), true, "global", world);
|
lpUser.setPermission("group." + s.toLowerCase(), true, "global", world);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpUser).action("addgroup " + s.toLowerCase() + " global " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,14 +376,30 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
prefix = ArgumentChecker.escapeCharacters(prefix);
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("prefix.100." + prefix, true);
|
lpUser.setPermission("prefix.100." + prefix, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpUser).action("set prefix.100." + prefix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
if (suffix != null && !suffix.equals("")) {
|
||||||
suffix = ArgumentChecker.escapeCharacters(suffix);
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("suffix.100." + suffix, true);
|
lpUser.setPermission("suffix.100." + suffix, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(lpUser).action("set suffix.100." + suffix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(lpUser);
|
plugin.getUserManager().cleanup(lpUser);
|
||||||
@ -223,84 +407,6 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("PermissionsEx Migration: Migrated " + userCount + " users.");
|
log.info("PermissionsEx Migration: Migrated " + userCount + " users.");
|
||||||
|
|
||||||
// Migrate all groups.
|
|
||||||
log.info("PermissionsEx Migration: Starting group migration.");
|
|
||||||
int groupCount = 0;
|
|
||||||
for (PermissionGroup group : manager.getGroupList()) {
|
|
||||||
groupCount ++;
|
|
||||||
final String name = group.getName().toLowerCase();
|
|
||||||
plugin.getDatastore().createAndLoadGroup(name);
|
|
||||||
Group lpGroup = plugin.getGroupManager().get(name);
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (String node : group.getOwnPermissions(null)) {
|
|
||||||
boolean value = true;
|
|
||||||
if (node.startsWith("!")) {
|
|
||||||
node = node.substring(1);
|
|
||||||
value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
lpGroup.setPermission(node, value);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
|
||||||
for (String world : worlds) {
|
|
||||||
for (String node : group.getOwnPermissions(world)) {
|
|
||||||
boolean value = true;
|
|
||||||
if (node.startsWith("!")) {
|
|
||||||
node = node.substring(1);
|
|
||||||
value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
lpGroup.setPermission(node, value, "global", world);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PermissionGroup g : group.getParents()) {
|
|
||||||
try {
|
|
||||||
lpGroup.setPermission("group." + g.getName().toLowerCase(), true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
|
||||||
for (String world : worlds) {
|
|
||||||
for (PermissionGroup g : group.getParents(world)) {
|
|
||||||
try {
|
|
||||||
lpGroup.setPermission("group." + g.getName().toLowerCase(), true, "global", world);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String prefix = group.getOwnPrefix();
|
|
||||||
String suffix = group.getOwnSuffix();
|
|
||||||
|
|
||||||
if (prefix != null && !prefix.equals("")) {
|
|
||||||
prefix = ArgumentChecker.escapeCharacters(prefix);
|
|
||||||
try {
|
|
||||||
lpGroup.setPermission("prefix.50." + prefix, true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
|
||||||
suffix = ArgumentChecker.escapeCharacters(suffix);
|
|
||||||
try {
|
|
||||||
lpGroup.setPermission("suffix.50." + suffix, true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("PermissionsEx Migration: Migrated " + groupCount + " groups");
|
|
||||||
log.info("PermissionsEx Migration: Success! Completed without any errors.");
|
log.info("PermissionsEx Migration: Success! Completed without any errors.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,9 @@ import me.lucko.luckperms.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.commands.Predicate;
|
import me.lucko.luckperms.commands.Predicate;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.commands.SubCommand;
|
import me.lucko.luckperms.commands.SubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Constants;
|
||||||
import me.lucko.luckperms.core.PermissionHolder;
|
import me.lucko.luckperms.core.PermissionHolder;
|
||||||
|
import me.lucko.luckperms.data.LogEntry;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
|
|
||||||
@ -155,6 +157,45 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) plugin.getPlugin("PowerfulPerms");
|
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) plugin.getPlugin("PowerfulPerms");
|
||||||
PermissionManager pm = ppPlugin.getPermissionManager();
|
PermissionManager pm = ppPlugin.getPermissionManager();
|
||||||
|
|
||||||
|
// Groups first.
|
||||||
|
log.info("PowerfulPerms Migration: Starting group migration.");
|
||||||
|
Map<Integer, Group> groups = pm.getGroups();
|
||||||
|
for (Group g : groups.values()) {
|
||||||
|
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
||||||
|
final me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Permission p : g.getOwnPermissions()) {
|
||||||
|
applyPerm(group, p, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Group parent : g.getParents()) {
|
||||||
|
try {
|
||||||
|
group.setPermission("group." + parent.getName().toLowerCase(), true);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("setinherit " + parent.getName().toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().saveGroup(group);
|
||||||
|
}
|
||||||
|
log.info("PowerfulPerms Migration: Group migration complete.");
|
||||||
|
|
||||||
|
// Now users.
|
||||||
|
log.info("PowerfulPerms Migration: Starting user migration.");
|
||||||
final Map<UUID, CountDownLatch> progress = new HashMap<>();
|
final Map<UUID, CountDownLatch> progress = new HashMap<>();
|
||||||
|
|
||||||
// Migrate all users and their groups
|
// Migrate all users and their groups
|
||||||
@ -170,7 +211,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
List<Permission> perms = this.getResult();
|
List<Permission> perms = this.getResult();
|
||||||
perms.forEach(p -> applyPerm(user, p));
|
perms.forEach(p -> applyPerm(user, p, plugin));
|
||||||
|
|
||||||
// Update the progress so the user can be saved and unloaded.
|
// Update the progress so the user can be saved and unloaded.
|
||||||
synchronized (progress) {
|
synchronized (progress) {
|
||||||
@ -216,11 +257,27 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + g.getName().toLowerCase(), true);
|
user.setPermission("group." + g.getName().toLowerCase(), true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + g.getName().toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + g.getName().toLowerCase(), true, server);
|
user.setPermission("group." + g.getName().toLowerCase(), true, server);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + g.getName().toLowerCase() + " " + server)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -233,22 +290,54 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, g.getExpirationDate().getTime() / 1000L);
|
user.setPermission("group." + group.getName().toLowerCase(), true, g.getExpirationDate().getTime() / 1000L);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addtempgroup " + group.getName().toLowerCase() + " " + g.getExpirationDate().getTime() / 1000L)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, server, g.getExpirationDate().getTime() / 1000L);
|
user.setPermission("group." + group.getName().toLowerCase(), true, server, g.getExpirationDate().getTime() / 1000L);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addtempgroup " + group.getName().toLowerCase() + " " + g.getExpirationDate().getTime() / 1000L + " " + server)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true);
|
user.setPermission("group." + group.getName().toLowerCase(), true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + group.getName().toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, server);
|
user.setPermission("group." + group.getName().toLowerCase(), true, server);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + group.getName().toLowerCase() + " " + server)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -271,33 +360,9 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user processes will run individually in separate threads.
|
// All groups are migrated, but there may still be some users being migrated.
|
||||||
// In the meantime, it's should be safe to load in the groups on this thread.
|
|
||||||
log.info("PowerfulPerms Migration: User migration is now running. Starting group migration.");
|
|
||||||
|
|
||||||
// Let's import groups. yay
|
|
||||||
Map<Integer, Group> groups = pm.getGroups();
|
|
||||||
for (Group g : groups.values()) {
|
|
||||||
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
|
||||||
final me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
|
||||||
|
|
||||||
for (Permission p : g.getOwnPermissions()) {
|
|
||||||
applyPerm(group, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Group parent : g.getParents()) {
|
|
||||||
try {
|
|
||||||
group.setPermission("group." + parent.getName().toLowerCase(), true);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getDatastore().saveGroup(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
// All groups are now migrated, but there may still be some users being migrated.
|
|
||||||
// This block will wait for all users to be completed.
|
// This block will wait for all users to be completed.
|
||||||
log.info("PowerfulPerms Migration: All groups are now migrated. Waiting for user migration to complete.");
|
log.info("PowerfulPerms Migration: Waiting for user migration to complete. This may take some time");
|
||||||
log.info("PowerfulPerms Migration: This may take some time.");
|
|
||||||
boolean sleep = true;
|
boolean sleep = true;
|
||||||
while (sleep) {
|
while (sleep) {
|
||||||
sleep = false;
|
sleep = false;
|
||||||
@ -324,7 +389,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPerm(PermissionHolder holder, Permission p) {
|
private void applyPerm(PermissionHolder holder, Permission p, LuckPermsPlugin plugin) {
|
||||||
String node = p.getPermissionString();
|
String node = p.getPermissionString();
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
if (node.startsWith("!")) {
|
if (node.startsWith("!")) {
|
||||||
@ -357,14 +422,26 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (expireAt == 0L) {
|
if (expireAt == 0L) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server, world);
|
holder.setPermission(node, value, server, world);
|
||||||
} catch (ObjectAlreadyHasException e) {
|
LogEntry.build()
|
||||||
e.printStackTrace();
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(holder).action("set " + node + " " + value + " " + server + " " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server, world, expireAt);
|
holder.setPermission(node, value, server, world, expireAt);
|
||||||
} catch (ObjectAlreadyHasException e) {
|
LogEntry.build()
|
||||||
e.printStackTrace();
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(holder).action("settemp " + node + " " + value + " " + expireAt + " " + server + " " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,21 +449,53 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (expireAt == 0L) {
|
if (expireAt == 0L) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server);
|
holder.setPermission(node, value, server);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(holder).action("set " + node + " " + value + " " + server)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server, expireAt);
|
holder.setPermission(node, value, server, expireAt);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(holder).action("settemp " + node + " " + value + " " + expireAt + " " + server)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (expireAt == 0L) {
|
if (expireAt == 0L) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value);
|
holder.setPermission(node, value);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(holder).action("set " + node + " " + value)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, expireAt);
|
holder.setPermission(node, value, expireAt);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(holder).action("settemp " + node + " " + value + " " + expireAt)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ import me.lucko.luckperms.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.commands.Predicate;
|
import me.lucko.luckperms.commands.Predicate;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.commands.SubCommand;
|
import me.lucko.luckperms.commands.SubCommand;
|
||||||
|
import me.lucko.luckperms.constants.Constants;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.data.LogEntry;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.tracks.Track;
|
import me.lucko.luckperms.tracks.Track;
|
||||||
@ -69,6 +71,84 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
.map(String::toLowerCase)
|
.map(String::toLowerCase)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// Migrate all groups
|
||||||
|
log.info("zPermissions Migration: Starting group migration.");
|
||||||
|
for (String g : service.getAllGroups()) {
|
||||||
|
plugin.getDatastore().createAndLoadGroup(g.toLowerCase());
|
||||||
|
Group group = plugin.getGroupManager().get(g.toLowerCase());
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, Boolean> e : service.getGroupPermissions(null, null, g).entrySet()) {
|
||||||
|
try {
|
||||||
|
group.setPermission(e.getKey(), e.getValue());
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + e.getKey() + " " + e.getValue())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (worlds != null && !worlds.isEmpty()) {
|
||||||
|
for (String world : worlds) {
|
||||||
|
for (Map.Entry<String, Boolean> e : service.getGroupPermissions(world, null, g).entrySet()) {
|
||||||
|
try {
|
||||||
|
group.setPermission(e.getKey(), e.getValue(), "global", world);
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(group).action("set " + e.getKey() + " true " + e.getValue() + " " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().saveGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate all tracks
|
||||||
|
log.info("zPermissions Migration: Starting track migration.");
|
||||||
|
for (String t : service.getAllTracks()) {
|
||||||
|
plugin.getDatastore().createAndLoadTrack(t.toLowerCase());
|
||||||
|
Track track = plugin.getTrackManager().get(t.toLowerCase());
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(track).action("create")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
track.setGroups(service.getTrackGroups(t));
|
||||||
|
for (String group : track.getGroups()) {
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(track).action("append " + group)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getDatastore().saveTrack(track);
|
||||||
|
}
|
||||||
|
|
||||||
// Migrate all users.
|
// Migrate all users.
|
||||||
log.info("zPermissions Migration: Starting user migration.");
|
log.info("zPermissions Migration: Starting user migration.");
|
||||||
for (UUID u : service.getAllPlayersUUID()) {
|
for (UUID u : service.getAllPlayersUUID()) {
|
||||||
@ -78,7 +158,15 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(null, null, u).entrySet()) {
|
for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(null, null, u).entrySet()) {
|
||||||
try {
|
try {
|
||||||
user.setPermission(e.getKey(), e.getValue());
|
user.setPermission(e.getKey(), e.getValue());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set " + e.getKey() + " " + e.getValue())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
if (worlds != null && !worlds.isEmpty()) {
|
||||||
@ -86,7 +174,15 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(world, null, u).entrySet()) {
|
for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(world, null, u).entrySet()) {
|
||||||
try {
|
try {
|
||||||
user.setPermission(e.getKey(), e.getValue(), "global", world);
|
user.setPermission(e.getKey(), e.getValue(), "global", world);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set " + e.getKey() + " true " + e.getValue() + " " + world)
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,10 +190,26 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
for (String g : service.getPlayerAssignedGroups(u)) {
|
for (String g : service.getPlayerAssignedGroups(u)) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + g.toLowerCase(), true);
|
user.setPermission("group." + g.toLowerCase(), true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("addgroup " + g.toLowerCase())
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
||||||
|
try {
|
||||||
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("setprimarygroup " + service.getPlayerPrimaryGroup(u))
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
String prefix = service.getPlayerPrefix(u);
|
String prefix = service.getPlayerPrefix(u);
|
||||||
String suffix = service.getPlayerSuffix(u);
|
String suffix = service.getPlayerSuffix(u);
|
||||||
@ -106,56 +218,36 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
prefix = ArgumentChecker.escapeCharacters(prefix);
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
try {
|
try {
|
||||||
user.setPermission("prefix.100." + prefix, true);
|
user.setPermission("prefix.100." + prefix, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set prefix.100." + prefix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
if (suffix != null && !suffix.equals("")) {
|
||||||
suffix = ArgumentChecker.escapeCharacters(suffix);
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
try {
|
try {
|
||||||
user.setPermission("suffix.100." + suffix, true);
|
user.setPermission("suffix.100." + suffix, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
LogEntry.build()
|
||||||
|
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
||||||
|
.acted(user).action("set suffix.100." + suffix + " true")
|
||||||
|
.build().submit(plugin);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof ObjectAlreadyHasException)) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
plugin.getDatastore().saveUser(user);
|
plugin.getDatastore().saveUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate all tracks
|
|
||||||
log.info("zPermissions Migration: Starting track migration.");
|
|
||||||
for (String t : service.getAllTracks()) {
|
|
||||||
plugin.getDatastore().createAndLoadTrack(t.toLowerCase());
|
|
||||||
Track track = plugin.getTrackManager().get(t.toLowerCase());
|
|
||||||
|
|
||||||
track.setGroups(service.getTrackGroups(t));
|
|
||||||
|
|
||||||
plugin.getDatastore().saveTrack(track);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate all groups
|
|
||||||
log.info("zPermissions Migration: Starting group migration.");
|
|
||||||
for (String g : service.getAllGroups()) {
|
|
||||||
plugin.getDatastore().createAndLoadGroup(g.toLowerCase());
|
|
||||||
Group group = plugin.getGroupManager().get(g.toLowerCase());
|
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> e : service.getGroupPermissions(null, null, g).entrySet()) {
|
|
||||||
try {
|
|
||||||
group.setPermission(e.getKey(), e.getValue());
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
|
||||||
for (String world : worlds) {
|
|
||||||
for (Map.Entry<String, Boolean> e : service.getGroupPermissions(world, null, g).entrySet()) {
|
|
||||||
try {
|
|
||||||
group.setPermission(e.getKey(), e.getValue(), "global", world);
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getDatastore().saveGroup(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("zPermissions Migration: Success! Completed without any errors.");
|
log.info("zPermissions Migration: Success! Completed without any errors.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void submit(LuckPermsPlugin plugin) {
|
||||||
|
submit(plugin, null);
|
||||||
|
}
|
||||||
|
|
||||||
public void submit(LuckPermsPlugin plugin, Sender sender) {
|
public void submit(LuckPermsPlugin plugin, Sender sender) {
|
||||||
plugin.getDatastore().logAction(this);
|
plugin.getDatastore().logAction(this);
|
||||||
|
|
||||||
@ -58,11 +62,17 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
senders.add(plugin.getConsoleSender());
|
senders.add(plugin.getConsoleSender());
|
||||||
|
|
||||||
|
if (sender == null) {
|
||||||
|
senders.stream()
|
||||||
|
.filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid()))
|
||||||
|
.forEach(s -> Message.LOG.send(s, msg));
|
||||||
|
} else {
|
||||||
senders.stream()
|
senders.stream()
|
||||||
.filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid()))
|
.filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid()))
|
||||||
.filter(s -> !s.getUuid().equals(sender.getUuid()))
|
.filter(s -> !s.getUuid().equals(sender.getUuid()))
|
||||||
.forEach(s -> Message.LOG.send(s, msg));
|
.forEach(s -> Message.LOG.send(s, msg));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class LogEntryBuilder extends AbstractLogEntryBuilder<LogEntry, LogEntry.LogEntryBuilder> {
|
public static class LogEntryBuilder extends AbstractLogEntryBuilder<LogEntry, LogEntry.LogEntryBuilder> {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user