Search in sources :

Example 1 with LPSubjectReference

use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.

the class SubjectReferenceFactory method obtain.

public LPSubjectReference obtain(LPSubject subject) {
    Objects.requireNonNull(subject, "subject");
    LPSubjectReference ret = obtain(subject.getParentCollection().getIdentifier(), subject.getIdentifier());
    ((CachedSubjectReference) ret).fillCache(subject);
    return ret;
}
Also used : LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference)

Example 2 with LPSubjectReference

use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.

the class CalculatedSubject method getCombinedParents.

public Set<LPSubjectReference> getCombinedParents() {
    Set<LPSubjectReference> parents;
    Set<LPSubjectReference> merging;
    switch(getParentCollection().getResolutionOrder()) {
        case TRANSIENT_FIRST:
            parents = getTransientSubjectData().resolveParents();
            merging = getSubjectData().resolveParents();
            break;
        case TRANSIENT_LAST:
            parents = getSubjectData().resolveParents();
            merging = getTransientSubjectData().resolveParents();
            break;
        default:
            throw new AssertionError();
    }
    for (LPSubjectReference entry : merging) {
        if (!parents.contains(entry)) {
            parents.add(entry);
        }
    }
    return parents;
}
Also used : LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference)

Example 3 with LPSubjectReference

use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.

the class CalculatedSubjectData method resolveParents.

public Set<LPSubjectReference> resolveParents() {
    // get relevant entries
    SortedMap<ImmutableContextSet, Set<LPSubjectReference>> sorted = new TreeMap<>(ContextSetComparator.reverse());
    for (Map.Entry<ImmutableContextSet, Set<LPSubjectReference>> entry : this.parents.entrySet()) {
        sorted.put(entry.getKey(), entry.getValue());
    }
    // flatten
    Set<LPSubjectReference> result = new LinkedHashSet<>();
    for (Set<LPSubjectReference> set : sorted.values()) {
        for (LPSubjectReference e : set) {
            if (!result.contains(e)) {
                result.add(e);
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ContextSet(me.lucko.luckperms.api.context.ContextSet) LinkedHashSet(java.util.LinkedHashSet) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 4 with LPSubjectReference

use of me.lucko.luckperms.sponge.service.model.LPSubjectReference 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 5 with LPSubjectReference

use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.

the class CalculatedSubject method resolveAllParents.

public Set<LPSubjectReference> resolveAllParents(ImmutableContextSet filter) {
    SubjectInheritanceGraph graph = SubjectInheritanceGraphs.getGraph(filter);
    Set<LPSubjectReference> result = new LinkedHashSet<>();
    Iterable<CalculatedSubject> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this);
    for (CalculatedSubject subject : traversal) {
        for (LPSubjectReference entry : subject.getCombinedParents(filter)) {
            if (!result.contains(entry)) {
                result.add(entry);
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SubjectInheritanceGraph(me.lucko.luckperms.sponge.service.inheritance.SubjectInheritanceGraph)

Aggregations

LPSubjectReference (me.lucko.luckperms.sponge.service.model.LPSubjectReference)11 Map (java.util.Map)5 ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 LinkedHashSet (java.util.LinkedHashSet)4 HashMap (java.util.HashMap)3 Set (java.util.Set)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ContextSet (me.lucko.luckperms.api.context.ContextSet)2 SubjectInheritanceGraph (me.lucko.luckperms.sponge.service.inheritance.SubjectInheritanceGraph)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Node (me.lucko.luckperms.api.Node)1 InheritanceGraph (me.lucko.luckperms.common.inheritance.InheritanceGraph)1