mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Remove sponge migration commands
This commit is contained in:
parent
d9a45b1090
commit
6c0bb61cb1
@ -58,9 +58,6 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
|||||||
.put("me.lucko.luckperms.bukkit.migration.MigrationPermissionsBukkit", "com.platymuus.bukkit.permissions.PermissionsPlugin")
|
.put("me.lucko.luckperms.bukkit.migration.MigrationPermissionsBukkit", "com.platymuus.bukkit.permissions.PermissionsPlugin")
|
||||||
// bungee
|
// bungee
|
||||||
.put("me.lucko.luckperms.bungee.migration.MigrationBungeePerms", "net.alpenblock.bungeeperms.BungeePerms")
|
.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();
|
.build().inverse();
|
||||||
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
|
@ -1,143 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of LuckPerms, licensed under the MIT License.
|
|
||||||
*
|
|
||||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
|
||||||
* 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<Object> {
|
|
||||||
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<String> 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<PluginContainer> 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,195 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of LuckPerms, licensed under the MIT License.
|
|
||||||
*
|
|
||||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
|
||||||
* 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<Object> {
|
|
||||||
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<String> 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<PluginContainer> 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<String> pos = pexGroup.getOption("rank");
|
|
||||||
if (pos.isPresent()) {
|
|
||||||
try {
|
|
||||||
i = Math.max(i, Integer.parseInt(pos.get()));
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int maxWeight = i + 5;
|
|
||||||
|
|
||||||
Map<String, TreeMap<Integer, String>> 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<String> 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<String> 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of LuckPerms, licensed under the MIT License.
|
|
||||||
*
|
|
||||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
|
||||||
* 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<Set<Context>, Map<String, Boolean>> perms = from.getSubjectData().getAllPermissions();
|
|
||||||
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) {
|
|
||||||
ContextSet context = CompatibilityUtil.convertContexts(e.getKey());
|
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) {
|
|
||||||
if (perm.getKey().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
to.setPermission(NodeFactory.builder(perm.getKey()).withExtraContext(context).setValue(perm.getValue()).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate options
|
|
||||||
Map<Set<Context>, Map<String, String>> opts = from.getSubjectData().getAllOptions();
|
|
||||||
for (Map.Entry<Set<Context>, Map<String, String>> e : opts.entrySet()) {
|
|
||||||
ContextSet context = CompatibilityUtil.convertContexts(e.getKey());
|
|
||||||
|
|
||||||
for (Map.Entry<String, String> 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<Set<Context>, List<Subject>> parents = from.getSubjectData().getAllParents();
|
|
||||||
for (Map.Entry<Set<Context>, List<Subject>> 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<Set<Context>, Map<String, Boolean>> e : from.getAllPermissions().entrySet()) {
|
|
||||||
for (Map.Entry<String, Boolean> e1 : e.getValue().entrySet()) {
|
|
||||||
to.setPermission(e.getKey(), e1.getKey(), Tristate.fromBoolean(e1.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<Set<Context>, Map<String, String>> e : from.getAllOptions().entrySet()) {
|
|
||||||
for (Map.Entry<String, String> e1 : e.getValue().entrySet()) {
|
|
||||||
to.setOption(e.getKey(), e1.getKey(), e1.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<Set<Context>, List<Subject>> e : from.getAllParents().entrySet()) {
|
|
||||||
for (Subject s : e.getValue()) {
|
|
||||||
to.addParent(e.getKey(), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private SpongeMigrationUtils() {}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user