mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Complete the migration system
This commit is contained in:
parent
dd7aee9d15
commit
5dc551c05d
@ -2,7 +2,7 @@ name: LuckPerms
|
||||
author: Luck
|
||||
version: ${release.version}.${git.closest.tag.commit.count}
|
||||
main: me.lucko.luckperms.LPBukkitPlugin
|
||||
softdepend: [Vault]
|
||||
softdepend: [Vault, PermissionsEx, GroupManager, PowerfulPerms, zPermissions] # For migration
|
||||
description: A permissions plugin
|
||||
commands:
|
||||
luckperms:
|
||||
|
@ -2,4 +2,5 @@ name: LuckPerms
|
||||
author: Luck
|
||||
version: ${release.version}.${git.closest.tag.commit.count}
|
||||
main: me.lucko.luckperms.LPBungeePlugin
|
||||
softdepend: [VPowerfulPerms] # For migration
|
||||
description: A permissions plugin
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.commands.group.DeleteGroup;
|
||||
import me.lucko.luckperms.commands.group.GroupMainCommand;
|
||||
import me.lucko.luckperms.commands.group.ListGroups;
|
||||
import me.lucko.luckperms.commands.log.LogMainCommand;
|
||||
import me.lucko.luckperms.commands.migration.MigrationMainCommand;
|
||||
import me.lucko.luckperms.commands.misc.DebugCommand;
|
||||
import me.lucko.luckperms.commands.misc.ImportCommand;
|
||||
import me.lucko.luckperms.commands.misc.InfoCommand;
|
||||
@ -63,7 +64,7 @@ public class CommandManager {
|
||||
.add(new InfoCommand())
|
||||
.add(new DebugCommand())
|
||||
.add(new ImportCommand())
|
||||
// .add(new MigrationMainCommand()) TODO
|
||||
.add(new MigrationMainCommand())
|
||||
.add(new CreateGroup())
|
||||
.add(new DeleteGroup())
|
||||
.add(new ListGroups())
|
||||
|
@ -27,7 +27,10 @@ import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.migration.subcommands.MigrationGroupManager;
|
||||
import me.lucko.luckperms.commands.migration.subcommands.MigrationPermissionsEx;
|
||||
import me.lucko.luckperms.commands.migration.subcommands.MigrationPowerfulPerms;
|
||||
import me.lucko.luckperms.commands.migration.subcommands.MigrationZPermissions;
|
||||
import me.lucko.luckperms.constants.Constants;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
@ -42,9 +45,24 @@ public class MigrationMainCommand extends MainCommand<Object> {
|
||||
super("Migration", "/%s migration", 1, null);
|
||||
|
||||
try {
|
||||
Class.forName("org.anjocaido.groupmanager.GroupManager");
|
||||
subCommands.add(new MigrationGroupManager());
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
try {
|
||||
Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx");
|
||||
subCommands.add(new MigrationPermissionsEx());
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
try {
|
||||
Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin");
|
||||
subCommands.add(new MigrationPowerfulPerms());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
try {
|
||||
Class.forName("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService");
|
||||
subCommands.add(new MigrationZPermissions());
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,25 @@ import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import org.anjocaido.groupmanager.GlobalGroups;
|
||||
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.worlds.WorldsHolder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MigrationGroupManager extends SubCommand<Object> {
|
||||
public MigrationGroupManager() {
|
||||
super("groupmanager", "Migration from GroupManager",
|
||||
"/%s migration groupmanager [world names]", Permission.MIGRATION, Predicate.alwaysFalse());
|
||||
"/%s migration groupmanager [world names]", Permission.MIGRATION, Predicate.is(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,13 +58,145 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
final List<String> worlds = args.stream()
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
GroupManager gm = (GroupManager) plugin.getPlugin("GroupManager");
|
||||
|
||||
// Migrate all users.
|
||||
log.info("GroupManager Migration: Starting user migration.");
|
||||
// Migrate Global Groups
|
||||
log.info("GroupManager Migration: Starting Global Group migration.");
|
||||
|
||||
// gm.getWorldsHolder().getWorldData().
|
||||
// TODO
|
||||
return null;
|
||||
GlobalGroups gg;
|
||||
try {
|
||||
gg = (GlobalGroups) GroupManager.class.getMethod("getGlobalGroups").invoke(gm);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
for (Group g : gg.getGroupList()) {
|
||||
plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase());
|
||||
me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase());
|
||||
|
||||
for (String node : g.getPermissionList()) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
try {
|
||||
group.setPermission(node, value);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
for (String s : g.getInherits()) {
|
||||
try {
|
||||
group.setPermission("group." + s.toLowerCase(), true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Map<UUID, Map<String, Boolean>> users = new HashMap<>();
|
||||
Map<String, Map<String, Boolean>> groups = new HashMap<>();
|
||||
|
||||
WorldsHolder wh;
|
||||
try {
|
||||
wh = (WorldsHolder) GroupManager.class.getMethod("getWorldsHolder").invoke(gm);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
// Collect data for all users and groups.
|
||||
log.info("GroupManager Migration: Starting user and group migration.");
|
||||
for (String world : worlds) {
|
||||
world = world.toLowerCase();
|
||||
|
||||
WorldDataHolder wdh;
|
||||
|
||||
try {
|
||||
wdh = (WorldDataHolder) WorldsHolder.class.getMethod("getWorldData", String.class).invoke(wh, world);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
for (Group g : wdh.getGroupList()) {
|
||||
groups.putIfAbsent(g.getName().toLowerCase(), new HashMap<>());
|
||||
|
||||
for (String node : g.getPermissionList()) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
groups.get(g.getName().toLowerCase()).put("global-" + world + "/" + node, value);
|
||||
}
|
||||
|
||||
for (String s : g.getInherits()) {
|
||||
groups.get(g.getName().toLowerCase()).put("global-" + world + "/group." + s.toLowerCase(), true);
|
||||
}
|
||||
}
|
||||
|
||||
for (User user : wdh.getUserList()) {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(user.getUUID());
|
||||
} catch (IllegalArgumentException e){
|
||||
continue;
|
||||
}
|
||||
|
||||
users.putIfAbsent(uuid, new HashMap<>());
|
||||
|
||||
for (String node : user.getPermissionList()) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
users.get(uuid).put("global-" + world + "/" + node, value);
|
||||
}
|
||||
|
||||
users.get(uuid).put("global-" + world + "/group." + user.getGroupName().toLowerCase(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
|
||||
|
||||
for (Map.Entry<UUID, Map<String, Boolean>> e : users.entrySet()) {
|
||||
plugin.getDatastore().loadOrCreateUser(e.getKey(), "null");
|
||||
me.lucko.luckperms.users.User user = plugin.getUserManager().get(e.getKey());
|
||||
|
||||
for (Map.Entry<String, Boolean> n : e.getValue().entrySet()) {
|
||||
try {
|
||||
user.setPermission(n.getKey(), n.getValue());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
plugin.getDatastore().saveUser(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.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,10 @@ import ru.tehkode.permissions.PermissionManager;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
public MigrationPermissionsEx() {
|
||||
@ -55,8 +57,24 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (plugin.getType() != LuckPermsPlugin.Type.BUKKIT) {
|
||||
// Sponge uses a completely different version of PEX.
|
||||
log.severe("PEX import is not supported on this platform.");
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
final List<String> worlds = args.stream()
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PermissionsEx pex = (PermissionsEx) plugin.getPlugin("PermissionsEx");
|
||||
PermissionManager manager = null; // TODO
|
||||
PermissionManager manager; // The compiler complains if you call the method directly, as Bukkit is not in this module.
|
||||
try {
|
||||
manager = (PermissionManager) PermissionsEx.class.getMethod("getPermissionsManager").invoke(pex);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
// Migrate all users
|
||||
log.info("PermissionsEx Migration: Starting user migration.");
|
||||
@ -81,8 +99,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
||||
}
|
||||
|
||||
if (args != null && !args.isEmpty()) {
|
||||
for (String world : args) {
|
||||
if (worlds != null && !worlds.isEmpty()) {
|
||||
for (String world : worlds) {
|
||||
for (String node : user.getOwnPermissions(world)) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!")) {
|
||||
@ -103,8 +121,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
if (args != null && !args.isEmpty()) {
|
||||
for (String world : args) {
|
||||
if (worlds != null && !worlds.isEmpty()) {
|
||||
for (String world : worlds) {
|
||||
for (String s : user.getGroupNames(world)) {
|
||||
try {
|
||||
lpUser.setPermission("group." + s.toLowerCase(), true, "global", world);
|
||||
@ -140,8 +158,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
||||
}
|
||||
|
||||
if (args != null && !args.isEmpty()) {
|
||||
for (String world : args) {
|
||||
if (worlds != null && !worlds.isEmpty()) {
|
||||
for (String world : worlds) {
|
||||
for (String node : group.getOwnPermissions(world)) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!")) {
|
||||
@ -162,8 +180,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
if (args != null && !args.isEmpty()) {
|
||||
for (String world : args) {
|
||||
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);
|
||||
@ -173,6 +191,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
log.info("PermissionsEx Migration: Success! Completed without any errors.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
</sadness> */
|
||||
private static Method getPlayerGroupsMethod = null;
|
||||
private static Method getGroupMethod = null;
|
||||
private static boolean legacy = true;
|
||||
private static boolean legacy = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -320,7 +320,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
// We done.
|
||||
log.info("PowerfulPerms Migration: Success! Migration completed without any errors.");
|
||||
log.info("PowerfulPerms Migration: Success! Completed without any errors.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <3 <3 zPermissions <3 <3
|
||||
@ -63,6 +64,10 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
final List<String> worlds = args.stream()
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Migrate all users.
|
||||
log.info("zPermissions Migration: Starting user migration.");
|
||||
for (UUID u : service.getAllPlayersUUID()) {
|
||||
@ -75,8 +80,8 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
if (args != null && !args.isEmpty()) {
|
||||
for (String world : args) {
|
||||
if (worlds != null && !worlds.isEmpty()) {
|
||||
for (String world : worlds) {
|
||||
for (Map.Entry<String, Boolean> e : service.getPlayerPermissions(world, null, u).entrySet()) {
|
||||
try {
|
||||
user.setPermission(e.getKey(), e.getValue(), "global", world);
|
||||
@ -119,8 +124,8 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
if (args != null && !args.isEmpty()) {
|
||||
for (String world : args) {
|
||||
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);
|
||||
@ -132,7 +137,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
plugin.getDatastore().saveGroup(group);
|
||||
}
|
||||
|
||||
log.info("zPermissions Migration: Complete!");
|
||||
log.info("zPermissions Migration: Success! Completed without any errors.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user