Search in sources :

Example 1 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method removeExact.

@Override
public Difference<Node> removeExact(Node node) {
    ImmutableContextSet context = node.getContexts();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.get(context);
        if (nodes == null) {
            return result;
        }
        // try to remove an exact match
        if (nodes.remove(node)) {
            // if we removed something, record to results
            result.recordChange(ChangeType.REMOVE, node);
            // update inheritance map too if necessary
            if (node instanceof InheritanceNode && node.getValue()) {
                SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.get(context);
                if (inhNodes != null) {
                    inhNodes.remove(node);
                }
            }
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 2 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method removeIf.

@Override
public Difference<Node> removeIf(ContextSet contextSet, Predicate<? super Node> predicate) {
    ImmutableContextSet context = contextSet.immutableCopy();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.get(context);
        if (nodes == null) {
            return result;
        }
        removeMatching(nodes.iterator(), predicate, result);
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 3 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method remove.

@Override
public Difference<Node> remove(Node node) {
    ImmutableContextSet context = node.getContexts();
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        SortedSet<Node> nodes = this.map.get(context);
        if (nodes == null) {
            return result;
        }
        // remove any nodes that match, record to results
        removeMatching(nodes.iterator(), node, result);
        // update inheritance map too
        if (node instanceof InheritanceNode) {
            SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.get(context);
            if (inhNodes != null) {
                inhNodes.removeIf(el -> node.equals(el, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
            }
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Difference(me.lucko.luckperms.common.util.Difference)

Example 4 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class NodeMapMutable method addAll.

@Override
public Difference<Node> addAll(Iterable<? extends Node> set) {
    Difference<Node> result = new Difference<>();
    this.lock.lock();
    try {
        for (Node n : set) {
            result.mergeFrom(add(n));
        }
    } finally {
        this.lock.unlock();
    }
    return result;
}
Also used : Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) Difference(me.lucko.luckperms.common.util.Difference)

Example 5 with Difference

use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.

the class SqlStorage method saveUser.

@Override
public void saveUser(User user) throws SQLException {
    Difference<Node> changes = user.normalData().exportChanges(results -> {
        if (this.plugin.getUserManager().isNonDefaultUser(user)) {
            return true;
        }
        // if the only change is adding the default node, we don't need to export
        if (results.getChanges().size() == 1) {
            Difference.Change<Node> onlyChange = results.getChanges().iterator().next();
            return !(onlyChange.type() == Difference.ChangeType.ADD && this.plugin.getUserManager().isDefaultNode(onlyChange.value()));
        }
        return true;
    });
    if (changes == null) {
        try (Connection c = this.connectionFactory.getConnection()) {
            deleteUser(c, user.getUniqueId());
        }
        return;
    }
    try (Connection c = this.connectionFactory.getConnection()) {
        updateUserPermissions(c, user.getUniqueId(), changes.getAdded(), changes.getRemoved());
        insertPlayerData(c, user.getUniqueId(), new SqlPlayerData(user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME), user.getUsername().orElse("null").toLowerCase(Locale.ROOT)));
    }
}
Also used : Node(net.luckperms.api.node.Node) Connection(java.sql.Connection) Difference(me.lucko.luckperms.common.util.Difference)

Aggregations

Difference (me.lucko.luckperms.common.util.Difference)9 Node (net.luckperms.api.node.Node)9 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)7 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)5 Connection (java.sql.Connection)1 ApiPermissionHolder (me.lucko.luckperms.common.api.implementation.ApiPermissionHolder)1