Cleanup migration commands
This commit is contained in:
+5
-4
@@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
@@ -50,7 +51,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject;
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject;
|
||||
|
||||
public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
public MigrationPermissionManager() {
|
||||
@@ -88,12 +89,12 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
// Migrate defaults
|
||||
log.log("Migrating default subjects.");
|
||||
for (SubjectCollection collection : pmService.getKnownSubjects().values()) {
|
||||
MigrationUtils.migrateSubjectData(
|
||||
SpongeMigrationUtils.migrateSubjectData(
|
||||
collection.getDefaults().getSubjectData(),
|
||||
lpService.getSubjects("defaults").get(collection.getIdentifier()).getSubjectData()
|
||||
);
|
||||
}
|
||||
MigrationUtils.migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
SpongeMigrationUtils.migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
|
||||
// Migrate groups
|
||||
log.log("Starting group migration.");
|
||||
@@ -108,7 +109,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (Subject pmGroup : pmService.getGroupSubjects().getAllSubjects()) {
|
||||
String pmName = MigrationUtils.convertName(pmGroup.getIdentifier());
|
||||
String pmName = MigrationUtils.standardizeName(pmGroup.getIdentifier());
|
||||
|
||||
// Make a LuckPerms group for the one being migrated
|
||||
plugin.getStorage().createAndLoadGroup(pmName, CreationCause.INTERNAL).join();
|
||||
|
||||
+6
-5
@@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
@@ -55,7 +56,7 @@ import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject;
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject;
|
||||
|
||||
public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
public MigrationPermissionsEx() {
|
||||
@@ -84,12 +85,12 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Migrate defaults
|
||||
log.log("Migrating default subjects.");
|
||||
for (SubjectCollection collection : pexService.getKnownSubjects().values()) {
|
||||
MigrationUtils.migrateSubjectData(
|
||||
SpongeMigrationUtils.migrateSubjectData(
|
||||
collection.getDefaults().getSubjectData(),
|
||||
lpService.getSubjects("defaults").get(collection.getIdentifier()).getSubjectData()
|
||||
);
|
||||
}
|
||||
MigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
SpongeMigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
|
||||
log.log("Calculating group weightings.");
|
||||
int maxWeight = 0;
|
||||
@@ -110,7 +111,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
log.log("Starting group migration.");
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
||||
String pexName = MigrationUtils.convertName(pexGroup.getIdentifier());
|
||||
String pexName = MigrationUtils.standardizeName(pexGroup.getIdentifier());
|
||||
|
||||
Optional<String> rankString = pexGroup.getOption("rank");
|
||||
OptionalInt rank = OptionalInt.empty();
|
||||
@@ -135,7 +136,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Pull track data
|
||||
Optional<String> track = pexGroup.getOption("rank-ladder");
|
||||
if (track.isPresent() && rank.isPresent()) {
|
||||
String trackName = MigrationUtils.convertName(track.get());
|
||||
String trackName = MigrationUtils.standardizeName(track.get());
|
||||
if (!tracks.containsKey(trackName)) {
|
||||
tracks.put(trackName, new TreeMap<>(Comparator.reverseOrder()));
|
||||
}
|
||||
|
||||
+8
-12
@@ -25,11 +25,12 @@ package me.lucko.luckperms.sponge.migration;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.core.NodeBuilder;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.sponge.service.proxy.Util;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@@ -43,12 +44,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class MigrationUtils {
|
||||
public class SpongeMigrationUtils {
|
||||
|
||||
public static void migrateSubject(Subject subject, PermissionHolder holder, int priority) {
|
||||
|
||||
holder.removeIf(n -> n.getPermission().startsWith("weight."));
|
||||
holder.setPermissionUnchecked(NodeFactory.make("weight." + priority, true));
|
||||
if (holder instanceof Group) {
|
||||
MigrationUtils.setGroupWeight((Group) holder, priority);
|
||||
}
|
||||
|
||||
// Migrate permissions
|
||||
Map<Set<Context>, Map<String, Boolean>> perms = subject.getSubjectData().getAllPermissions();
|
||||
@@ -61,9 +63,7 @@ public class MigrationUtils {
|
||||
String world = extractedContexts.getWorld();
|
||||
|
||||
for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) {
|
||||
try {
|
||||
holder.setPermission(new NodeBuilder(perm.getKey()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
holder.setPermissionUnchecked(new NodeBuilder(perm.getKey()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class MigrationUtils {
|
||||
continue; // LuckPerms does not support persisting other subject types.
|
||||
}
|
||||
|
||||
holder.setPermissionUnchecked(new NodeBuilder("group." + convertName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermissionUnchecked(new NodeBuilder("group." + MigrationUtils.standardizeName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,8 +132,4 @@ public class MigrationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertName(String s) {
|
||||
return s.replace(' ', '_').toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user