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