Search in sources :

Example 1 with InheritanceGraph

use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.

the class AllParentsByWeightHolder method calculateValue.

@Override
protected String calculateValue() {
    Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
    if (contexts == null) {
        contexts = this.user.getPlugin().getContextManager().getStaticContexts();
    }
    InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
    // fully traverse the graph, obtain a list of permission holders the user inherits from
    List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
    Group bestGroup = null;
    if (!traversal.isEmpty()) {
        int best = 0;
        for (PermissionHolder holder : traversal) {
            if (!(holder instanceof Group)) {
                continue;
            }
            Group g = ((Group) holder);
            int weight = g.getWeight().orElse(0);
            if (bestGroup == null || g.getWeight().orElse(0) > best) {
                bestGroup = g;
                best = weight;
            }
        }
    }
    return bestGroup == null ? null : bestGroup.getName();
}
Also used : Group(me.lucko.luckperms.common.model.Group) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Contexts(me.lucko.luckperms.api.Contexts) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 2 with InheritanceGraph

use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.

the class PermissionHolder method accumulateInheritancesTo.

private void accumulateInheritancesTo(List<LocalizedNode> accumulator, Contexts context) {
    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) {
            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 3 with InheritanceGraph

use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.

the class HolderSubject method getParents.

@Override
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(this.plugin.getContextManager().formContexts(contexts));
    Iterable<PermissionHolder> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this.parent);
    ImmutableList.Builder<LPSubjectReference> subjects = ImmutableList.builder();
    for (PermissionHolder parent : traversal) {
        if (!(parent instanceof Group)) {
            continue;
        }
        subjects.add(((SpongeGroup) parent).sponge().toReference());
    }
    return subjects.build();
}
Also used : Group(me.lucko.luckperms.common.model.Group) SpongeGroup(me.lucko.luckperms.sponge.model.SpongeGroup) ImmutableList(com.google.common.collect.ImmutableList) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SpongeGroup(me.lucko.luckperms.sponge.model.SpongeGroup) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 4 with InheritanceGraph

use of me.lucko.luckperms.common.inheritance.InheritanceGraph 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 5 with InheritanceGraph

use of me.lucko.luckperms.common.inheritance.InheritanceGraph 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)

Aggregations

InheritanceGraph (me.lucko.luckperms.common.inheritance.InheritanceGraph)6 LocalizedNode (me.lucko.luckperms.api.LocalizedNode)4 Node (me.lucko.luckperms.api.Node)4 ImmutableLocalizedNode (me.lucko.luckperms.common.node.ImmutableLocalizedNode)4 OptionalInt (java.util.OptionalInt)2 Group (me.lucko.luckperms.common.model.Group)2 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)2 ImmutableList (com.google.common.collect.ImmutableList)1 Contexts (me.lucko.luckperms.api.Contexts)1 SpongeGroup (me.lucko.luckperms.sponge.model.SpongeGroup)1 LPSubjectReference (me.lucko.luckperms.sponge.service.model.LPSubjectReference)1