From 1c97cb3cece1e77fd03c22c21c925e8bb557135c Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 7 Dec 2016 21:14:24 +0000 Subject: [PATCH] Sponge: Fix migration for subjects with identifiers containing spaces --- .../migration/MigrationPermissionManager.java | 6 ++++-- .../migration/MigrationPermissionsEx.java | 6 ++++-- .../sponge/migration/MigrationUtils.java | 21 +++++++++---------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java index f1afaaa1..ef8c0a90 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java @@ -89,9 +89,11 @@ public class MigrationPermissionManager extends SubCommand { for (Subject pmGroup : pmService.getGroupSubjects().getAllSubjects()) { groupCount++; + String pmName = MigrationUtils.convertGroupName(pmGroup.getIdentifier().toLowerCase()); + // Make a LuckPerms group for the one being migrated - plugin.getStorage().createAndLoadGroup(pmGroup.getIdentifier().toLowerCase()).join(); - Group group = plugin.getGroupManager().getIfLoaded(pmGroup.getIdentifier().toLowerCase()); + plugin.getStorage().createAndLoadGroup(pmName).join(); + Group group = plugin.getGroupManager().getIfLoaded(pmName); migrateSubject(pmGroup, group); plugin.getStorage().saveGroup(group); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java index 67086110..901a275d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java @@ -83,9 +83,11 @@ public class MigrationPermissionsEx extends SubCommand { for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) { groupCount++; + String pexName = MigrationUtils.convertGroupName(pexGroup.getIdentifier().toLowerCase()); + // Make a LuckPerms group for the one being migrated - plugin.getStorage().createAndLoadGroup(pexGroup.getIdentifier().toLowerCase()).join(); - Group group = plugin.getGroupManager().getIfLoaded(pexGroup.getIdentifier().toLowerCase()); + plugin.getStorage().createAndLoadGroup(pexName).join(); + Group group = plugin.getGroupManager().getIfLoaded(pexName); migrateSubject(pexGroup, group); plugin.getStorage().saveGroup(group); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java index e2cc6ae2..04696809 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java @@ -59,8 +59,7 @@ public class MigrationUtils { for (Map.Entry perm : e.getValue().entrySet()) { try { holder.setPermission(new NodeBuilder(perm.getKey()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build()); - } catch (ObjectAlreadyHasException ignored) { - } + } catch (ObjectAlreadyHasException ignored) {} } } @@ -79,18 +78,15 @@ public class MigrationUtils { if (opt.getKey().equalsIgnoreCase("prefix")) { try { holder.setPermission(NodeFactory.makePrefixNode(100, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) { - } + } catch (ObjectAlreadyHasException ignored) {} } else if (opt.getKey().equalsIgnoreCase("suffix")) { try { holder.setPermission(NodeFactory.makeSuffixNode(100, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) { - } + } catch (ObjectAlreadyHasException ignored) {} } else { try { holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) { - } + } catch (ObjectAlreadyHasException ignored) {} } } } @@ -115,9 +111,8 @@ public class MigrationUtils { } try { - holder.setPermission(new NodeBuilder("group." + s.getIdentifier().toLowerCase()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) { - } + holder.setPermission(new NodeBuilder("group." + convertGroupName(s.getIdentifier().toLowerCase())).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); + } catch (ObjectAlreadyHasException ignored) {} } } } @@ -142,4 +137,8 @@ public class MigrationUtils { } } + public static String convertGroupName(String s) { + return s.replace(' ', '_'); + } + }