Fix some issues with null world contexts in migration scripts

This commit is contained in:
Luck 2019-12-13 11:51:42 +00:00
parent 06f7900318
commit dce792083b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 7 additions and 10 deletions

View File

@ -86,7 +86,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
} }
final boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0)); final boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0));
final Function<String, String> worldMappingFunc = s -> migrateAsGlobal ? null : s; final Function<String, String> worldMappingFunc = s -> migrateAsGlobal || s == null ? "global" : s;
if (!Bukkit.getPluginManager().isPluginEnabled("GroupManager")) { if (!Bukkit.getPluginManager().isPluginEnabled("GroupManager")) {
log.logError("Plugin not loaded."); log.logError("Plugin not loaded.");
@ -145,7 +145,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
} }
for (String s : group.getInherits()) { for (String s : group.getInherits()) {
if (s.isEmpty()) continue; if (s.isEmpty()) continue;
groups.get(groupName).add(Inheritance.builder(MigrationUtils.standardizeName(s)).value(true).withContext(DefaultContextKeys.SERVER_KEY, null).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); groups.get(groupName).add(Inheritance.builder(MigrationUtils.standardizeName(s)).value(true).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build());
} }
String[] metaKeys = group.getVariables().getVarKeyList(); String[] metaKeys = group.getVariables().getVarKeyList();

View File

@ -313,12 +313,9 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
} }
private static String standardizeWorld(String world) { private static String standardizeWorld(String world) {
if (world != null && (world.isEmpty() || world.equals("*"))) { if (world == null || world.isEmpty() || world.equals("*")) {
world = null; world = "global";
} }
if (world != null) { return world.toLowerCase();
world = world.toLowerCase();
}
return world;
} }
} }

View File

@ -309,7 +309,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
server = "global"; server = "global";
} }
NodeBuilder nb = NodeBuilders.determineMostApplicable(node).value(value); NodeBuilder<?, ?> nb = NodeBuilders.determineMostApplicable(node).value(value);
if (expireAt != 0) nb.expiry(expireAt); if (expireAt != 0) nb.expiry(expireAt);
if (server != null) nb.withContext(DefaultContextKeys.SERVER_KEY, server); if (server != null) nb.withContext(DefaultContextKeys.SERVER_KEY, server);
if (world != null) nb.withContext(DefaultContextKeys.WORLD_KEY, world); if (world != null) nb.withContext(DefaultContextKeys.WORLD_KEY, world);
@ -325,7 +325,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
expireAt = g.getExpirationDate().getTime() / 1000L; expireAt = g.getExpirationDate().getTime() / 1000L;
} }
NodeBuilder nb = Inheritance.builder(MigrationUtils.standardizeName(group.getName())); NodeBuilder<?, ?> nb = Inheritance.builder(MigrationUtils.standardizeName(group.getName()));
if (expireAt != 0) { if (expireAt != 0) {
nb.expiry(expireAt); nb.expiry(expireAt);