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>
<groupId>org.tyrannyofheaven.bukkit</groupId>
<artifactId>zPermissions</artifactId>
<version>1.3</version>
<version>1.3.1-SNAPSHOT</version>
<scope>provided</scope>
</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.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<Object> {
public MigrationZPermissions() {
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());
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<Object> {
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<Object> {
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()) {
if (e.getWorld() != null) {
try {
@ -133,15 +135,22 @@ public class MigrationZPermissions extends SubCommand<Object> {
}
}
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) {
}
}
}