Fix migrating weight with zPerms
This commit is contained in:
parent
4731ad8061
commit
6c4fa65f91
@ -93,14 +93,18 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
// Migrate all groups
|
// Migrate all groups
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
|
int maxWeight = 0;
|
||||||
for (String g : service.getAllGroups()) {
|
for (String g : service.getAllGroups()) {
|
||||||
String groupName = MigrationUtils.standardizeName(g);
|
PermissionEntity entity = internalService.getEntity(g, null, true);
|
||||||
|
|
||||||
|
String groupName = MigrationUtils.standardizeName(g);
|
||||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||||
|
|
||||||
PermissionEntity entity = internalService.getEntity(g, null, true);
|
int weight = entity.getPriority();
|
||||||
migrateEntity(group, entity, null);
|
maxWeight = Math.max(maxWeight, weight);
|
||||||
|
migrateEntity(group, entity, null, weight);
|
||||||
|
MigrationUtils.setGroupWeight(group, weight);
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
@ -124,6 +128,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Migrate all users.
|
// Migrate all users.
|
||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
|
maxWeight += 10;
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
for (UUID u : service.getAllPlayersUUID()) {
|
for (UUID u : service.getAllPlayersUUID()) {
|
||||||
PermissionEntity entity = internalService.getEntity(null, u, false);
|
PermissionEntity entity = internalService.getEntity(null, u, false);
|
||||||
@ -134,7 +139,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
plugin.getStorage().loadUser(u, username).join();
|
plugin.getStorage().loadUser(u, username).join();
|
||||||
User user = plugin.getUserManager().getIfLoaded(u);
|
User user = plugin.getUserManager().getIfLoaded(u);
|
||||||
migrateEntity(user, entity, internalService.getGroups(u));
|
migrateEntity(user, entity, internalService.getGroups(u), maxWeight);
|
||||||
user.getPrimaryGroup().setStoredValue(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u)));
|
user.getPrimaryGroup().setStoredValue(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u)));
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
@ -147,7 +152,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, List<Membership> memberships) {
|
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, List<Membership> memberships, int weight) {
|
||||||
for (Entry e : entity.getPermissions()) {
|
for (Entry e : entity.getPermissions()) {
|
||||||
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
|
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
|
||||||
holder.setPermission(NodeFactory.newBuilder(e.getPermission()).setValue(e.isValue()).setWorld(e.getWorld().getName()).build());
|
holder.setPermission(NodeFactory.newBuilder(e.getPermission()).setValue(e.isValue()).setWorld(e.getWorld().getName()).build());
|
||||||
@ -169,7 +174,6 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int weight = entity.isGroup() ? 50 : 100;
|
|
||||||
for (EntityMetadata metadata : entity.getMetadata()) {
|
for (EntityMetadata metadata : entity.getMetadata()) {
|
||||||
String key = metadata.getName().toLowerCase();
|
String key = metadata.getName().toLowerCase();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user