Search in sources :

Example 6 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(ContextSet filter) {
    Set<LPSubjectReference> parents;
    Set<LPSubjectReference> merging;
    switch(getParentCollection().getResolutionOrder()) {
        case TRANSIENT_FIRST:
            parents = getTransientSubjectData().resolveParents(filter);
            merging = getSubjectData().resolveParents(filter);
            break;
        case TRANSIENT_LAST:
            parents = getSubjectData().resolveParents(filter);
            merging = getTransientSubjectData().resolveParents(filter);
            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 7 with LPSubjectReference

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

the class ParentInfo method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
    if (contextSet.isEmpty()) {
        MessageUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
        Map<ImmutableContextSet, ImmutableList<LPSubjectReference>> parents = subjectData.getAllParents();
        if (parents.isEmpty()) {
            MessageUtils.sendPluginMessage(sender, "That subject does not have any parents defined.");
            return CommandResult.SUCCESS;
        }
        for (Map.Entry<ImmutableContextSet, ImmutableList<LPSubjectReference>> e : parents.entrySet()) {
            MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
        }
    } else {
        List<LPSubjectReference> parents = subjectData.getParents(contextSet);
        if (parents.isEmpty()) {
            MessageUtils.sendPluginMessage(sender, "That subject does not have any parents defined in those contexts.");
            return CommandResult.SUCCESS;
        }
        MessageUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
    }
    return CommandResult.SUCCESS;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) Map(java.util.Map)

Example 8 with LPSubjectReference

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

the class HolderSubjectData method getAllParents.

@Override
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
    ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> ret = ImmutableMap.builder();
    for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getNodes(this.type).asMap().entrySet()) {
        ImmutableList.Builder<LPSubjectReference> builder = ImmutableList.builder();
        for (Node n : entry.getValue()) {
            if (n.isGroupNode()) {
                builder.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
            }
        }
        ret.put(entry.getKey(), builder.build());
    }
    return ret.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Node(me.lucko.luckperms.api.Node) Collection(java.util.Collection) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with LPSubjectReference

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

the class SubjectDataContainer method serialize.

/**
 * Converts this container to json
 *
 * @return a json serialisation of the data in this container
 */
public JsonObject serialize() {
    JsonObject root = new JsonObject();
    JsonArray permissions = new JsonArray();
    for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : sortContextMap(this.permissions)) {
        if (e.getValue().isEmpty()) {
            continue;
        }
        JsonObject section = new JsonObject();
        section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
        JsonObject data = new JsonObject();
        // sort alphabetically.
        List<Map.Entry<String, Boolean>> perms = new ArrayList<>(e.getValue().entrySet());
        perms.sort(Map.Entry.comparingByKey(CollationKeyCache.comparator()));
        for (Map.Entry<String, Boolean> ent : perms) {
            data.addProperty(ent.getKey(), ent.getValue());
        }
        section.add("data", data);
        permissions.add(section);
    }
    root.add("permissions", permissions);
    JsonArray options = new JsonArray();
    for (Map.Entry<ImmutableContextSet, Map<String, String>> e : sortContextMap(this.options)) {
        if (e.getValue().isEmpty()) {
            continue;
        }
        JsonObject section = new JsonObject();
        section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
        JsonObject data = new JsonObject();
        // sort alphabetically.
        List<Map.Entry<String, String>> opts = new ArrayList<>(e.getValue().entrySet());
        opts.sort(Map.Entry.comparingByKey(CollationKeyCache.comparator()));
        for (Map.Entry<String, String> ent : opts) {
            data.addProperty(ent.getKey(), ent.getValue());
        }
        section.add("data", data);
        options.add(section);
    }
    root.add("options", options);
    JsonArray parents = new JsonArray();
    for (Map.Entry<ImmutableContextSet, List<LPSubjectReference>> e : sortContextMap(this.parents)) {
        if (e.getValue().isEmpty()) {
            continue;
        }
        JsonObject section = new JsonObject();
        section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
        JsonArray data = new JsonArray();
        for (LPSubjectReference ref : e.getValue()) {
            JsonObject parent = new JsonObject();
            parent.addProperty("collection", ref.getCollectionIdentifier());
            parent.addProperty("subject", ref.getSubjectIdentifier());
            data.add(parent);
        }
        section.add("data", data);
        options.add(section);
    }
    root.add("parents", parents);
    return root;
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) JsonArray(com.google.gson.JsonArray) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 10 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() {
    SubjectInheritanceGraph graph = SubjectInheritanceGraphs.getGraph();
    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()) {
            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