mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Cleanup handling of empty permissions when migrating data (closes #387)
This commit is contained in:
parent
b4aeb04d1b
commit
90afd3c3ed
@ -270,7 +270,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
String primaryGroup = primaryGroups.get(e.getKey());
|
||||
if (primaryGroup != null) {
|
||||
if (primaryGroup != null && !primaryGroup.isEmpty()) {
|
||||
user.setPermission(NodeFactory.make("group." + primaryGroup));
|
||||
user.getPrimaryGroup().setStoredValue(primaryGroup);
|
||||
user.unsetPermission(NodeFactory.make("group.default"));
|
||||
|
@ -159,7 +159,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
if (primary != null && !primary.equalsIgnoreCase("default")) {
|
||||
if (primary != null && !primary.isEmpty() && !primary.equalsIgnoreCase("default")) {
|
||||
lpUser.setPermission(NodeFactory.make("group." + primary.toLowerCase()));
|
||||
lpUser.getPrimaryGroup().setStoredValue(primary);
|
||||
lpUser.unsetPermission(NodeFactory.make("group.default"));
|
||||
@ -216,11 +216,11 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
String prefix = entity.getOwnPrefix();
|
||||
String suffix = entity.getOwnSuffix();
|
||||
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
if (prefix != null && !prefix.isEmpty()) {
|
||||
holder.setPermission(NodeFactory.makePrefixNode(weight, prefix).build());
|
||||
}
|
||||
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
holder.setPermission(NodeFactory.makeSuffixNode(weight, suffix).build());
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
Map<String, Map<String, String>> options = entity.getAllOptions();
|
||||
for (Map.Entry<String, Map<String, String>> worldData : options.entrySet()) {
|
||||
String world = worldData.getKey();
|
||||
if (world != null && (world.equals("") || world.equals("*"))) {
|
||||
if (world != null && (world.isEmpty() || world.equals("*"))) {
|
||||
world = null;
|
||||
}
|
||||
if (world != null) {
|
||||
|
@ -181,6 +181,10 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
|
||||
// server --> prefix afaik
|
||||
for (Map.Entry<String, String> prefix : g.getPrefixes().entrySet()) {
|
||||
if (prefix.getValue().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String server = prefix.getKey().toLowerCase();
|
||||
if (prefix.getKey().equals("*") || prefix.getKey().equals("all")) {
|
||||
server = null;
|
||||
@ -194,6 +198,10 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> suffix : g.getSuffixes().entrySet()) {
|
||||
if (suffix.getValue().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String server = suffix.getKey().toLowerCase();
|
||||
if (suffix.getKey().equals("*") || suffix.getKey().equals("all")) {
|
||||
server = null;
|
||||
@ -247,11 +255,11 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
String prefix = joinFuture(pm.getPlayerOwnPrefix(uuid));
|
||||
String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
|
||||
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
if (prefix != null && !prefix.isEmpty()) {
|
||||
user.setPermission(NodeFactory.makePrefixNode(maxWeight, prefix).build());
|
||||
}
|
||||
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
user.setPermission(NodeFactory.makeSuffixNode(maxWeight, suffix).build());
|
||||
}
|
||||
|
||||
@ -279,6 +287,10 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
value = false;
|
||||
}
|
||||
|
||||
if (node.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String server = p.getServer();
|
||||
if (server != null && (server.equalsIgnoreCase("all") || server.equalsIgnoreCase("*"))) {
|
||||
server = null;
|
||||
@ -299,18 +311,9 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
Node.Builder nb = NodeFactory.newBuilder(node).setValue(value);
|
||||
|
||||
if (expireAt != 0) {
|
||||
nb.setExpiry(expireAt);
|
||||
}
|
||||
|
||||
if (server != null) {
|
||||
nb.setServer(server);
|
||||
}
|
||||
|
||||
if (world != null) {
|
||||
nb.setWorld(world);
|
||||
}
|
||||
if (expireAt != 0) nb.setExpiry(expireAt);
|
||||
if (server != null) nb.setServer(server);
|
||||
if (world != null) nb.setWorld(world);
|
||||
|
||||
holder.setPermission(nb.build());
|
||||
}
|
||||
|
@ -196,6 +196,10 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
|
||||
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, int weight) {
|
||||
for (Entry e : entity.getPermissions()) {
|
||||
if (e.getPermission().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
|
||||
holder.setPermission(NodeFactory.newBuilder(e.getPermission()).setValue(e.isValue()).setWorld(e.getWorld().getName()).build());
|
||||
} else {
|
||||
@ -215,6 +219,10 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
for (EntityMetadata metadata : entity.getMetadata()) {
|
||||
String key = metadata.getName().toLowerCase();
|
||||
|
||||
if (key.isEmpty() || metadata.getStringValue().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key.equals("prefix") || key.equals("suffix")) {
|
||||
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
||||
holder.setPermission(NodeFactory.makeChatMetaNode(type, weight, metadata.getStringValue()).build());
|
||||
|
@ -174,10 +174,10 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
String prefix = entity.getPrefix();
|
||||
String suffix = entity.getSuffix();
|
||||
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
if (prefix != null && !prefix.isEmpty()) {
|
||||
holder.setPermission(NodeFactory.makePrefixNode(weight, prefix).build());
|
||||
}
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
holder.setPermission(NodeFactory.makeSuffixNode(weight, suffix).build());
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,17 @@ public class MigrationUtils {
|
||||
|
||||
public static Node.Builder parseNode(String permission, boolean value) {
|
||||
if (permission.startsWith("-") || permission.startsWith("!")) {
|
||||
if (permission.length() == 1) {
|
||||
return NodeFactory.newBuilder(permission).setValue(value);
|
||||
}
|
||||
|
||||
permission = permission.substring(1);
|
||||
value = false;
|
||||
} else if (permission.startsWith("+")) {
|
||||
if (permission.length() == 1) {
|
||||
return NodeFactory.newBuilder(permission).setValue(value);
|
||||
}
|
||||
|
||||
permission = permission.substring(1);
|
||||
value = true;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject;
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubjectData;
|
||||
|
||||
public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
public MigrationPermissionManager(LocaleManager locale) {
|
||||
@ -93,12 +94,12 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
// Migrate defaults
|
||||
log.log("Migrating default subjects.");
|
||||
for (SubjectCollection collection : pmService.getKnownSubjects().values()) {
|
||||
SpongeMigrationUtils.migrateSubjectData(
|
||||
migrateSubjectData(
|
||||
collection.getDefaults().getSubjectData(),
|
||||
lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData()
|
||||
);
|
||||
}
|
||||
SpongeMigrationUtils.migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
||||
migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
||||
|
||||
// Migrate groups
|
||||
log.log("Starting group migration.");
|
||||
|
@ -62,6 +62,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject;
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubjectData;
|
||||
|
||||
public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
public MigrationPermissionsEx(LocaleManager locale) {
|
||||
@ -90,12 +91,12 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Migrate defaults
|
||||
log.log("Migrating default subjects.");
|
||||
for (SubjectCollection collection : pexService.getKnownSubjects().values()) {
|
||||
SpongeMigrationUtils.migrateSubjectData(
|
||||
migrateSubjectData(
|
||||
collection.getDefaults().getSubjectData(),
|
||||
lpService.getCollection("defaults").loadSubject(collection.getIdentifier()).join().sponge().getSubjectData()
|
||||
);
|
||||
}
|
||||
SpongeMigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
||||
migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().sponge().getSubjectData());
|
||||
|
||||
log.log("Calculating group weightings.");
|
||||
int maxWeight = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user