Catch and ignore exceptions thrown when migrating a specific entity
This commit is contained in:
parent
e71ef834c0
commit
211fb219a7
@ -47,6 +47,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -124,13 +125,14 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Migrate one world at a time.
|
// Migrate one world at a time.
|
||||||
log.log("Starting world migration.");
|
log.log("Starting world migration.");
|
||||||
for (World world : worldManager.getAllWorlds()) {
|
SafeIterator.iterate(worldManager.getAllWorlds(), world -> {
|
||||||
log.log("Migrating world: " + world.getName());
|
log.log("Migrating world: " + world.getName());
|
||||||
|
|
||||||
// Migrate all groups
|
// Migrate all groups
|
||||||
log.log("Starting group migration in world " + world.getName() + ".");
|
log.log("Starting group migration in world " + world.getName() + ".");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Calculable group : world.getAll(CalculableType.GROUP)) {
|
|
||||||
|
SafeIterator.iterate(world.getAll(CalculableType.GROUP), group -> {
|
||||||
String groupName = MigrationUtils.standardizeName(group.getName());
|
String groupName = MigrationUtils.standardizeName(group.getName());
|
||||||
if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) {
|
if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) {
|
||||||
groupName = "default";
|
groupName = "default";
|
||||||
@ -146,18 +148,18 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
plugin.getStorage().saveGroup(lpGroup);
|
plugin.getStorage().saveGroup(lpGroup);
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups in world " + world.getName() + ".");
|
log.log("Migrated " + groupCount.get() + " groups in world " + world.getName() + ".");
|
||||||
|
|
||||||
|
|
||||||
// Migrate all users
|
// Migrate all users
|
||||||
log.log("Starting user migration in world " + world.getName() + ".");
|
log.log("Starting user migration in world " + world.getName() + ".");
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
for (Calculable user : world.getAll(CalculableType.USER)) {
|
SafeIterator.iterate(world.getAll(CalculableType.USER), user -> {
|
||||||
// There is no mention of UUIDs in the API. I assume that name = uuid. idk?
|
// There is no mention of UUIDs in the API. I assume that name = uuid. idk?
|
||||||
UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getName());
|
UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getName());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a LuckPerms user for the one being migrated.
|
// Make a LuckPerms user for the one being migrated.
|
||||||
@ -170,10 +172,10 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
plugin.getUserManager().cleanup(lpUser);
|
plugin.getUserManager().cleanup(lpUser);
|
||||||
|
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users in world " + world.getName() + ".");
|
log.log("Migrated " + userCount.get() + " users in world " + world.getName() + ".");
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -40,11 +40,10 @@ import me.lucko.luckperms.common.logging.ProgressLogger;
|
|||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.GlobalGroups;
|
import org.anjocaido.groupmanager.GlobalGroups;
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
import org.anjocaido.groupmanager.data.Group;
|
|
||||||
import org.anjocaido.groupmanager.data.User;
|
|
||||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||||
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -93,31 +92,24 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
GlobalGroups gg = GroupManager.getGlobalGroups();
|
GlobalGroups gg = GroupManager.getGlobalGroups();
|
||||||
|
|
||||||
AtomicInteger globalGroupCount = new AtomicInteger(0);
|
AtomicInteger globalGroupCount = new AtomicInteger(0);
|
||||||
for (Group g : gg.getGroupList()) {
|
SafeIterator.iterate(gg.getGroupList(), g -> {
|
||||||
String groupName = MigrationUtils.standardizeName(g.getName());
|
String groupName = MigrationUtils.standardizeName(g.getName());
|
||||||
|
|
||||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||||
me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||||
|
|
||||||
for (String node : g.getPermissionList()) {
|
for (String node : g.getPermissionList()) {
|
||||||
if (node.isEmpty()) {
|
if (node.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
group.setPermission(MigrationUtils.parseNode(node, true).build());
|
group.setPermission(MigrationUtils.parseNode(node, true).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : g.getInherits()) {
|
for (String s : g.getInherits()) {
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
group.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(s)));
|
group.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
log.logAllProgress("Migrated {} groups so far.", globalGroupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", globalGroupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + globalGroupCount.get() + " global groups");
|
log.log("Migrated " + globalGroupCount.get() + " global groups");
|
||||||
|
|
||||||
// Collect data
|
// Collect data
|
||||||
@ -129,47 +121,32 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Collect data for all users and groups.
|
// Collect data for all users and groups.
|
||||||
log.log("Collecting user and group data.");
|
log.log("Collecting user and group data.");
|
||||||
for (String world : worlds) {
|
SafeIterator.iterate(worlds, String::toLowerCase, world -> {
|
||||||
world = world.toLowerCase();
|
|
||||||
log.log("Querying world " + world);
|
log.log("Querying world " + world);
|
||||||
|
|
||||||
WorldDataHolder wdh = wh.getWorldData(world);
|
WorldDataHolder wdh = wh.getWorldData(world);
|
||||||
|
|
||||||
AtomicInteger groupWorldCount = new AtomicInteger(0);
|
AtomicInteger groupWorldCount = new AtomicInteger(0);
|
||||||
for (Group group : wdh.getGroupList()) {
|
SafeIterator.iterate(wdh.getGroupList(), group -> {
|
||||||
String groupName = MigrationUtils.standardizeName(group.getName());
|
String groupName = MigrationUtils.standardizeName(group.getName());
|
||||||
|
|
||||||
groups.putIfAbsent(groupName, new HashSet<>());
|
groups.putIfAbsent(groupName, new HashSet<>());
|
||||||
|
|
||||||
for (String node : group.getPermissionList()) {
|
for (String node : group.getPermissionList()) {
|
||||||
if (node.isEmpty()) {
|
if (node.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
groups.get(groupName).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
|
groups.get(groupName).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : group.getInherits()) {
|
for (String s : group.getInherits()) {
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
groups.get(groupName).add(NodeFactory.make("group." + MigrationUtils.standardizeName(s), true, null, worldMappingFunc.apply(world)));
|
groups.get(groupName).add(NodeFactory.make("group." + MigrationUtils.standardizeName(s), true, null, worldMappingFunc.apply(world)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String[] metaKeys = group.getVariables().getVarKeyList();
|
String[] metaKeys = group.getVariables().getVarKeyList();
|
||||||
for (String key : metaKeys) {
|
for (String key : metaKeys) {
|
||||||
String value = group.getVariables().getVarString(key);
|
String value = group.getVariables().getVarString(key);
|
||||||
key = key.toLowerCase();
|
key = key.toLowerCase();
|
||||||
|
if (key.isEmpty() || value.isEmpty()) continue;
|
||||||
if (key.isEmpty() || value.isEmpty()) {
|
if (key.equals("build")) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals("build")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals("prefix") || key.equals("suffix")) {
|
if (key.equals("prefix") || key.equals("suffix")) {
|
||||||
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
||||||
@ -180,23 +157,20 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} groups so far in world " + world, groupWorldCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far in world " + world, groupWorldCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupWorldCount.get() + " groups in world " + world);
|
log.log("Migrated " + groupWorldCount.get() + " groups in world " + world);
|
||||||
|
|
||||||
AtomicInteger userWorldCount = new AtomicInteger(0);
|
AtomicInteger userWorldCount = new AtomicInteger(0);
|
||||||
for (User user : wdh.getUserList()) {
|
SafeIterator.iterate(wdh.getUserList(), user -> {
|
||||||
UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getUUID());
|
UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getUUID());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
users.putIfAbsent(uuid, new HashSet<>());
|
users.putIfAbsent(uuid, new HashSet<>());
|
||||||
|
|
||||||
for (String node : user.getPermissionList()) {
|
for (String node : user.getPermissionList()) {
|
||||||
if (node.isEmpty()) {
|
if (node.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
users.get(uuid).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
|
users.get(uuid).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,14 +190,8 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
for (String key : metaKeys) {
|
for (String key : metaKeys) {
|
||||||
String value = user.getVariables().getVarString(key);
|
String value = user.getVariables().getVarString(key);
|
||||||
key = key.toLowerCase();
|
key = key.toLowerCase();
|
||||||
|
if (key.isEmpty() || value.isEmpty()) continue;
|
||||||
if (key.isEmpty() || value.isEmpty()) {
|
if (key.equals("build")) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals("build")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals("prefix") || key.equals("suffix")) {
|
if (key.equals("prefix") || key.equals("suffix")) {
|
||||||
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
||||||
@ -234,16 +202,16 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.logProgress("Migrated {} users so far in world " + world, userWorldCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far in world " + world, userWorldCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + userWorldCount.get() + " users in world " + world);
|
log.log("Migrated " + userWorldCount.get() + " users in world " + world);
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("All data has now been processed, now starting the import process.");
|
log.log("All data has now been processed, now starting the import process.");
|
||||||
log.log("Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
log.log("Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
||||||
|
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Map.Entry<String, Set<Node>> e : groups.entrySet()) {
|
SafeIterator.iterate(groups.entrySet(), e -> {
|
||||||
plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
|
||||||
me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey());
|
me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey());
|
||||||
|
|
||||||
@ -253,12 +221,12 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
for (Map.Entry<UUID, Set<Node>> e : users.entrySet()) {
|
SafeIterator.iterate(users.entrySet(), e -> {
|
||||||
plugin.getStorage().loadUser(e.getKey(), null).join();
|
plugin.getStorage().loadUser(e.getKey(), null).join();
|
||||||
me.lucko.luckperms.common.model.User user = plugin.getUserManager().getIfLoaded(e.getKey());
|
me.lucko.luckperms.common.model.User user = plugin.getUserManager().getIfLoaded(e.getKey());
|
||||||
|
|
||||||
@ -276,7 +244,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
|
@ -41,17 +41,15 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import ru.tehkode.permissions.NativeInterface;
|
|
||||||
import ru.tehkode.permissions.PermissionEntity;
|
import ru.tehkode.permissions.PermissionEntity;
|
||||||
import ru.tehkode.permissions.PermissionGroup;
|
import ru.tehkode.permissions.PermissionGroup;
|
||||||
import ru.tehkode.permissions.PermissionManager;
|
import ru.tehkode.permissions.PermissionManager;
|
||||||
import ru.tehkode.permissions.PermissionUser;
|
|
||||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -79,27 +77,17 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
PermissionsEx pex = (PermissionsEx) Bukkit.getPluginManager().getPlugin("PermissionsEx");
|
PermissionsEx pex = (PermissionsEx) Bukkit.getPluginManager().getPlugin("PermissionsEx");
|
||||||
PermissionManager manager = pex.getPermissionsManager();
|
PermissionManager manager = pex.getPermissionsManager();
|
||||||
|
|
||||||
NativeInterface ni;
|
|
||||||
try {
|
|
||||||
Field f = manager.getClass().getDeclaredField("nativeI");
|
|
||||||
f.setAccessible(true);
|
|
||||||
ni = (NativeInterface) f.get(manager);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.log("Calculating group weightings.");
|
log.log("Calculating group weightings.");
|
||||||
int maxWeight = 0;
|
int i = 0;
|
||||||
for (PermissionGroup group : manager.getGroupList()) {
|
for (PermissionGroup group : manager.getGroupList()) {
|
||||||
maxWeight = Math.max(maxWeight, group.getRank());
|
i = Math.max(i, group.getRank());
|
||||||
}
|
}
|
||||||
maxWeight += 5;
|
int maxWeight = i + 5;
|
||||||
|
|
||||||
// Migrate all groups.
|
// Migrate all groups.
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (PermissionGroup group : manager.getGroupList()) {
|
SafeIterator.iterate(manager.getGroupList(), group -> {
|
||||||
int groupWeight = maxWeight - group.getRank();
|
int groupWeight = maxWeight - group.getRank();
|
||||||
|
|
||||||
final String groupName = MigrationUtils.standardizeName(group.getName());
|
final String groupName = MigrationUtils.standardizeName(group.getName());
|
||||||
@ -113,7 +101,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
plugin.getStorage().saveGroup(lpGroup);
|
plugin.getStorage().saveGroup(lpGroup);
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate all users
|
// Migrate all users
|
||||||
@ -121,12 +109,12 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
// Increment the max weight from the group migrations. All user meta should override.
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
maxWeight += 5;
|
int userWeight = maxWeight + 5;
|
||||||
|
|
||||||
for (PermissionUser user : manager.getUsers()) {
|
SafeIterator.iterate(manager.getUsers(), user -> {
|
||||||
UUID u = BukkitMigrationUtils.lookupUuid(log, user.getIdentifier());
|
UUID u = BukkitMigrationUtils.lookupUuid(log, user.getIdentifier());
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load in a user instance
|
// load in a user instance
|
||||||
@ -134,7 +122,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
User lpUser = plugin.getUserManager().getIfLoaded(u);
|
User lpUser = plugin.getUserManager().getIfLoaded(u);
|
||||||
|
|
||||||
// migrate data
|
// migrate data
|
||||||
migrateEntity(user, lpUser, maxWeight);
|
migrateEntity(user, lpUser, userWeight);
|
||||||
|
|
||||||
// Lowest rank is the highest group #logic
|
// Lowest rank is the highest group #logic
|
||||||
String primary = null;
|
String primary = null;
|
||||||
@ -155,7 +143,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
plugin.getUserManager().cleanup(lpUser);
|
plugin.getUserManager().cleanup(lpUser);
|
||||||
plugin.getStorage().saveUser(lpUser);
|
plugin.getStorage().saveUser(lpUser);
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
@ -175,10 +163,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (String node : worldData.getValue()) {
|
for (String node : worldData.getValue()) {
|
||||||
if (node.isEmpty()) {
|
if (node.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.setPermission(MigrationUtils.parseNode(node, true).setWorld(world).build());
|
holder.setPermission(MigrationUtils.parseNode(node, true).setWorld(world).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup;
|
import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.Group;
|
import com.github.cheesesoftware.PowerfulPermsAPI.Group;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.Permission;
|
import com.github.cheesesoftware.PowerfulPermsAPI.Permission;
|
||||||
@ -53,6 +51,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
import me.lucko.luckperms.common.storage.StorageType;
|
import me.lucko.luckperms.common.storage.StorageType;
|
||||||
import me.lucko.luckperms.common.utils.HikariSupplier;
|
import me.lucko.luckperms.common.utils.HikariSupplier;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
@ -66,6 +65,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -113,7 +113,6 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
try (Connection c = hikari.getConnection()) {
|
try (Connection c = hikari.getConnection()) {
|
||||||
DatabaseMetaData meta = c.getMetaData();
|
DatabaseMetaData meta = c.getMetaData();
|
||||||
|
|
||||||
try (ResultSet rs = meta.getTables(null, null, dbTable, null)) {
|
try (ResultSet rs = meta.getTables(null, null, dbTable, null)) {
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
log.log("Error - Couldn't find table.");
|
log.log("Error - Couldn't find table.");
|
||||||
@ -125,7 +124,6 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
try (Connection c = hikari.getConnection()) {
|
try (Connection c = hikari.getConnection()) {
|
||||||
try (PreparedStatement ps = c.prepareStatement("SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=?")) {
|
try (PreparedStatement ps = c.prepareStatement("SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=?")) {
|
||||||
ps.setString(1, dbTable);
|
ps.setString(1, dbTable);
|
||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
log.log("Found table: " + dbTable);
|
log.log("Found table: " + dbTable);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -133,7 +131,6 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (PreparedStatement ps = c.prepareStatement("SELECT `uuid` FROM " + dbTable)) {
|
try (PreparedStatement ps = c.prepareStatement("SELECT `uuid` FROM " + dbTable)) {
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -158,17 +155,17 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
Collection<Group> groups = pm.getGroups().values();
|
Collection<Group> groups = pm.getGroups().values();
|
||||||
|
|
||||||
int maxWeight = 0;
|
AtomicInteger maxWeight = new AtomicInteger(0);
|
||||||
|
|
||||||
// Groups first.
|
// Groups first.
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Group g : groups) {
|
SafeIterator.iterate(groups, g -> {
|
||||||
maxWeight = Math.max(maxWeight, g.getRank());
|
maxWeight.set(Math.max(maxWeight.get(), g.getRank()));
|
||||||
|
|
||||||
final String groupName = MigrationUtils.standardizeName(g.getName());
|
String groupName = MigrationUtils.standardizeName(g.getName());
|
||||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||||
final me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
me.lucko.luckperms.common.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||||
|
|
||||||
MigrationUtils.setGroupWeight(group, g.getRank());
|
MigrationUtils.setGroupWeight(group, g.getRank());
|
||||||
|
|
||||||
@ -182,9 +179,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
// server --> prefix afaik
|
// server --> prefix afaik
|
||||||
for (Map.Entry<String, String> prefix : g.getPrefixes().entrySet()) {
|
for (Map.Entry<String, String> prefix : g.getPrefixes().entrySet()) {
|
||||||
if (prefix.getValue().isEmpty()) {
|
if (prefix.getValue().isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String server = prefix.getKey().toLowerCase();
|
String server = prefix.getKey().toLowerCase();
|
||||||
if (prefix.getKey().equals("*") || prefix.getKey().equals("all")) {
|
if (prefix.getKey().equals("*") || prefix.getKey().equals("all")) {
|
||||||
@ -199,9 +194,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> suffix : g.getSuffixes().entrySet()) {
|
for (Map.Entry<String, String> suffix : g.getSuffixes().entrySet()) {
|
||||||
if (suffix.getValue().isEmpty()) {
|
if (suffix.getValue().isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String server = suffix.getKey().toLowerCase();
|
String server = suffix.getKey().toLowerCase();
|
||||||
if (suffix.getKey().equals("*") || suffix.getKey().equals("all")) {
|
if (suffix.getKey().equals("*") || suffix.getKey().equals("all")) {
|
||||||
@ -217,7 +210,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate all users
|
// Migrate all users
|
||||||
@ -225,10 +218,10 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
// Increment the max weight from the group migrations. All user meta should override.
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
maxWeight += 5;
|
maxWeight.addAndGet(5);
|
||||||
|
|
||||||
// Migrate all users and their groups
|
// Migrate all users and their groups
|
||||||
for (UUID uuid : uuids) {
|
SafeIterator.iterate(uuids, uuid -> {
|
||||||
|
|
||||||
// Create a LuckPerms user for the UUID
|
// Create a LuckPerms user for the UUID
|
||||||
plugin.getStorage().loadUser(uuid, null).join();
|
plugin.getStorage().loadUser(uuid, null).join();
|
||||||
@ -257,11 +250,11 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
|
String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
|
||||||
|
|
||||||
if (prefix != null && !prefix.isEmpty()) {
|
if (prefix != null && !prefix.isEmpty()) {
|
||||||
user.setPermission(NodeFactory.makePrefixNode(maxWeight, prefix).build());
|
user.setPermission(NodeFactory.makePrefixNode(maxWeight.get(), prefix).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffix != null && !suffix.isEmpty()) {
|
if (suffix != null && !suffix.isEmpty()) {
|
||||||
user.setPermission(NodeFactory.makeSuffixNode(maxWeight, suffix).build());
|
user.setPermission(NodeFactory.makeSuffixNode(maxWeight.get(), suffix).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid));
|
Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid));
|
||||||
@ -276,7 +269,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
@ -344,8 +337,11 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
holder.setPermission(nb.build());
|
holder.setPermission(nb.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private static <T> T joinFuture(Future<T> future) {
|
private static <T> T joinFuture(Future<T> future) {
|
||||||
|
try {
|
||||||
return future.get();
|
return future.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||||
@ -103,14 +104,14 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
Map<UUID, Set<Node>> userParents = new HashMap<>();
|
Map<UUID, Set<Node>> userParents = new HashMap<>();
|
||||||
|
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
int maxWeight = 0;
|
AtomicInteger maxWeight = new AtomicInteger(0);
|
||||||
for (PermissionEntity entity : internalService.getEntities(true)) {
|
SafeIterator.iterate(internalService.getEntities(true), entity -> {
|
||||||
String groupName = MigrationUtils.standardizeName(entity.getDisplayName());
|
String groupName = MigrationUtils.standardizeName(entity.getDisplayName());
|
||||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||||
|
|
||||||
int weight = entity.getPriority();
|
int weight = entity.getPriority();
|
||||||
maxWeight = Math.max(maxWeight, weight);
|
maxWeight.set(Math.max(maxWeight.get(), weight));
|
||||||
migrateEntity(group, entity, weight);
|
migrateEntity(group, entity, weight);
|
||||||
MigrationUtils.setGroupWeight(group, weight);
|
MigrationUtils.setGroupWeight(group, weight);
|
||||||
|
|
||||||
@ -133,13 +134,13 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate all tracks
|
// Migrate all tracks
|
||||||
log.log("Starting track migration.");
|
log.log("Starting track migration.");
|
||||||
AtomicInteger trackCount = new AtomicInteger(0);
|
AtomicInteger trackCount = new AtomicInteger(0);
|
||||||
for (String t : service.getAllTracks()) {
|
SafeIterator.iterate(service.getAllTracks(), t -> {
|
||||||
String trackName = MigrationUtils.standardizeName(t);
|
String trackName = MigrationUtils.standardizeName(t);
|
||||||
|
|
||||||
plugin.getStorage().createAndLoadTrack(trackName, CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadTrack(trackName, CreationCause.INTERNAL).join();
|
||||||
@ -148,18 +149,18 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
plugin.getStorage().saveTrack(track);
|
plugin.getStorage().saveTrack(track);
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} tracks so far.", trackCount.incrementAndGet());
|
log.logAllProgress("Migrated {} tracks so far.", trackCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + trackCount.get() + " tracks");
|
log.log("Migrated " + trackCount.get() + " tracks");
|
||||||
|
|
||||||
// Migrate all users.
|
// Migrate all users.
|
||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
maxWeight += 10;
|
maxWeight.addAndGet(10);
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
Set<UUID> usersToMigrate = new HashSet<>(userParents.keySet());
|
Set<UUID> usersToMigrate = new HashSet<>(userParents.keySet());
|
||||||
usersToMigrate.addAll(service.getAllPlayersUUID());
|
usersToMigrate.addAll(service.getAllPlayersUUID());
|
||||||
|
|
||||||
for (UUID u : usersToMigrate) {
|
SafeIterator.iterate(usersToMigrate, u -> {
|
||||||
PermissionEntity entity = internalService.getEntity(null, u, false);
|
PermissionEntity entity = internalService.getEntity(null, u, false);
|
||||||
|
|
||||||
String username = null;
|
String username = null;
|
||||||
@ -172,7 +173,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
// migrate permissions & meta
|
// migrate permissions & meta
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
migrateEntity(user, entity, maxWeight);
|
migrateEntity(user, entity, maxWeight.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// migrate groups
|
// migrate groups
|
||||||
@ -186,7 +187,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
@ -195,9 +196,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, int weight) {
|
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, int weight) {
|
||||||
for (Entry e : entity.getPermissions()) {
|
for (Entry e : entity.getPermissions()) {
|
||||||
if (e.getPermission().isEmpty()) {
|
if (e.getPermission().isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
|
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
|
||||||
holder.setPermission(NodeFactory.newBuilder(e.getPermission()).setValue(e.isValue()).setWorld(e.getWorld().getName()).build());
|
holder.setPermission(NodeFactory.newBuilder(e.getPermission()).setValue(e.isValue()).setWorld(e.getWorld().getName()).build());
|
||||||
@ -217,10 +216,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
for (EntityMetadata metadata : entity.getMetadata()) {
|
for (EntityMetadata metadata : entity.getMetadata()) {
|
||||||
String key = metadata.getName().toLowerCase();
|
String key = metadata.getName().toLowerCase();
|
||||||
|
if (key.isEmpty() || metadata.getStringValue().isEmpty()) continue;
|
||||||
if (key.isEmpty() || metadata.getStringValue().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals("prefix") || key.equals("suffix")) {
|
if (key.equals("prefix") || key.equals("suffix")) {
|
||||||
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
||||||
|
@ -39,12 +39,12 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
|||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
|
||||||
import net.alpenblock.bungeeperms.BungeePerms;
|
import net.alpenblock.bungeeperms.BungeePerms;
|
||||||
import net.alpenblock.bungeeperms.Group;
|
import net.alpenblock.bungeeperms.Group;
|
||||||
import net.alpenblock.bungeeperms.PermEntity;
|
import net.alpenblock.bungeeperms.PermEntity;
|
||||||
import net.alpenblock.bungeeperms.Server;
|
import net.alpenblock.bungeeperms.Server;
|
||||||
import net.alpenblock.bungeeperms.User;
|
|
||||||
import net.alpenblock.bungeeperms.World;
|
import net.alpenblock.bungeeperms.World;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -74,16 +74,16 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
List<Group> groups = bp.getPermissionsManager().getBackEnd().loadGroups();
|
List<Group> groups = bp.getPermissionsManager().getBackEnd().loadGroups();
|
||||||
|
|
||||||
log.log("Calculating group weightings.");
|
log.log("Calculating group weightings.");
|
||||||
int maxWeight = 0;
|
int i = 0;
|
||||||
for (Group group : groups) {
|
for (Group group : groups) {
|
||||||
maxWeight = Math.max(maxWeight, group.getRank());
|
i = Math.max(i, group.getRank());
|
||||||
}
|
}
|
||||||
maxWeight += 5;
|
int maxWeight = i + 5;
|
||||||
|
|
||||||
// Migrate all groups.
|
// Migrate all groups.
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Group g : groups) {
|
SafeIterator.iterate(groups, g -> {
|
||||||
int groupWeight = maxWeight - g.getRank();
|
int groupWeight = maxWeight - g.getRank();
|
||||||
|
|
||||||
// Make a LuckPerms group for the one being migrated
|
// Make a LuckPerms group for the one being migrated
|
||||||
@ -96,7 +96,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate all users.
|
// Migrate all users.
|
||||||
@ -104,25 +104,25 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
// Increment the max weight from the group migrations. All user meta should override.
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
maxWeight += 5;
|
int userWeight = maxWeight + 5;
|
||||||
|
|
||||||
for (User u : bp.getPermissionsManager().getBackEnd().loadUsers()) {
|
SafeIterator.iterate(bp.getPermissionsManager().getBackEnd().loadUsers(), u -> {
|
||||||
if (u.getUUID() == null) {
|
if (u.getUUID() == null) {
|
||||||
log.logErr("Could not parse UUID for user: " + u.getName());
|
log.logErr("Could not parse UUID for user: " + u.getName());
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a LuckPerms user for the one being migrated.
|
// Make a LuckPerms user for the one being migrated.
|
||||||
plugin.getStorage().loadUser(u.getUUID(), u.getName()).join();
|
plugin.getStorage().loadUser(u.getUUID(), u.getName()).join();
|
||||||
me.lucko.luckperms.common.model.User user = plugin.getUserManager().getIfLoaded(u.getUUID());
|
me.lucko.luckperms.common.model.User user = plugin.getUserManager().getIfLoaded(u.getUUID());
|
||||||
|
|
||||||
migrateHolder(u, u.getGroupsString(), maxWeight, user);
|
migrateHolder(u, u.getGroupsString(), userWeight, user);
|
||||||
|
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
|
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
@ -132,30 +132,21 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
private static void migrateHolder(PermEntity entity, List<String> parents, int weight, PermissionHolder holder) {
|
private static void migrateHolder(PermEntity entity, List<String> parents, int weight, PermissionHolder holder) {
|
||||||
// Migrate global perms
|
// Migrate global perms
|
||||||
for (String perm : entity.getPerms()) {
|
for (String perm : entity.getPerms()) {
|
||||||
if (perm.isEmpty()) {
|
if (perm.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.setPermission(MigrationUtils.parseNode(perm, true).build());
|
holder.setPermission(MigrationUtils.parseNode(perm, true).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate per-server perms
|
// Migrate per-server perms
|
||||||
for (Map.Entry<String, Server> e : entity.getServers().entrySet()) {
|
for (Map.Entry<String, Server> e : entity.getServers().entrySet()) {
|
||||||
for (String perm : e.getValue().getPerms()) {
|
for (String perm : e.getValue().getPerms()) {
|
||||||
if (perm.isEmpty()) {
|
if (perm.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.setPermission(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).build());
|
holder.setPermission(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate per-world perms
|
// 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()) {
|
||||||
if (perm.isEmpty()) {
|
if (perm.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.setPermission(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).setWorld(we.getKey()).build());
|
holder.setPermission(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).setWorld(we.getKey()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,10 +154,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Migrate any parent groups
|
// Migrate any parent groups
|
||||||
for (String inherit : parents) {
|
for (String inherit : parents) {
|
||||||
if (inherit.isEmpty()) {
|
if (inherit.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(inherit)));
|
holder.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(inherit)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,19 +35,18 @@ import java.util.stream.IntStream;
|
|||||||
/**
|
/**
|
||||||
* A collection of predicate utilities used mostly in command classes
|
* A collection of predicate utilities used mostly in command classes
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Predicates {
|
public class Predicates {
|
||||||
private static final Predicate FALSE = o -> false;
|
private static final Predicate FALSE = o -> false;
|
||||||
private static final Predicate TRUE = o -> true;
|
private static final Predicate TRUE = o -> true;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> Predicate<T> alwaysFalse() {
|
public static <T> Predicate<T> alwaysFalse() {
|
||||||
|
//noinspection unchecked
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> Predicate<T> alwaysTrue() {
|
public static <T> Predicate<T> alwaysTrue() {
|
||||||
|
//noinspection unchecked
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.utils;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class SafeIterator {
|
||||||
|
|
||||||
|
public static <I> void iterate(Iterable<I> iterable, Consumer<I> action) {
|
||||||
|
for (I i : iterable) {
|
||||||
|
try {
|
||||||
|
action.accept(i);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <I, O> void iterate(Iterable<I> iterable, Function<I, O> mapping, Consumer<O> action) {
|
||||||
|
for (I i : iterable) {
|
||||||
|
try {
|
||||||
|
action.accept(mapping.apply(i));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <I> void iterate(I[] array, Consumer<I> action) {
|
||||||
|
for (I i : array) {
|
||||||
|
try {
|
||||||
|
action.accept(i);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <I, O> void iterate(I[] array, Function<I, O> mapping, Consumer<O> action) {
|
||||||
|
for (I i : array) {
|
||||||
|
try {
|
||||||
|
action.accept(mapping.apply(i));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -40,14 +40,13 @@ import me.lucko.luckperms.common.model.Group;
|
|||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -93,18 +92,18 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Migrate defaults
|
// Migrate defaults
|
||||||
log.log("Migrating default subjects.");
|
log.log("Migrating default subjects.");
|
||||||
for (SubjectCollection collection : pmService.getKnownSubjects().values()) {
|
SafeIterator.iterate(pmService.getKnownSubjects().values(), collection -> {
|
||||||
migrateSubjectData(
|
migrateSubjectData(
|
||||||
collection.getDefaults().getSubjectData(),
|
collection.getDefaults().getSubjectData(),
|
||||||
lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData()
|
lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
||||||
|
|
||||||
// Migrate groups
|
// Migrate groups
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Subject pmGroup : pmService.getGroupSubjects().getAllSubjects()) {
|
SafeIterator.iterate(pmService.getGroupSubjects().getAllSubjects(), pmGroup -> {
|
||||||
String pmName = MigrationUtils.standardizeName(pmGroup.getIdentifier());
|
String pmName = MigrationUtils.standardizeName(pmGroup.getIdentifier());
|
||||||
|
|
||||||
// Make a LuckPerms group for the one being migrated
|
// Make a LuckPerms group for the one being migrated
|
||||||
@ -114,17 +113,17 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
|||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate users
|
// Migrate users
|
||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
for (Subject pmUser : pmService.getUserSubjects().getAllSubjects()) {
|
SafeIterator.iterate(pmService.getUserSubjects().getAllSubjects(), pmUser -> {
|
||||||
UUID uuid = CommandUtils.parseUuid(pmUser.getIdentifier());
|
UUID uuid = CommandUtils.parseUuid(pmUser.getIdentifier());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.logErr("Could not parse UUID for user: " + pmUser.getIdentifier());
|
log.logErr("Could not parse UUID for user: " + pmUser.getIdentifier());
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a LuckPerms user for the one being migrated
|
// Make a LuckPerms user for the one being migrated
|
||||||
@ -138,7 +137,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
|||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
|
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
|
@ -41,6 +41,7 @@ import me.lucko.luckperms.common.model.Track;
|
|||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
|
||||||
@ -48,7 +49,6 @@ import org.spongepowered.api.Sponge;
|
|||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -89,33 +89,32 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Migrate defaults
|
// Migrate defaults
|
||||||
log.log("Migrating default subjects.");
|
log.log("Migrating default subjects.");
|
||||||
for (SubjectCollection collection : pexService.getKnownSubjects().values()) {
|
SafeIterator.iterate(pexService.getKnownSubjects().values(), collection -> {
|
||||||
migrateSubjectData(
|
migrateSubjectData(
|
||||||
collection.getDefaults().getSubjectData(),
|
collection.getDefaults().getSubjectData(),
|
||||||
lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData()
|
lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
||||||
|
|
||||||
log.log("Calculating group weightings.");
|
log.log("Calculating group weightings.");
|
||||||
int maxWeight = 0;
|
int i = 0;
|
||||||
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
||||||
Optional<String> pos = pexGroup.getOption("rank");
|
Optional<String> pos = pexGroup.getOption("rank");
|
||||||
if (pos.isPresent()) {
|
if (pos.isPresent()) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(pos.get());
|
i = Math.max(i, Integer.parseInt(pos.get()));
|
||||||
maxWeight = Math.max(maxWeight, i);
|
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maxWeight += 5;
|
int maxWeight = i + 5;
|
||||||
|
|
||||||
Map<String, TreeMap<Integer, String>> tracks = new HashMap<>();
|
Map<String, TreeMap<Integer, String>> tracks = new HashMap<>();
|
||||||
|
|
||||||
// Migrate groups
|
// Migrate groups
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
SafeIterator.iterate(pexService.getGroupSubjects().getAllSubjects(), pexGroup -> {
|
||||||
String pexName = MigrationUtils.standardizeName(pexGroup.getIdentifier());
|
String pexName = MigrationUtils.standardizeName(pexGroup.getIdentifier());
|
||||||
|
|
||||||
Optional<String> rankString = pexGroup.getOption("rank");
|
Optional<String> rankString = pexGroup.getOption("rank");
|
||||||
@ -149,12 +148,12 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate tracks
|
// Migrate tracks
|
||||||
log.log("Starting track migration.");
|
log.log("Starting track migration.");
|
||||||
for (Map.Entry<String, TreeMap<Integer, String>> e : tracks.entrySet()) {
|
SafeIterator.iterate(tracks.entrySet(), e -> {
|
||||||
plugin.getStorage().createAndLoadTrack(e.getKey(), CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadTrack(e.getKey(), CreationCause.INTERNAL).join();
|
||||||
Track track = plugin.getTrackManager().getIfLoaded(e.getKey());
|
Track track = plugin.getTrackManager().getIfLoaded(e.getKey());
|
||||||
for (String groupName : e.getValue().values()) {
|
for (String groupName : e.getValue().values()) {
|
||||||
@ -163,7 +162,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
track.appendGroup(group);
|
track.appendGroup(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
log.log("Migrated " + tracks.size() + " tracks");
|
log.log("Migrated " + tracks.size() + " tracks");
|
||||||
|
|
||||||
// Migrate users
|
// Migrate users
|
||||||
@ -171,13 +170,13 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
// Increment the max weight from the group migrations. All user meta should override.
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
maxWeight += 5;
|
int userWeight = maxWeight + 5;
|
||||||
|
|
||||||
for (Subject pexUser : pexService.getUserSubjects().getAllSubjects()) {
|
SafeIterator.iterate(pexService.getUserSubjects().getAllSubjects(), pexUser -> {
|
||||||
UUID uuid = CommandUtils.parseUuid(pexUser.getIdentifier());
|
UUID uuid = CommandUtils.parseUuid(pexUser.getIdentifier());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.logErr("Could not parse UUID for user: " + pexUser.getIdentifier());
|
log.logErr("Could not parse UUID for user: " + pexUser.getIdentifier());
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a LuckPerms user for the one being migrated
|
// Make a LuckPerms user for the one being migrated
|
||||||
@ -186,12 +185,12 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
if (user.getEnduringNodes().size() <= 1) {
|
if (user.getEnduringNodes().size() <= 1) {
|
||||||
user.clearNodes(false);
|
user.clearNodes(false);
|
||||||
}
|
}
|
||||||
migrateSubject(pexUser, user, maxWeight);
|
migrateSubject(pexUser, user, userWeight);
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
|
|
||||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
});
|
||||||
|
|
||||||
log.log("Migrated " + userCount.get() + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
|
Loading…
Reference in New Issue
Block a user