From e5e77ffec59bac3b329064420b41a50dbab4125c Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 12 Dec 2016 19:51:21 +0000 Subject: [PATCH] Add PEX track migration - closes #78 --- .../migration/MigrationPermissionsEx.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) 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 901a275d..0a732e96 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 @@ -31,8 +31,10 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; +import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.Predicates; +import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.service.LuckPermsService; @@ -42,8 +44,12 @@ import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.SubjectCollection; +import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.TreeMap; import java.util.UUID; import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject; @@ -77,6 +83,8 @@ public class MigrationPermissionsEx extends SubCommand { MigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData()); + Map> tracks = new HashMap<>(); + // Migrate groups log.info("PermissionsEx Migration: Starting group migration."); int groupCount = 0; @@ -90,9 +98,41 @@ public class MigrationPermissionsEx extends SubCommand { Group group = plugin.getGroupManager().getIfLoaded(pexName); migrateSubject(pexGroup, group); plugin.getStorage().saveGroup(group); + + // Pull track data + Optional track = pexGroup.getOption("rank-ladder"); + Optional pos = pexGroup.getOption("rank"); + if (track.isPresent() && pos.isPresent()) { + String trackName = track.get().toLowerCase(); + try { + int rank = Integer.parseInt(pos.get()); + if (!tracks.containsKey(trackName)) { + tracks.put(trackName, new TreeMap<>(Comparator.reverseOrder())); + } + + tracks.get(trackName).put(rank, pexName); + } catch (NumberFormatException ignored) {} + } + } log.info("PermissionsEx Migration: Migrated " + groupCount + " groups"); + // Migrate tracks + log.info("PermissionsEx Migration: Starting track migration."); + for (Map.Entry> e : tracks.entrySet()) { + plugin.getStorage().createAndLoadTrack(e.getKey()).join(); + Track track = plugin.getTrackManager().getIfLoaded(e.getKey()); + for (String groupName : e.getValue().values()) { + Group group = plugin.getGroupManager().getIfLoaded(groupName); + if (group != null) { + try { + track.appendGroup(group); + } catch (ObjectAlreadyHasException ignored) {} + } + } + } + log.info("PermissionsEx Migration: Migrated " + tracks.size() + " tracks"); + // Migrate users log.info("PermissionsEx Migration: Starting user migration."); int userCount = 0;