Search in sources :

Example 11 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class PermissionHolder method accumulateInheritancesTo.

private void accumulateInheritancesTo(List<LocalizedNode> accumulator, Contexts context) {
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(context);
    Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
    for (PermissionHolder holder : traversal) {
        List<Node> nodes = holder.getOwnNodes(context.getContexts());
        for (Node node : nodes) {
            ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(node, holder.getObjectName());
            accumulator.add(localizedNode);
        }
    }
}
Also used : ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 12 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class WeightCache method supply.

@Override
protected OptionalInt supply() {
    boolean seen = false;
    int best = 0;
    for (Node n : this.group.getOwnNodes(ImmutableContextSet.empty())) {
        Integer weight = NodeFactory.parseWeightNode(n.getPermission());
        if (weight == null) {
            continue;
        }
        if (!seen || weight > best) {
            seen = true;
            best = weight;
        }
    }
    OptionalInt weight = seen ? OptionalInt.of(best) : OptionalInt.empty();
    if (!weight.isPresent()) {
        Map<String, Integer> configWeights = this.group.getPlugin().getConfiguration().get(ConfigKeys.GROUP_WEIGHTS);
        Integer w = configWeights.get(this.group.getObjectName().toLowerCase());
        if (w != null) {
            weight = OptionalInt.of(w);
        }
    }
    return weight;
}
Also used : Node(me.lucko.luckperms.api.Node) OptionalInt(java.util.OptionalInt)

Example 13 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class HolderSubjectData method getAllOptions.

@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, String>> getAllOptions() {
    Map<ImmutableContextSet, Map<String, String>> options = new HashMap<>();
    Map<ImmutableContextSet, Integer> minPrefixPriority = new HashMap<>();
    Map<ImmutableContextSet, Integer> minSuffixPriority = new HashMap<>();
    for (Node n : this.holder.getNodes(this.type).values()) {
        if (!n.getValuePrimitive())
            continue;
        if (!n.isMeta() && !n.isPrefix() && !n.isSuffix())
            continue;
        ImmutableContextSet immutableContexts = n.getFullContexts().makeImmutable();
        if (!options.containsKey(immutableContexts)) {
            options.put(immutableContexts, new HashMap<>());
            minPrefixPriority.put(immutableContexts, Integer.MIN_VALUE);
            minSuffixPriority.put(immutableContexts, Integer.MIN_VALUE);
        }
        if (n.isPrefix()) {
            Map.Entry<Integer, String> value = n.getPrefix();
            if (value.getKey() > minPrefixPriority.get(immutableContexts)) {
                options.get(immutableContexts).put(NodeFactory.PREFIX_KEY, value.getValue());
                minPrefixPriority.put(immutableContexts, value.getKey());
            }
            continue;
        }
        if (n.isSuffix()) {
            Map.Entry<Integer, String> value = n.getSuffix();
            if (value.getKey() > minSuffixPriority.get(immutableContexts)) {
                options.get(immutableContexts).put(NodeFactory.SUFFIX_KEY, value.getValue());
                minSuffixPriority.put(immutableContexts, value.getKey());
            }
            continue;
        }
        if (n.isMeta()) {
            Map.Entry<String, String> meta = n.getMeta();
            options.get(immutableContexts).put(meta.getKey(), meta.getValue());
        }
    }
    ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, String>> map = ImmutableMap.builder();
    for (Map.Entry<ImmutableContextSet, Map<String, String>> e : options.entrySet()) {
        map.put(e.getKey(), ImmutableMap.copyOf(e.getValue()));
    }
    return map.build();
}
Also used : HashMap(java.util.HashMap) Node(me.lucko.luckperms.api.Node) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 14 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class HolderSubjectData method setPermission.

@Override
public CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate tristate) {
    Objects.requireNonNull(contexts, "contexts");
    Objects.requireNonNull(permission, "permission");
    Objects.requireNonNull(tristate, "tristate");
    if (tristate == Tristate.UNDEFINED) {
        // Unset
        Node node = NodeFactory.builder(permission).withExtraContext(contexts).build();
        this.type.run(() -> this.holder.unsetPermission(node), () -> this.holder.unsetTransientPermission(node));
        return objectSave(this.holder).thenApply(v -> true);
    }
    Node node = NodeFactory.builder(permission).setValue(tristate.asBoolean()).withExtraContext(contexts).build();
    this.type.run(() -> {
        // unset the inverse, to allow false -> true, true -> false overrides.
        this.holder.unsetPermission(node);
        this.holder.setPermission(node);
    }, () -> {
        // unset the inverse, to allow false -> true, true -> false overrides.
        this.holder.unsetTransientPermission(node);
        this.holder.setTransientPermission(node);
    });
    return objectSave(this.holder).thenApply(v -> true);
}
Also used : Node(me.lucko.luckperms.api.Node)

Example 15 with Node

use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.

the class SearchCommand method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm) {
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> " + (perm.asNode().getValuePrimitive() ? "&a" : "&c") + perm.asNode().getPermission(), " ", "&7Click to remove this node from " + holderName), CommandManager.AMPERSAND_CHAR));
    String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false);
    ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
Also used : TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) HoverEvent(net.kyori.text.event.HoverEvent) Function(java.util.function.Function) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) DateUtil(me.lucko.luckperms.common.utils.DateUtil) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) HolderType(me.lucko.luckperms.common.references.HolderType) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) HeldPermission(me.lucko.luckperms.api.HeldPermission) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) CommandManager(me.lucko.luckperms.common.command.CommandManager) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) TabCompletions(me.lucko.luckperms.common.command.utils.TabCompletions) BuildableComponent(net.kyori.text.BuildableComponent) Node(me.lucko.luckperms.api.Node) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Aggregations

Node (me.lucko.luckperms.api.Node)56 LocalizedNode (me.lucko.luckperms.api.LocalizedNode)15 Group (me.lucko.luckperms.common.model.Group)15 User (me.lucko.luckperms.common.model.User)13 Map (java.util.Map)12 ImmutableLocalizedNode (me.lucko.luckperms.common.node.ImmutableLocalizedNode)12 List (java.util.List)11 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)10 Message (me.lucko.luckperms.common.locale.message.Message)9 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)9 Sender (me.lucko.luckperms.common.sender.Sender)9 Collectors (java.util.stream.Collectors)8 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)8 CommandResult (me.lucko.luckperms.common.command.CommandResult)8 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)8 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)8 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)8 Predicates (me.lucko.luckperms.common.utils.Predicates)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7