From 6c0bb61cb16313fc41bbe6073882535aa8e21fef Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 1 Mar 2018 11:03:22 +0000 Subject: [PATCH] Remove sponge migration commands --- .../impl/migration/MigrationMainCommand.java | 3 - .../migration/MigrationPermissionManager.java | 143 ------------- .../migration/MigrationPermissionsEx.java | 195 ------------------ .../migration/SpongeMigrationUtils.java | 123 ----------- 4 files changed, 464 deletions(-) delete mode 100644 sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java delete mode 100644 sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java delete mode 100644 sponge/src/main/java/me/lucko/luckperms/sponge/migration/SpongeMigrationUtils.java diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/migration/MigrationMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/migration/MigrationMainCommand.java index 41e340bd..c50c556c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/migration/MigrationMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/migration/MigrationMainCommand.java @@ -58,9 +58,6 @@ public class MigrationMainCommand extends MainCommand { .put("me.lucko.luckperms.bukkit.migration.MigrationPermissionsBukkit", "com.platymuus.bukkit.permissions.PermissionsPlugin") // bungee .put("me.lucko.luckperms.bungee.migration.MigrationBungeePerms", "net.alpenblock.bungeeperms.BungeePerms") - // sponge - .put("me.lucko.luckperms.sponge.migration.MigrationPermissionsEx", "ninja.leaping.permissionsex.sponge.PermissionsExPlugin") - .put("me.lucko.luckperms.sponge.migration.MigrationPermissionManager", "io.github.djxy.permissionmanager.sponge.SpongePlugin") .build().inverse(); private final ReentrantLock lock = new ReentrantLock(); 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 deleted file mode 100644 index c2c32357..00000000 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * 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.sponge.migration; - -import me.lucko.luckperms.api.event.cause.CreationCause; -import me.lucko.luckperms.common.commands.CommandPermission; -import me.lucko.luckperms.common.commands.CommandResult; -import me.lucko.luckperms.common.commands.abstraction.SubCommand; -import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils; -import me.lucko.luckperms.common.commands.sender.Sender; -import me.lucko.luckperms.common.locale.CommandSpec; -import me.lucko.luckperms.common.locale.LocaleManager; -import me.lucko.luckperms.common.logging.ProgressLogger; -import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.User; -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.Predicates; -import me.lucko.luckperms.common.utils.SafeIteration; -import me.lucko.luckperms.common.utils.Uuids; -import me.lucko.luckperms.sponge.LPSpongePlugin; -import me.lucko.luckperms.sponge.service.LuckPermsService; - -import org.spongepowered.api.Sponge; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.service.permission.PermissionService; - -import java.lang.reflect.Method; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject; -import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubjectData; - -public class MigrationPermissionManager extends SubCommand { - public MigrationPermissionManager(LocaleManager locale) { - super(CommandSpec.MIGRATION_COMMAND.spec(locale), "permissionmanager", CommandPermission.MIGRATION, Predicates.alwaysFalse()); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) { - ProgressLogger log = new ProgressLogger("PermissionManager"); - log.addListener(plugin.getConsoleSender()); - log.addListener(sender); - - log.log("Starting."); - - final LuckPermsService lpService = ((LPSpongePlugin) plugin).getService(); - - Optional pm = Sponge.getPluginManager().getPlugin("permissionmanager"); - if (!pm.isPresent()) { - log.logError("Plugin not loaded."); - return CommandResult.STATE_ERROR; - } - - // Get PM's PermissionService - PermissionService pmService; - - try { - Object pmPlugin = pm.get().getInstance().get(); - Method method = pmPlugin.getClass().getDeclaredMethod("getPermissionService"); - pmService = (PermissionService) method.invoke(pmPlugin); - } catch (Throwable t) { - t.printStackTrace(); - return CommandResult.FAILURE; - } - - // Migrate defaults - log.log("Migrating default subjects."); - SafeIteration.iterate(pmService.getKnownSubjects().values(), collection -> { - migrateSubjectData( - collection.getDefaults().getSubjectData(), - lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData() - ); - }); - migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData()); - - // Migrate groups - log.log("Starting group migration."); - AtomicInteger groupCount = new AtomicInteger(0); - SafeIteration.iterate(pmService.getGroupSubjects().getAllSubjects(), pmGroup -> { - String pmName = MigrationUtils.standardizeName(pmGroup.getIdentifier()); - - // Make a LuckPerms group for the one being migrated - Group group = plugin.getStorage().createAndLoadGroup(pmName, CreationCause.INTERNAL).join(); - migrateSubject(pmGroup, group, 100); - plugin.getStorage().saveGroup(group); - - log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet()); - }); - log.log("Migrated " + groupCount.get() + " groups"); - - // Migrate users - log.log("Starting user migration."); - AtomicInteger userCount = new AtomicInteger(0); - SafeIteration.iterate(pmService.getUserSubjects().getAllSubjects(), pmUser -> { - UUID uuid = Uuids.parseNullable(pmUser.getIdentifier()); - if (uuid == null) { - log.logError("Could not parse UUID for user: " + pmUser.getIdentifier()); - return; - } - - // Make a LuckPerms user for the one being migrated - User user = plugin.getStorage().loadUser(uuid, "null").join(); - if (user.getEnduringNodes().size() <= 1) { - user.clearNodes(false); - } - migrateSubject(pmUser, user, 100); - plugin.getStorage().saveUser(user); - plugin.getUserManager().cleanup(user); - - log.logProgress("Migrated {} users so far.", userCount.incrementAndGet()); - }); - - log.log("Migrated " + userCount.get() + " users."); - log.log("Success! Migration complete."); - return CommandResult.SUCCESS; - } -} 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 deleted file mode 100644 index c039e99e..00000000 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * 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.sponge.migration; - -import me.lucko.luckperms.api.event.cause.CreationCause; -import me.lucko.luckperms.common.commands.CommandPermission; -import me.lucko.luckperms.common.commands.CommandResult; -import me.lucko.luckperms.common.commands.abstraction.SubCommand; -import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils; -import me.lucko.luckperms.common.commands.sender.Sender; -import me.lucko.luckperms.common.locale.CommandSpec; -import me.lucko.luckperms.common.locale.LocaleManager; -import me.lucko.luckperms.common.logging.ProgressLogger; -import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.Track; -import me.lucko.luckperms.common.model.User; -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.Predicates; -import me.lucko.luckperms.common.utils.SafeIteration; -import me.lucko.luckperms.common.utils.Uuids; -import me.lucko.luckperms.sponge.LPSpongePlugin; -import me.lucko.luckperms.sponge.service.LuckPermsService; - -import org.spongepowered.api.Sponge; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.service.permission.PermissionService; -import org.spongepowered.api.service.permission.Subject; - -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.OptionalInt; -import java.util.TreeMap; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject; -import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubjectData; - -public class MigrationPermissionsEx extends SubCommand { - public MigrationPermissionsEx(LocaleManager locale) { - super(CommandSpec.MIGRATION_COMMAND.spec(locale), "permissionsex", CommandPermission.MIGRATION, Predicates.alwaysFalse()); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) { - ProgressLogger log = new ProgressLogger("PermissionsEx"); - log.addListener(plugin.getConsoleSender()); - log.addListener(sender); - - log.log("Starting."); - - final LuckPermsService lpService = ((LPSpongePlugin) plugin).getService(); - - Optional pex = Sponge.getPluginManager().getPlugin("permissionsex"); - if (!pex.isPresent()) { - log.logError("Plugin not loaded."); - return CommandResult.STATE_ERROR; - } - - // Cast to PermissionService. PEX has all of it's damned classes defined as package private. - PermissionService pexService = (PermissionService) pex.get().getInstance().get(); - - // Migrate defaults - log.log("Migrating default subjects."); - SafeIteration.iterate(pexService.getKnownSubjects().values(), collection -> { - migrateSubjectData( - collection.getDefaults().getSubjectData(), - lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData() - ); - }); - migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData()); - - log.log("Calculating group weightings."); - int i = 0; - for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) { - Optional pos = pexGroup.getOption("rank"); - if (pos.isPresent()) { - try { - i = Math.max(i, Integer.parseInt(pos.get())); - } catch (NumberFormatException ignored) {} - } - } - int maxWeight = i + 5; - - Map> tracks = new HashMap<>(); - - // Migrate groups - log.log("Starting group migration."); - AtomicInteger groupCount = new AtomicInteger(0); - SafeIteration.iterate(pexService.getGroupSubjects().getAllSubjects(), pexGroup -> { - String pexName = MigrationUtils.standardizeName(pexGroup.getIdentifier()); - - Optional rankString = pexGroup.getOption("rank"); - OptionalInt rank = OptionalInt.empty(); - if (rankString.isPresent()) { - try { - int r = Integer.parseInt(rankString.get()); - rank = OptionalInt.of(r); - } catch (NumberFormatException ignored) {} - } - - int weight = 100; - if (rank.isPresent()) { - weight = maxWeight - rank.getAsInt(); - } - - // Make a LuckPerms group for the one being migrated - Group group = plugin.getStorage().createAndLoadGroup(pexName, CreationCause.INTERNAL).join(); - migrateSubject(pexGroup, group, weight); - plugin.getStorage().saveGroup(group); - - // Pull track data - Optional track = pexGroup.getOption("rank-ladder"); - if (track.isPresent() && rank.isPresent()) { - String trackName = MigrationUtils.standardizeName(track.get()); - if (!tracks.containsKey(trackName)) { - tracks.put(trackName, new TreeMap<>(Comparator.reverseOrder())); - } - tracks.get(trackName).put(rank.getAsInt(), pexName); - } - - log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet()); - }); - log.log("Migrated " + groupCount.get() + " groups"); - - // Migrate tracks - log.log("Starting track migration."); - SafeIteration.iterate(tracks.entrySet(), e -> { - Track track = plugin.getStorage().createAndLoadTrack(e.getKey(), CreationCause.INTERNAL).join(); - for (String groupName : e.getValue().values()) { - Group group = plugin.getGroupManager().getIfLoaded(groupName); - if (group != null) { - track.appendGroup(group); - } - } - }); - log.log("Migrated " + tracks.size() + " tracks"); - - // Migrate users - log.log("Starting user migration."); - AtomicInteger userCount = new AtomicInteger(0); - - // Increment the max weight from the group migrations. All user meta should override. - int userWeight = maxWeight + 5; - - SafeIteration.iterate(pexService.getUserSubjects().getAllSubjects(), pexUser -> { - UUID uuid = Uuids.parseNullable(pexUser.getIdentifier()); - if (uuid == null) { - log.logError("Could not parse UUID for user: " + pexUser.getIdentifier()); - return; - } - - // Make a LuckPerms user for the one being migrated - User user = plugin.getStorage().loadUser(uuid, null).join(); - if (user.getEnduringNodes().size() <= 1) { - user.clearNodes(false); - } - migrateSubject(pexUser, user, userWeight); - plugin.getStorage().saveUser(user); - plugin.getUserManager().cleanup(user); - - log.logProgress("Migrated {} users so far.", userCount.incrementAndGet()); - }); - - log.log("Migrated " + userCount.get() + " users."); - log.log("Success! Migration complete."); - return CommandResult.SUCCESS; - } -} 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 deleted file mode 100644 index c68cd513..00000000 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/SpongeMigrationUtils.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * 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.sponge.migration; - -import me.lucko.luckperms.api.context.ContextSet; -import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils; -import me.lucko.luckperms.common.model.Group; -import me.lucko.luckperms.common.model.PermissionHolder; -import me.lucko.luckperms.common.node.NodeFactory; -import me.lucko.luckperms.sponge.service.CompatibilityUtil; - -import org.spongepowered.api.service.context.Context; -import org.spongepowered.api.service.permission.PermissionService; -import org.spongepowered.api.service.permission.Subject; -import org.spongepowered.api.service.permission.SubjectData; -import org.spongepowered.api.util.Tristate; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -public final class SpongeMigrationUtils { - - public static void migrateSubject(Subject from, PermissionHolder to, int priority) { - if (to.getType().isGroup()) { - MigrationUtils.setGroupWeight((Group) to, priority); - } - - // Migrate permissions - Map, Map> perms = from.getSubjectData().getAllPermissions(); - for (Map.Entry, Map> e : perms.entrySet()) { - ContextSet context = CompatibilityUtil.convertContexts(e.getKey()); - - for (Map.Entry perm : e.getValue().entrySet()) { - if (perm.getKey().isEmpty()) { - continue; - } - - to.setPermission(NodeFactory.builder(perm.getKey()).withExtraContext(context).setValue(perm.getValue()).build()); - } - } - - // Migrate options - Map, Map> opts = from.getSubjectData().getAllOptions(); - for (Map.Entry, Map> e : opts.entrySet()) { - ContextSet context = CompatibilityUtil.convertContexts(e.getKey()); - - for (Map.Entry opt : e.getValue().entrySet()) { - if (opt.getKey().isEmpty() || opt.getValue().isEmpty()) { - continue; - } - - if (opt.getKey().equalsIgnoreCase(NodeFactory.PREFIX_KEY)) { - to.setPermission(NodeFactory.buildPrefixNode(priority, opt.getValue()).withExtraContext(context).setValue(true).build()); - } else if (opt.getKey().equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) { - to.setPermission(NodeFactory.buildSuffixNode(priority, opt.getValue()).withExtraContext(context).setValue(true).build()); - } else { - to.setPermission(NodeFactory.buildMetaNode(opt.getKey(), opt.getValue()).withExtraContext(context).setValue(true).build()); - } - } - } - - // Migrate parents - Map, List> parents = from.getSubjectData().getAllParents(); - for (Map.Entry, List> e : parents.entrySet()) { - ContextSet context = CompatibilityUtil.convertContexts(e.getKey()); - - for (Subject s : e.getValue()) { - if (!s.getContainingCollection().getIdentifier().equalsIgnoreCase(PermissionService.SUBJECTS_GROUP)) { - continue; // LuckPerms does not support persisting other subject types. - } - - to.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(s.getIdentifier())).withExtraContext(context).setValue(true).build()); - } - } - } - - public static void migrateSubjectData(SubjectData from, SubjectData to) { - for (Map.Entry, Map> e : from.getAllPermissions().entrySet()) { - for (Map.Entry e1 : e.getValue().entrySet()) { - to.setPermission(e.getKey(), e1.getKey(), Tristate.fromBoolean(e1.getValue())); - } - } - - for (Map.Entry, Map> e : from.getAllOptions().entrySet()) { - for (Map.Entry e1 : e.getValue().entrySet()) { - to.setOption(e.getKey(), e1.getKey(), e1.getValue()); - } - } - - for (Map.Entry, List> e : from.getAllParents().entrySet()) { - for (Subject s : e.getValue()) { - to.addParent(e.getKey(), s); - } - } - } - - private SpongeMigrationUtils() {} - -}