From 74bb0796254bb87142ad10ee3c8631e48ff8b391 Mon Sep 17 00:00:00 2001 From: Slind14 Date: Wed, 7 Dec 2016 23:13:50 +0100 Subject: [PATCH] Fix zPermissions imports (PR #72, fixes #61) * removed zPerm inherit loop check. (blocked the import due to throwing NPE) * should fix zperm migration (group inheritance and memberships) * zperm import, include username * zperm import: fixed memberships --- bukkit/pom.xml | 2 +- .../migration/MigrationZPermissions.java | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 70e6cecc2..4e652cc10 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -149,7 +149,7 @@ org.tyrannyofheaven.bukkit zPermissions - 1.3 + 1.3.1-SNAPSHOT provided diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 95b7af4ac..b2bc24ce3 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -39,16 +39,14 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService; import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionService; -import org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata; -import org.tyrannyofheaven.bukkit.zPermissions.model.Entry; -import org.tyrannyofheaven.bukkit.zPermissions.model.Inheritance; -import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity; +import org.tyrannyofheaven.bukkit.zPermissions.model.*; import java.lang.reflect.Field; import java.util.List; import java.util.UUID; public class MigrationZPermissions extends SubCommand { + public MigrationZPermissions() { super("zpermissions", "Migration from zPermissions", Permission.MIGRATION, Predicates.alwaysFalse(), null); } @@ -85,7 +83,7 @@ public class MigrationZPermissions extends SubCommand { Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase()); PermissionEntity entity = internalService.getEntity(g, null, true); - migrateEntity(group, entity); + migrateEntity(group, entity, null); plugin.getStorage().saveGroup(group); } @@ -106,10 +104,14 @@ public class MigrationZPermissions extends SubCommand { User user = plugin.getUserManager().get(u); PermissionEntity entity = internalService.getEntity(null, u, false); - migrateEntity(user, entity); + migrateEntity(user, entity, internalService.getGroups(u)); user.setPrimaryGroup(service.getPlayerPrimaryGroup(u)); + if (!entity.isGroup()) { + user.setName(entity.getDisplayName()); + } + plugin.getUserManager().cleanup(user); plugin.getStorage().saveUser(user); } @@ -118,7 +120,7 @@ public class MigrationZPermissions extends SubCommand { return CommandResult.SUCCESS; } - private void migrateEntity(PermissionHolder group, PermissionEntity entity) { + private void migrateEntity(PermissionHolder group, PermissionEntity entity, List memberships) { for (Entry e : entity.getPermissions()) { if (e.getWorld() != null) { try { @@ -133,15 +135,22 @@ public class MigrationZPermissions extends SubCommand { } } - for (Inheritance inheritance : entity.getInheritancesAsChild()) { - if (!inheritance.getChild().getId().equals(entity.getId())) { - new Throwable("Illegal inheritance").printStackTrace(); - continue; + if (entity.isGroup()) { + for (Inheritance inheritance : entity.getInheritancesAsChild()) { + try { + if (!inheritance.getParent().getName().equals(group.getObjectName())) { + group.setPermission("group." + inheritance.getParent().getName(), true); + } + } catch (ObjectAlreadyHasException ignored) { + } } - - try { - group.setPermission("group." + inheritance.getParent(), true); - } catch (ObjectAlreadyHasException ignored) { + } else { + // entity.getMemberships() doesn't work (always returns 0 records) + for (Membership membership : memberships) { + try { + group.setPermission("group." + membership.getGroup().getDisplayName(), true); + } catch (ObjectAlreadyHasException ignored) { + } } }