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 5106a640..027afc7b 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 @@ -33,10 +33,13 @@ import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.utils.Predicates; +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 org.spongepowered.api.service.permission.SubjectCollection; import java.util.List; import java.util.Optional; @@ -52,6 +55,7 @@ public class MigrationPermissionsEx extends SubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { final Logger log = plugin.getLog(); + final LuckPermsService lpService = ((LPSpongePlugin) plugin).getService(); Optional pex = Sponge.getPluginManager().getPlugin("permissionsex"); if (!pex.isPresent()) { @@ -62,6 +66,16 @@ public class MigrationPermissionsEx extends SubCommand { // Cast to PermissionService. PEX has all of it's damned classes defined as package private. PermissionService pexService = (PermissionService) pex.get().getInstance().get(); + // Migrate defaults + for (SubjectCollection collection : pexService.getKnownSubjects().values()) { + MigrationUtils.migrateSubjectData( + collection.getDefaults().getSubjectData(), + lpService.getSubjects("defaults").get(collection.getIdentifier()).getSubjectData() + ); + } + + MigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData()); + // Migrate groups log.info("PermissionsEx Migration: Starting group migration."); int groupCount = 0; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java index a0a840fa..8320d1d7 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.sponge.service.LuckPermsService; 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; @@ -113,4 +115,24 @@ public class MigrationUtils { } } + public static void migrateSubjectData(SubjectData from, SubjectData to) { + 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, 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, List> e : from.getAllParents().entrySet()) { + for (Subject s : e.getValue()) { + to.addParent(e.getKey(), s); + } + } + } + }