Search in sources :

Example 21 with ImmutableContextSet

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

the class ParentRemove method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
    String collection = args.get(0);
    String name = args.get(1);
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
    LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
        MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
    }
    LPSubjectCollection c = service.getCollection(collection);
    if (!c.hasRegistered(name).join()) {
        MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
    }
    LPSubject subject = c.loadSubject(name).join();
    if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
        MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
    }
    return CommandResult.SUCCESS;
}
Also used : LPPermissionService(me.lucko.luckperms.sponge.service.model.LPPermissionService) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection)

Example 22 with ImmutableContextSet

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

the class PermissionInfo 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 permissions matching contexts &bANY&a.");
        Map<ImmutableContextSet, ImmutableMap<String, Boolean>> permissions = subjectData.getAllPermissions();
        if (permissions.isEmpty()) {
            MessageUtils.sendPluginMessage(sender, "That subject does not have any permissions defined.");
            return CommandResult.SUCCESS;
        }
        for (Map.Entry<ImmutableContextSet, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
            MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
        }
    } else {
        Map<String, Boolean> permissions = subjectData.getPermissions(contextSet);
        if (permissions.isEmpty()) {
            MessageUtils.sendPluginMessage(sender, "That subject does not have any permissions defined in those contexts.");
            return CommandResult.SUCCESS;
        }
        MessageUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
    }
    return CommandResult.SUCCESS;
}
Also used : ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 23 with ImmutableContextSet

use of me.lucko.luckperms.api.context.ImmutableContextSet 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 24 with ImmutableContextSet

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

the class HolderSubjectData method setOption.

@Override
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
    Objects.requireNonNull(contexts, "contexts");
    Objects.requireNonNull(key, "key");
    Objects.requireNonNull(value, "value");
    Node node;
    if (key.equalsIgnoreCase(NodeFactory.PREFIX_KEY) || key.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
        // special handling.
        ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
        // remove all prefixes/suffixes from the user
        List<Node> toRemove = streamNodes().filter(type::matches).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
        toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
        MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, this.service.getPlugin().getContextManager().formContexts(contexts));
        int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
        priority += 10;
        node = NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build();
    } else {
        // standard remove
        List<Node> toRemove = streamNodes().filter(n -> n.isMeta() && n.getMeta().getKey().equals(key)).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
        toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
        node = NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build();
    }
    this.type.run(() -> this.holder.setPermission(node), () -> this.holder.setTransientPermission(node));
    return objectSave(this.holder).thenApply(v -> true);
}
Also used : DataMutateResult(me.lucko.luckperms.api.DataMutateResult) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) Tristate(me.lucko.luckperms.api.Tristate) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PermissionService(org.spongepowered.api.service.permission.PermissionService) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SubjectData(org.spongepowered.api.service.permission.SubjectData) ProxyFactory(me.lucko.luckperms.sponge.service.proxy.ProxyFactory) ImmutableMap(com.google.common.collect.ImmutableMap) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Collection(java.util.Collection) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) List(java.util.List) Stream(java.util.stream.Stream) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) NodeMapType(me.lucko.luckperms.common.model.NodeMapType) User(me.lucko.luckperms.common.model.User) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) Node(me.lucko.luckperms.api.Node) ChatMetaType(me.lucko.luckperms.api.ChatMetaType)

Example 25 with ImmutableContextSet

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

the class HolderSubjectData method getAllPermissions.

@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
    ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> ret = ImmutableMap.builder();
    for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getNodes(this.type).asMap().entrySet()) {
        ImmutableMap.Builder<String, Boolean> builder = ImmutableMap.builder();
        for (Node n : entry.getValue()) {
            builder.put(n.getPermission(), n.getValuePrimitive());
        }
        ret.put(entry.getKey(), builder.build());
    }
    return ret.build();
}
Also used : Node(me.lucko.luckperms.api.Node) Collection(java.util.Collection) 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)

Aggregations

ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)27 Map (java.util.Map)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 HashMap (java.util.HashMap)6 LPSubjectReference (me.lucko.luckperms.sponge.service.model.LPSubjectReference)6 Node (me.lucko.luckperms.api.Node)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)3 JsonObject (com.google.gson.JsonObject)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Tristate (me.lucko.luckperms.api.Tristate)2 ContextSet (me.lucko.luckperms.api.context.ContextSet)2 NodeModel (me.lucko.luckperms.common.node.NodeModel)2