From 9de44d26055fcadd6e6cf49245fe9bacb84824ed Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 7 Apr 2017 21:03:27 +0100 Subject: [PATCH] Don't attempt to migrate empty permissions --- .../migration/MigrationBPermissions.java | 11 +++++ .../migration/MigrationGroupManager.java | 29 ++++++++++++++ .../migration/MigrationPermissionsEx.java | 40 +++++++++++++++++++ .../migration/MigrationBungeePerms.java | 32 +++++++++++++++ .../migration/SpongeMigrationUtils.java | 8 ++++ 5 files changed, 120 insertions(+) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index 65b2fb543..27a2b5423 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -189,10 +189,17 @@ public class MigrationBPermissions extends SubCommand { private static void migrateHolder(World world, Calculable c, PermissionHolder holder) { // Migrate the groups permissions in this world for (Permission p : c.getPermissions()) { + if (p.name().isEmpty()) { + continue; + } holder.setPermission(NodeFactory.make(p.name(), p.isTrue(), "global", world.getName())); // Include any child permissions for (Map.Entry child : p.getChildren().entrySet()) { + if (child.getKey().isEmpty()) { + continue; + } + holder.setPermission(NodeFactory.make(child.getKey(), child.getValue(), "global", world.getName())); } } @@ -209,6 +216,10 @@ public class MigrationBPermissions extends SubCommand { // Migrate existing meta for (Map.Entry meta : c.getMeta().entrySet()) { + if (meta.getKey().isEmpty() || meta.getValue().isEmpty()) { + continue; + } + if (meta.getKey().equalsIgnoreCase("prefix") || meta.getKey().equalsIgnoreCase("suffix")) { holder.setPermission(NodeFactory.makeChatMetaNode(meta.getKey().equalsIgnoreCase("prefix"), c.getPriority(), meta.getValue()).setWorld(world.getName()).build()); continue; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index db2b353ed..cf6e97f31 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -97,10 +97,18 @@ public class MigrationGroupManager extends SubCommand { me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(groupName); for (String node : g.getPermissionList()) { + if (node.isEmpty()) { + continue; + } + group.setPermission(MigrationUtils.parseNode(node, true).build()); } for (String s : g.getInherits()) { + if (s.isEmpty()) { + continue; + } + group.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(s))); } @@ -131,10 +139,18 @@ public class MigrationGroupManager extends SubCommand { groups.putIfAbsent(groupName, new HashSet<>()); for (String node : group.getPermissionList()) { + if (node.isEmpty()) { + continue; + } + groups.get(groupName).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build()); } for (String s : group.getInherits()) { + if (s.isEmpty()) { + continue; + } + groups.get(groupName).add(NodeFactory.make("group." + MigrationUtils.standardizeName(s), true, null, worldMappingFunc.apply(world))); } @@ -144,6 +160,10 @@ public class MigrationGroupManager extends SubCommand { String value = group.getVariables().getVarString(key); key = key.toLowerCase(); + if (key.isEmpty() || value.isEmpty()) { + continue; + } + if (key.equals("build")) { continue; } @@ -172,12 +192,17 @@ public class MigrationGroupManager extends SubCommand { users.putIfAbsent(uuid, new HashSet<>()); for (String node : user.getPermissionList()) { + if (node.isEmpty()) { + continue; + } + users.get(uuid).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build()); } // Collect sub groups String finalWorld = worldMappingFunc.apply(world); users.get(uuid).addAll(user.subGroupListStringCopy().stream() + .filter(n -> !n.isEmpty()) .map(n -> "group." + MigrationUtils.standardizeName(n)) .map(n -> NodeFactory.make(n, true, null, finalWorld)) .collect(Collectors.toSet()) @@ -191,6 +216,10 @@ public class MigrationGroupManager extends SubCommand { String value = user.getVariables().getVarString(key); key = key.toLowerCase(); + if (key.isEmpty() || value.isEmpty()) { + continue; + } + if (key.equals("build")) { continue; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 018df9204..39e136a9b 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -106,6 +106,10 @@ public class MigrationPermissionsEx extends SubCommand { try { for (String node : group.getOwnPermissions(null)) { + if (node.isEmpty()) { + continue; + } + lpGroup.setPermission(MigrationUtils.parseNode(node, true).build()); } } catch (NullPointerException ignored) { @@ -113,7 +117,15 @@ public class MigrationPermissionsEx extends SubCommand { } for (String world : worlds) { + if (world.isEmpty()) { + continue; + } + for (String node : group.getOwnPermissions(world)) { + if (node.isEmpty()) { + continue; + } + lpGroup.setPermission(MigrationUtils.parseNode(node, true).setWorld(world.toLowerCase()).build()); } } @@ -123,6 +135,10 @@ public class MigrationPermissionsEx extends SubCommand { } for (String world : worlds) { + if (world.isEmpty()) { + continue; + } + for (PermissionGroup g : group.getParents(world)) { lpGroup.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(g.getName()), true, "global", world.toLowerCase())); } @@ -176,6 +192,10 @@ public class MigrationPermissionsEx extends SubCommand { try { for (String node : user.getOwnPermissions(null)) { + if (node.isEmpty()) { + continue; + } + lpUser.setPermission(MigrationUtils.parseNode(node, true).build()); } } catch (NullPointerException ignored) { @@ -183,17 +203,37 @@ public class MigrationPermissionsEx extends SubCommand { } for (String world : worlds) { + if (world.isEmpty()) { + continue; + } + for (String node : user.getOwnPermissions(world)) { + if (node.isEmpty()) { + continue; + } + lpUser.setPermission(MigrationUtils.parseNode(node, true).setWorld(world.toLowerCase()).build()); } } for (String g : user.getGroupNames()) { + if (g.isEmpty()) { + continue; + } + lpUser.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(g))); } for (String world : worlds) { + if (world.isEmpty()) { + continue; + } + for (String g : user.getGroupNames(world)) { + if (g.isEmpty()) { + continue; + } + lpUser.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(g), true, "global", world.toLowerCase())); } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 109ce1aed..0ea2cd8e2 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -88,18 +88,30 @@ public class MigrationBungeePerms extends SubCommand { // Migrate global perms for (String perm : g.getPerms()) { + if (perm.isEmpty()) { + continue; + } + group.setPermission(MigrationUtils.parseNode(perm, true).build()); } // Migrate per-server perms for (Map.Entry e : g.getServers().entrySet()) { for (String perm : e.getValue().getPerms()) { + if (perm.isEmpty()) { + continue; + } + group.setPermission(MigrationUtils.parseNode(perm, true).setWorld(e.getKey()).build()); } // Migrate per-world perms for (Map.Entry we : e.getValue().getWorlds().entrySet()) { for (String perm : we.getValue().getPerms()) { + if (perm.isEmpty()) { + continue; + } + group.setPermission(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).setWorld(we.getKey()).build()); } } @@ -107,6 +119,10 @@ public class MigrationBungeePerms extends SubCommand { // Migrate any parent groups for (String inherit : g.getInheritances()) { + if (inherit.isEmpty()) { + continue; + } + group.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(inherit))); } @@ -145,18 +161,30 @@ public class MigrationBungeePerms extends SubCommand { // Migrate global perms for (String perm : u.getPerms()) { + if (perm.isEmpty()) { + continue; + } + user.setPermission(MigrationUtils.parseNode(perm, true).build()); } // Migrate per-server perms for (Map.Entry e : u.getServers().entrySet()) { for (String perm : e.getValue().getPerms()) { + if (perm.isEmpty()) { + continue; + } + user.setPermission(MigrationUtils.parseNode(perm, true).setWorld(e.getKey()).build()); } // Migrate per-world perms for (Map.Entry we : e.getValue().getWorlds().entrySet()) { for (String perm : we.getValue().getPerms()) { + if (perm.isEmpty()) { + continue; + } + user.setPermission(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).setWorld(we.getKey()).build()); } } @@ -164,6 +192,10 @@ public class MigrationBungeePerms extends SubCommand { // Migrate groups for (String group : u.getGroupsString()) { + if (group.isEmpty()) { + continue; + } + user.setPermission(NodeFactory.make("group." + MigrationUtils.standardizeName(group))); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/SpongeMigrationUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/SpongeMigrationUtils.java index c9488b772..8c57a68b0 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/SpongeMigrationUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/SpongeMigrationUtils.java @@ -55,6 +55,10 @@ public class SpongeMigrationUtils { ContextSet context = Util.convertContexts(e.getKey()); for (Map.Entry perm : e.getValue().entrySet()) { + if (perm.getKey().isEmpty()) { + continue; + } + holder.setPermission(NodeFactory.newBuilder(perm.getKey()).withExtraContext(context).setValue(perm.getValue()).build()); } } @@ -65,6 +69,10 @@ public class SpongeMigrationUtils { ContextSet context = Util.convertContexts(e.getKey()); for (Map.Entry opt : e.getValue().entrySet()) { + if (opt.getKey().isEmpty() || opt.getValue().isEmpty()) { + continue; + } + if (opt.getKey().equalsIgnoreCase("prefix")) { holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).withExtraContext(context).setValue(true).build()); } else if (opt.getKey().equalsIgnoreCase("suffix")) {