Migrate PEX primary groups

This commit is contained in:
Luck 2016-08-29 17:57:47 +01:00
parent 35cb5b81dc
commit 3ddbf1da87
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -404,6 +404,22 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
}
String primary = null;
int weight = -100;
for (PermissionGroup group : user.getOwnParents()) {
if (group.getRank() > weight) {
primary = group.getName();
weight = group.getWeight();
}
}
if (primary != null) {
try {
lpUser.setPermission("group." + primary.toLowerCase(), true);
} catch (ObjectAlreadyHasException ignored) {}
lpUser.setPrimaryGroup(primary);
}
plugin.getUserManager().cleanup(lpUser);
plugin.getDatastore().saveUser(lpUser);
}