Search in sources :

Example 36 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method exportNodesAndShorthand.

public Map<String, Boolean> exportNodesAndShorthand(Contexts context, boolean lowerCase) {
    List<LocalizedNode> entries = getAllEntries(context);
    Map<String, Boolean> perms = new HashMap<>();
    boolean applyShorthand = this.plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
    for (Node node : entries) {
        String perm = lowerCase ? node.getPermission().toLowerCase() : node.getPermission();
        if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null) {
            if (applyShorthand) {
                List<String> shorthand = node.resolveShorthand();
                if (!shorthand.isEmpty()) {
                    for (String s : shorthand) {
                        perms.putIfAbsent(lowerCase ? s.toLowerCase() : s, node.getValuePrimitive());
                    }
                }
            }
        }
    }
    return ImmutableMap.copyOf(perms);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode)

Example 37 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method accumulateMeta.

public MetaAccumulator accumulateMeta(MetaAccumulator accumulator, Contexts context) {
    if (accumulator == null) {
        accumulator = MetaAccumulator.makeFromConfig(this.plugin);
    }
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(context);
    Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
    for (PermissionHolder holder : traversal) {
        List<Node> nodes = holder.getOwnNodes(context.getContexts());
        for (Node node : nodes) {
            if (!node.getValuePrimitive())
                continue;
            if (!node.isMeta() && !node.isPrefix() && !node.isSuffix())
                continue;
            if (!((context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER) || node.isServerSpecific()) && (context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD) || node.isWorldSpecific()))) {
                continue;
            }
            accumulator.accumulateNode(ImmutableLocalizedNode.of(node, holder.getObjectName()));
        }
        OptionalInt w = holder.getWeight();
        if (w.isPresent()) {
            accumulator.accumulateWeight(w.getAsInt());
        }
    }
    return accumulator;
}
Also used : LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) OptionalInt(java.util.OptionalInt) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 38 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method accumulateInheritancesTo.

private void accumulateInheritancesTo(List<LocalizedNode> accumulator) {
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph();
    Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
    for (PermissionHolder holder : traversal) {
        List<Node> nodes = holder.getOwnNodes();
        for (Node node : nodes) {
            ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(node, holder.getObjectName());
            accumulator.add(localizedNode);
        }
    }
}
Also used : ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 39 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method getAllEntries.

private List<LocalizedNode> getAllEntries(Contexts context) {
    List<LocalizedNode> entries = new LinkedList<>();
    if (context.hasSetting(LookupSetting.RESOLVE_INHERITANCE)) {
        accumulateInheritancesTo(entries, context);
    } else {
        for (Node n : getOwnNodes(context.getContexts())) {
            ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(n, getObjectName());
            entries.add(localizedNode);
        }
    }
    if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER)) {
        entries.removeIf(n -> !n.isGroupNode() && !n.isServerSpecific());
    }
    if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD)) {
        entries.removeIf(n -> !n.isGroupNode() && !n.isWorldSpecific());
    }
    return entries;
}
Also used : ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) LinkedList(java.util.LinkedList)

Example 40 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method setPermission.

/**
 * Sets a permission node, applying a temporary modifier if the node is temporary.
 * @param node the node to set
 * @param modifier the modifier to use for the operation
 * @return the node that was actually set, respective of the modifier
 */
public Map.Entry<DataMutateResult, Node> setPermission(Node node, TemporaryModifier modifier) {
    // If the node is temporary, we should take note of the modifier
    if (node.isTemporary()) {
        if (modifier == TemporaryModifier.ACCUMULATE) {
            // Try to accumulate with an existing node
            Optional<Node> existing = searchForMatch(NodeMapType.ENDURING, node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE);
            // An existing node was found
            if (existing.isPresent()) {
                Node previous = existing.get();
                // Create a new node with the same properties, but add the expiry dates together
                Node newNode = node.toBuilder().setExpiry(previous.getExpiryUnixTime() + node.getSecondsTilExpiry()).build();
                // Remove the old node & add the new one.
                ImmutableCollection<Node> before = getEnduringNodes().values();
                this.enduringNodes.replace(newNode, previous);
                invalidateCache();
                ImmutableCollection<Node> after = getEnduringNodes().values();
                this.plugin.getEventFactory().handleNodeAdd(newNode, this, before, after);
                return Maps.immutableEntry(DataMutateResult.SUCCESS, newNode);
            }
        } else if (modifier == TemporaryModifier.REPLACE) {
            // Try to replace an existing node
            Optional<Node> existing = searchForMatch(NodeMapType.ENDURING, node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE);
            // An existing node was found
            if (existing.isPresent()) {
                Node previous = existing.get();
                // Only replace if the new expiry time is greater than the old one.
                if (node.getExpiryUnixTime() > previous.getExpiryUnixTime()) {
                    ImmutableCollection<Node> before = getEnduringNodes().values();
                    this.enduringNodes.replace(node, previous);
                    invalidateCache();
                    ImmutableCollection<Node> after = getEnduringNodes().values();
                    this.plugin.getEventFactory().handleNodeAdd(node, this, before, after);
                    return Maps.immutableEntry(DataMutateResult.SUCCESS, node);
                }
            }
        }
    // DENY behaviour is the default anyways.
    }
    // Fallback to the normal handling.
    return Maps.immutableEntry(setPermission(node), node);
}
Also used : ImmutableCollection(com.google.common.collect.ImmutableCollection) Optional(java.util.Optional) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node)

Aggregations

Node (me.lucko.luckperms.api.Node)56 LocalizedNode (me.lucko.luckperms.api.LocalizedNode)15 Group (me.lucko.luckperms.common.model.Group)15 User (me.lucko.luckperms.common.model.User)13 Map (java.util.Map)12 ImmutableLocalizedNode (me.lucko.luckperms.common.node.ImmutableLocalizedNode)12 List (java.util.List)11 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)10 Message (me.lucko.luckperms.common.locale.message.Message)9 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)9 Sender (me.lucko.luckperms.common.sender.Sender)9 Collectors (java.util.stream.Collectors)8 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)8 CommandResult (me.lucko.luckperms.common.command.CommandResult)8 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)8 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)8 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)8 Predicates (me.lucko.luckperms.common.utils.Predicates)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7