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
This commit is contained in:
Slind14 2016-12-07 23:13:50 +01:00 committed by Luck
parent 2da7979d94
commit 74bb079625
2 changed files with 25 additions and 16 deletions

View File

@ -149,7 +149,7 @@
<dependency> <dependency>
<groupId>org.tyrannyofheaven.bukkit</groupId> <groupId>org.tyrannyofheaven.bukkit</groupId>
<artifactId>zPermissions</artifactId> <artifactId>zPermissions</artifactId>
<version>1.3</version> <version>1.3.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -39,16 +39,14 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService; import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionService; import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionService;
import org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata; import org.tyrannyofheaven.bukkit.zPermissions.model.*;
import org.tyrannyofheaven.bukkit.zPermissions.model.Entry;
import org.tyrannyofheaven.bukkit.zPermissions.model.Inheritance;
import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class MigrationZPermissions extends SubCommand<Object> { public class MigrationZPermissions extends SubCommand<Object> {
public MigrationZPermissions() { public MigrationZPermissions() {
super("zpermissions", "Migration from zPermissions", Permission.MIGRATION, Predicates.alwaysFalse(), null); super("zpermissions", "Migration from zPermissions", Permission.MIGRATION, Predicates.alwaysFalse(), null);
} }
@ -85,7 +83,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase()); Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase());
PermissionEntity entity = internalService.getEntity(g, null, true); PermissionEntity entity = internalService.getEntity(g, null, true);
migrateEntity(group, entity); migrateEntity(group, entity, null);
plugin.getStorage().saveGroup(group); plugin.getStorage().saveGroup(group);
} }
@ -106,10 +104,14 @@ public class MigrationZPermissions extends SubCommand<Object> {
User user = plugin.getUserManager().get(u); User user = plugin.getUserManager().get(u);
PermissionEntity entity = internalService.getEntity(null, u, false); PermissionEntity entity = internalService.getEntity(null, u, false);
migrateEntity(user, entity); migrateEntity(user, entity, internalService.getGroups(u));
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u)); user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
if (!entity.isGroup()) {
user.setName(entity.getDisplayName());
}
plugin.getUserManager().cleanup(user); plugin.getUserManager().cleanup(user);
plugin.getStorage().saveUser(user); plugin.getStorage().saveUser(user);
} }
@ -118,7 +120,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
private void migrateEntity(PermissionHolder group, PermissionEntity entity) { private void migrateEntity(PermissionHolder group, PermissionEntity entity, List<Membership> memberships) {
for (Entry e : entity.getPermissions()) { for (Entry e : entity.getPermissions()) {
if (e.getWorld() != null) { if (e.getWorld() != null) {
try { try {
@ -133,15 +135,22 @@ public class MigrationZPermissions extends SubCommand<Object> {
} }
} }
for (Inheritance inheritance : entity.getInheritancesAsChild()) { if (entity.isGroup()) {
if (!inheritance.getChild().getId().equals(entity.getId())) { for (Inheritance inheritance : entity.getInheritancesAsChild()) {
new Throwable("Illegal inheritance").printStackTrace(); try {
continue; if (!inheritance.getParent().getName().equals(group.getObjectName())) {
group.setPermission("group." + inheritance.getParent().getName(), true);
}
} catch (ObjectAlreadyHasException ignored) {
}
} }
} else {
try { // entity.getMemberships() doesn't work (always returns 0 records)
group.setPermission("group." + inheritance.getParent(), true); for (Membership membership : memberships) {
} catch (ObjectAlreadyHasException ignored) { try {
group.setPermission("group." + membership.getGroup().getDisplayName(), true);
} catch (ObjectAlreadyHasException ignored) {
}
} }
} }