Migrate group weightings onto the group itself as well as to the chat meta held by it

This commit is contained in:
Luck 2017-03-11 18:24:25 +00:00
parent bce7fa871d
commit 7305c6c54b
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 33 additions and 12 deletions

View File

@ -29,6 +29,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -103,6 +104,9 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
Group lpGroup = plugin.getGroupManager().getIfLoaded(name);
lpGroup.removeIf(n -> n.getPermission().startsWith("weight."));
lpGroup.setPermissionUnchecked(NodeFactory.make("weight." + groupWeight, true));
try {
for (String node : group.getOwnPermissions(null)) {
boolean value = true;

View File

@ -172,6 +172,9 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(name);
group.removeIf(n -> n.getPermission().startsWith("weight."));
group.setPermissionUnchecked(NodeFactory.make("weight." + g.getRank(), true));
for (Permission p : g.getOwnPermissions()) {
applyPerm(group, p);
}

View File

@ -76,6 +76,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
@ -403,6 +404,24 @@ public abstract class PermissionHolder {
invalidateCache(true);
}
public boolean removeIf(Predicate<Node> predicate) {
boolean result;
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
result = nodes.removeIf(predicate);
}
if (!result) {
return false;
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
return true;
}
public Set<Node> getTransientNodes() {
return transientCache.get();
}

View File

@ -47,6 +47,9 @@ public class MigrationUtils {
public static void migrateSubject(Subject subject, PermissionHolder holder, int priority) {
holder.removeIf(n -> n.getPermission().startsWith("weight."));
holder.setPermissionUnchecked(NodeFactory.make("weight." + priority, true));
// Migrate permissions
Map<Set<Context>, Map<String, Boolean>> perms = subject.getSubjectData().getAllPermissions();
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) {
@ -77,17 +80,11 @@ public class MigrationUtils {
for (Map.Entry<String, String> opt : e.getValue().entrySet()) {
if (opt.getKey().equalsIgnoreCase("prefix")) {
try {
holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
} catch (ObjectAlreadyHasException ignored) {}
holder.setPermissionUnchecked(NodeFactory.makePrefixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
} else if (opt.getKey().equalsIgnoreCase("suffix")) {
try {
holder.setPermission(NodeFactory.makeSuffixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
} catch (ObjectAlreadyHasException ignored) {}
holder.setPermissionUnchecked(NodeFactory.makeSuffixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
} else {
try {
holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
} catch (ObjectAlreadyHasException ignored) {}
holder.setPermissionUnchecked(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
}
}
}
@ -110,9 +107,7 @@ public class MigrationUtils {
continue; // LuckPerms does not support persisting other subject types.
}
try {
holder.setPermission(new NodeBuilder("group." + convertName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
} catch (ObjectAlreadyHasException ignored) {}
holder.setPermissionUnchecked(new NodeBuilder("group." + convertName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
}
}
}