Search in sources :

Example 11 with ImmutableContextSet

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

the class ParentAdd method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    String collection = args.get(0);
    String name = args.get(1);
    ImmutableContextSet contextSet = args.getContextOrEmpty(2);
    LPPermissionService service = subjectData.getParentSubject().getService();
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
        SpongeCommandUtils.sendPrefixed(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't already exist.");
    }
    LPSubjectCollection c = service.getCollection(collection);
    if (!c.hasRegistered(name).join()) {
        SpongeCommandUtils.sendPrefixed(sender, "Warning: Subject '&4" + name + "&c' doesn't already exist.");
    }
    LPSubject subject = c.loadSubject(name).join();
    if (subjectData.addParent(contextSet, subject.toReference()).join()) {
        SpongeCommandUtils.sendPrefixed(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier().getName() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        SpongeCommandUtils.sendPrefixed(sender, "Unable to add parent. Does the Subject already have it added?");
    }
}
Also used : LPPermissionService(me.lucko.luckperms.sponge.service.model.LPPermissionService) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection)

Example 12 with ImmutableContextSet

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

the class PermissionSet method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) throws CommandException {
    String node = args.get(0);
    Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
    ImmutableContextSet contextSet = args.getContextOrEmpty(2);
    if (subjectData.setPermission(contextSet, node, tristate).join()) {
        SpongeCommandUtils.sendPrefixed(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase(Locale.ROOT) + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        SpongeCommandUtils.sendPrefixed(sender, "Unable to set permission. Does the Subject already have it set?");
    }
}
Also used : Tristate(net.luckperms.api.util.Tristate) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 13 with ImmutableContextSet

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

the class PermissionHolderSubjectData 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(Prefix.NODE_KEY) || key.equalsIgnoreCase(Suffix.NODE_KEY)) {
        // special handling.
        ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase(Locale.ROOT));
        // remove all prefixes/suffixes from the user
        this.holder.removeIf(this.type, contexts, type.nodeType()::matches, false);
        MetaAccumulator metaAccumulator = this.holder.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build());
        int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
        priority += 10;
        node = type.builder(value, priority).withContext(contexts).build();
    } else {
        // standard remove
        this.holder.removeIf(this.type, contexts, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);
        node = Meta.builder(key, value).withContext(contexts).build();
    }
    this.holder.setNode(this.type, node, true);
    return save(this.holder).thenApply(v -> true);
}
Also used : PrefixNode(net.luckperms.api.node.types.PrefixNode) ChatMetaType(net.luckperms.api.node.ChatMetaType) Meta(me.lucko.luckperms.common.node.types.Meta) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) NodeType(net.luckperms.api.node.NodeType) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PermissionService(org.spongepowered.api.service.permission.PermissionService) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) Map(java.util.Map) Node(net.luckperms.api.node.Node) Suffix(me.lucko.luckperms.common.node.types.Suffix) HolderType(me.lucko.luckperms.common.model.HolderType) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SubjectData(org.spongepowered.api.service.permission.SubjectData) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) QueryOptionsImpl(me.lucko.luckperms.common.query.QueryOptionsImpl) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Collection(java.util.Collection) ProxyFactory(me.lucko.luckperms.sponge.service.ProxyFactory) Prefix(me.lucko.luckperms.common.node.types.Prefix) Tristate(net.luckperms.api.util.Tristate) Objects(java.util.Objects) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) NodeBuilders(me.lucko.luckperms.common.node.factory.NodeBuilders) Group(me.lucko.luckperms.common.model.Group) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) User(me.lucko.luckperms.common.model.User) DataType(net.luckperms.api.model.data.DataType) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) PrefixNode(net.luckperms.api.node.types.PrefixNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) ChatMetaType(net.luckperms.api.node.ChatMetaType)

Example 14 with ImmutableContextSet

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

the class PermissionHolderSubjectData method getAllPermissions.

@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
    ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> permissions = ImmutableMap.builder();
    for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getData(this.type).asMap().entrySet()) {
        ImmutableMap.Builder<String, Boolean> builder = ImmutableMap.builder();
        for (Node n : entry.getValue()) {
            builder.put(n.getKey(), n.getValue());
        }
        permissions.put(entry.getKey(), builder.build());
    }
    return permissions.build();
}
Also used : PrefixNode(net.luckperms.api.node.types.PrefixNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) Collection(java.util.Collection) 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 15 with ImmutableContextSet

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

the class ParentRemove method execute.

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

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