From 9cd4e01d8e30cec774d2cbb6e4772593fe167376 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 23 Aug 2016 12:36:20 +0100 Subject: [PATCH] Copy prefixes and suffixes during migration processes --- .../luckperms/api/vault/VaultChatHook.java | 12 ++---- .../subcommands/MigrationBungeePerms.java | 38 +++++++++++++++- .../subcommands/MigrationGroupManager.java | 1 + .../subcommands/MigrationPermissionsEx.java | 43 +++++++++++++++++++ .../subcommands/MigrationZPermissions.java | 19 ++++++++ .../luckperms/utils/ArgumentChecker.java | 8 ++++ 6 files changed, 111 insertions(+), 10 deletions(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultChatHook.java b/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultChatHook.java index 893283957..8d9d2c151 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultChatHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultChatHook.java @@ -36,6 +36,8 @@ import java.util.Collections; import java.util.Map; import java.util.regex.Pattern; +import static me.lucko.luckperms.utils.ArgumentChecker.escapeCharacters; + /** * Provides the Vault Chat service through the use of normal permission nodes. * @@ -50,7 +52,7 @@ import java.util.regex.Pattern; * Permission Nodes = meta.node.value * * Node that special characters used within LuckPerms are escaped: - * See {@link #escapeCharacters(String)} + * See {@link me.lucko.luckperms.utils.ArgumentChecker#escapeCharacters(String)} * * Registered on normal priority so other plugins can override. */ @@ -75,14 +77,6 @@ class VaultChatHook extends Chat { return perms.isEnabled(); } - private static String escapeCharacters(String s) { - s = s.replace(".", "{SEP}"); - s = s.replace("/", "{FSEP}"); - s = s.replace("$", "{DSEP}"); - - return s; - } - private void saveMeta(PermissionHolder holder, String world, String node, String value) { if (holder == null) return; if (node.equals("")) return; diff --git a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationBungeePerms.java b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationBungeePerms.java index 83a25c2bb..5c5e2909c 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationBungeePerms.java +++ b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationBungeePerms.java @@ -30,6 +30,7 @@ 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 me.lucko.luckperms.utils.ArgumentChecker; import net.alpenblock.bungeeperms.*; import java.util.List; @@ -92,6 +93,23 @@ public class MigrationBungeePerms extends SubCommand { } catch (ObjectAlreadyHasException ignored) {} } + String prefix = u.getPrefix(); + String suffix = u.getSuffix(); + + if (prefix != null && !prefix.equals("")) { + prefix = ArgumentChecker.escapeCharacters(prefix); + try { + user.setPermission("prefix.100." + prefix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + + if (suffix != null && !suffix.equals("")) { + suffix = ArgumentChecker.escapeCharacters(suffix); + try { + user.setPermission("suffix.100." + suffix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + plugin.getDatastore().saveUser(user); plugin.getUserManager().cleanup(user); } @@ -134,11 +152,29 @@ public class MigrationBungeePerms extends SubCommand { } catch (ObjectAlreadyHasException ignored) {} } + String prefix = g.getPrefix(); + String suffix = g.getSuffix(); + + if (prefix != null && !prefix.equals("")) { + prefix = ArgumentChecker.escapeCharacters(prefix); + try { + group.setPermission("prefix.50." + prefix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + + if (suffix != null && !suffix.equals("")) { + suffix = ArgumentChecker.escapeCharacters(suffix); + try { + group.setPermission("suffix.50." + suffix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + + + plugin.getDatastore().saveGroup(group); } log.info("BungeePerms Migration: Migrated " + groupCount + " groups"); - log.info("BungeePerms Migration: Success! Completed without any errors."); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationGroupManager.java b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationGroupManager.java index d4709f19b..2c123782c 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationGroupManager.java +++ b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationGroupManager.java @@ -168,6 +168,7 @@ public class MigrationGroupManager extends SubCommand { } log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process."); + log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups."); for (Map.Entry> e : users.entrySet()) { plugin.getDatastore().loadOrCreateUser(e.getKey(), "null"); diff --git a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationPermissionsEx.java b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationPermissionsEx.java index 90d72cd99..eff539595 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationPermissionsEx.java +++ b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationPermissionsEx.java @@ -32,6 +32,7 @@ import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; +import me.lucko.luckperms.utils.ArgumentChecker; import ru.tehkode.permissions.NativeInterface; import ru.tehkode.permissions.PermissionGroup; import ru.tehkode.permissions.PermissionManager; @@ -120,6 +121,7 @@ public class MigrationPermissionsEx extends SubCommand { // Migrate all users log.info("PermissionsEx Migration: Starting user migration."); + int userCount = 0; for (PermissionUser user : manager.getUsers()) { UUID u = null; @@ -147,6 +149,7 @@ public class MigrationPermissionsEx extends SubCommand { continue; } + userCount++; plugin.getDatastore().loadOrCreateUser(u, "null"); User lpUser = plugin.getUserManager().get(u); @@ -198,13 +201,34 @@ public class MigrationPermissionsEx extends SubCommand { } } + String prefix = user.getOwnPrefix(); + String suffix = user.getOwnSuffix(); + + if (prefix != null && !prefix.equals("")) { + prefix = ArgumentChecker.escapeCharacters(prefix); + try { + lpUser.setPermission("prefix.100." + prefix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + + if (suffix != null && !suffix.equals("")) { + suffix = ArgumentChecker.escapeCharacters(suffix); + try { + lpUser.setPermission("suffix.100." + suffix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + plugin.getUserManager().cleanup(lpUser); plugin.getDatastore().saveUser(lpUser); } + log.info("PermissionsEx Migration: Migrated " + userCount + " users."); + // Migrate all groups. log.info("PermissionsEx Migration: Starting group migration."); + int groupCount = 0; for (PermissionGroup group : manager.getGroupList()) { + groupCount ++; final String name = group.getName().toLowerCase(); plugin.getDatastore().createAndLoadGroup(name); Group lpGroup = plugin.getGroupManager().get(name); @@ -256,8 +280,27 @@ public class MigrationPermissionsEx extends SubCommand { } } } + + String prefix = group.getOwnPrefix(); + String suffix = group.getOwnSuffix(); + + if (prefix != null && !prefix.equals("")) { + prefix = ArgumentChecker.escapeCharacters(prefix); + try { + lpGroup.setPermission("prefix.50." + prefix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + + if (suffix != null && !suffix.equals("")) { + suffix = ArgumentChecker.escapeCharacters(suffix); + try { + lpGroup.setPermission("suffix.50." + suffix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + } + log.info("PermissionsEx Migration: Migrated " + groupCount + " groups"); log.info("PermissionsEx Migration: Success! Completed without any errors."); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationZPermissions.java b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationZPermissions.java index a6900a976..47b248bc9 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationZPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/commands/migration/subcommands/MigrationZPermissions.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.users.User; +import me.lucko.luckperms.utils.ArgumentChecker; import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService; import java.util.List; @@ -97,6 +98,24 @@ public class MigrationZPermissions extends SubCommand { } user.setPrimaryGroup(service.getPlayerPrimaryGroup(u)); + + String prefix = service.getPlayerPrefix(u); + String suffix = service.getPlayerSuffix(u); + + if (prefix != null && !prefix.equals("")) { + prefix = ArgumentChecker.escapeCharacters(prefix); + try { + user.setPermission("prefix.100." + prefix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + + if (suffix != null && !suffix.equals("")) { + suffix = ArgumentChecker.escapeCharacters(suffix); + try { + user.setPermission("suffix.100." + suffix, true); + } catch (ObjectAlreadyHasException ignored) {} + } + plugin.getUserManager().cleanup(user); plugin.getDatastore().saveUser(user); } diff --git a/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java b/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java index 8bcc675fc..1bc8efbbd 100644 --- a/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java +++ b/common/src/main/java/me/lucko/luckperms/utils/ArgumentChecker.java @@ -48,4 +48,12 @@ public class ArgumentChecker { return DateUtil.shouldExpire(l); } + public static String escapeCharacters(String s) { + s = s.replace(".", "{SEP}"); + s = s.replace("/", "{FSEP}"); + s = s.replace("$", "{DSEP}"); + + return s; + } + }