Search in sources :

Example 1 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class AbstractConfigurateStorage method readAttributes.

private static Node readAttributes(NodeBuilder<?, ?> builder, ConfigurationNode attributes) {
    long expiryVal = attributes.getNode("expiry").getLong(0L);
    Instant expiry = expiryVal == 0L ? null : Instant.ofEpochSecond(expiryVal);
    ImmutableContextSet context = readContexts(attributes);
    return builder.expiry(expiry).context(context).build();
}
Also used : Instant(java.time.Instant) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 2 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.

the class AbstractConfigurateStorage method readContexts.

private static ImmutableContextSet readContexts(ConfigurationNode attributes) {
    ImmutableContextSet.Builder contextBuilder = new ImmutableContextSetImpl.BuilderImpl();
    ConfigurationNode contextMap = attributes.getNode("context");
    if (!contextMap.isVirtual() && contextMap.isMap()) {
        contextBuilder.addAll(ContextSetConfigurateSerializer.deserializeContextSet(contextMap));
    }
    String server = attributes.getNode("server").getString("global");
    contextBuilder.add(DefaultContextKeys.SERVER_KEY, server);
    String world = attributes.getNode("world").getString("global");
    contextBuilder.add(DefaultContextKeys.WORLD_KEY, world);
    return contextBuilder.build();
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 3 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet 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 4 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet 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 5 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet 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)

Aggregations

ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)35 Map (java.util.Map)10 Node (net.luckperms.api.node.Node)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)8 HashMap (java.util.HashMap)5 List (java.util.List)5 Locale (java.util.Locale)5 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)5 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)5 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)5 Difference (me.lucko.luckperms.common.util.Difference)5 DataType (net.luckperms.api.model.data.DataType)5 ImmutableList (com.google.common.collect.ImmutableList)4 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)4 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)4 GenericChildCommand (me.lucko.luckperms.common.command.abstraction.GenericChildCommand)4 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)4 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)4 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)4