Search in sources :

Example 26 with ImmutableContextSet

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

the class PermissionClear method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    ImmutableContextSet contextSet = args.getContextOrEmpty(0);
    if (contextSet.isEmpty()) {
        subjectData.clearPermissions();
        SpongeCommandUtils.sendPrefixed(sender, "&aCleared permissions matching contexts &bANY&a.");
    } else {
        subjectData.clearPermissions(contextSet);
        SpongeCommandUtils.sendPrefixed(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
    }
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 27 with ImmutableContextSet

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

the class CalculatedSubjectData method resolvePermissions.

public Map<String, Node> resolvePermissions(QueryOptions filter) {
    // get relevant entries
    SortedMap<ImmutableContextSet, Map<String, Node>> sorted = new TreeMap<>(ContextSetComparator.reverse());
    for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> entry : this.permissions.entrySet()) {
        if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) {
            continue;
        }
        Map<String, Node> nodeMap = new HashMap<>();
        entry.getValue().forEach((key, value) -> {
            PermissionNode node = Permission.builder().permission(key).value(value).context(entry.getKey()).withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
            nodeMap.put(key, node);
        });
        sorted.put(entry.getKey(), nodeMap);
    }
    // flatten
    Map<String, Node> result = new HashMap<>();
    for (Map<String, Node> map : sorted.values()) {
        for (Map.Entry<String, Node> e : map.entrySet()) {
            result.putIfAbsent(e.getKey(), e.getValue());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Node(net.luckperms.api.node.Node) PermissionNode(net.luckperms.api.node.types.PermissionNode) MetaNode(net.luckperms.api.node.types.MetaNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) PermissionNode(net.luckperms.api.node.types.PermissionNode)

Example 28 with ImmutableContextSet

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

the class CalculatedSubjectData method resolveOptions.

public Map<String, MetaNode> resolveOptions(QueryOptions filter) {
    // get relevant entries
    SortedMap<ImmutableContextSet, Map<String, MetaNode>> sorted = new TreeMap<>(ContextSetComparator.reverse());
    for (Map.Entry<ImmutableContextSet, Map<String, String>> entry : this.options.entrySet()) {
        if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) {
            continue;
        }
        Map<String, MetaNode> nodeMap = new HashMap<>();
        entry.getValue().forEach((key, value) -> {
            MetaNode node = Meta.builder().key(key).value(value).context(entry.getKey()).withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
            nodeMap.put(key, node);
        });
        sorted.put(entry.getKey(), nodeMap);
    }
    // flatten
    Map<String, MetaNode> result = new HashMap<>();
    for (Map<String, MetaNode> map : sorted.values()) {
        for (Map.Entry<String, MetaNode> e : map.entrySet()) {
            result.putIfAbsent(e.getKey(), e.getValue());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MetaNode(net.luckperms.api.node.types.MetaNode) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 29 with ImmutableContextSet

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

the class PermissionHolderSubjectData method getAllParents.

@Override
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
    ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> parents = ImmutableMap.builder();
    for (Map.Entry<ImmutableContextSet, Collection<InheritanceNode>> entry : this.holder.getData(this.type).inheritanceAsMap().entrySet()) {
        ImmutableList.Builder<LPSubjectReference> builder = ImmutableList.builder();
        for (InheritanceNode n : entry.getValue()) {
            builder.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
        }
        parents.put(entry.getKey(), builder.build());
    }
    return parents.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) Collection(java.util.Collection) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(net.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 30 with ImmutableContextSet

use of net.luckperms.api.context.ImmutableContextSet 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.serialize(e.getKey()));
        JsonObject data = new JsonObject();
        // sort alphabetically.
        List<Map.Entry<String, Boolean>> perms = new ArrayList<>(e.getValue().entrySet());
        perms.sort(Map.Entry.comparingByKey());
        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.serialize(e.getKey()));
        JsonObject data = new JsonObject();
        // sort alphabetically.
        List<Map.Entry<String, String>> opts = new ArrayList<>(e.getValue().entrySet());
        opts.sort(Map.Entry.comparingByKey());
        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.serialize(e.getKey()));
        JsonArray data = new JsonArray();
        for (LPSubjectReference ref : e.getValue()) {
            JsonObject parent = new JsonObject();
            parent.addProperty("collection", ref.collectionIdentifier());
            parent.addProperty("subject", ref.subjectIdentifier());
            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(net.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)

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