Sponge: also migrate defaults
This commit is contained in:
parent
2d88405d69
commit
aeeb2820f9
@ -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<Object> {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
final Logger log = plugin.getLog();
|
||||
final LuckPermsService lpService = ((LPSpongePlugin) plugin).getService();
|
||||
|
||||
Optional<PluginContainer> pex = Sponge.getPluginManager().getPlugin("permissionsex");
|
||||
if (!pex.isPresent()) {
|
||||
@ -62,6 +66,16 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// 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;
|
||||
|
@ -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<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>, 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>, List<Subject>> e : from.getAllParents().entrySet()) {
|
||||
for (Subject s : e.getValue()) {
|
||||
to.addParent(e.getKey(), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user