Search in sources :

Example 1 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class AllParentsByWeightHolder method calculateValue.

@Override
protected String calculateValue() {
    Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
    if (contexts == null) {
        contexts = this.user.getPlugin().getContextManager().getStaticContexts();
    }
    InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
    // fully traverse the graph, obtain a list of permission holders the user inherits from
    List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
    Group bestGroup = null;
    if (!traversal.isEmpty()) {
        int best = 0;
        for (PermissionHolder holder : traversal) {
            if (!(holder instanceof Group)) {
                continue;
            }
            Group g = ((Group) holder);
            int weight = g.getWeight().orElse(0);
            if (bestGroup == null || g.getWeight().orElse(0) > best) {
                bestGroup = g;
                best = weight;
            }
        }
    }
    return bestGroup == null ? null : bestGroup.getName();
}
Also used : Group(me.lucko.luckperms.common.model.Group) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Contexts(me.lucko.luckperms.api.Contexts) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 2 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class HolderSubject method getParents.

@Override
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(this.plugin.getContextManager().formContexts(contexts));
    Iterable<PermissionHolder> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this.parent);
    ImmutableList.Builder<LPSubjectReference> subjects = ImmutableList.builder();
    for (PermissionHolder parent : traversal) {
        if (!(parent instanceof Group)) {
            continue;
        }
        subjects.add(((SpongeGroup) parent).sponge().toReference());
    }
    return subjects.build();
}
Also used : Group(me.lucko.luckperms.common.model.Group) SpongeGroup(me.lucko.luckperms.sponge.model.SpongeGroup) ImmutableList(com.google.common.collect.ImmutableList) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SpongeGroup(me.lucko.luckperms.sponge.model.SpongeGroup) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 3 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class ApplyEditsCommand method read.

private boolean read(JsonObject data, String code, Sender sender, LuckPermsPlugin plugin) {
    if (!data.has("who") || data.get("who").getAsString().isEmpty()) {
        Message.APPLY_EDITS_NO_TARGET.send(sender);
        return false;
    }
    String who = data.get("who").getAsString();
    PermissionHolder holder = WebEditor.getHolderFromIdentifier(plugin, sender, who);
    if (holder == null) {
        // the #getHolderFromIdentifier method will send the error message onto the sender
        return false;
    }
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return false;
    }
    Set<NodeModel> nodes = WebEditor.deserializePermissions(data.getAsJsonArray("nodes"));
    Set<Node> before = new HashSet<>(holder.getEnduringNodes().values());
    Set<Node> after = nodes.stream().map(NodeModel::toNode).collect(Collectors.toSet());
    Map.Entry<Set<Node>, Set<Node>> diff = diff(before, after);
    int additions = diff.getKey().size();
    int deletions = diff.getValue().size();
    if (additions == 0 && deletions == 0) {
        return false;
    }
    ExtendedLogEntry.build().actor(sender).acted(holder).action("applyedits", code).build().submit(plugin, sender);
    holder.setEnduringNodes(after);
    String additionsSummary = "addition" + (additions == 1 ? "" : "s");
    String deletionsSummary = "deletion" + (deletions == 1 ? "" : "s");
    Message.APPLY_EDITS_SUCCESS.send(sender, holder.getFriendlyName());
    Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary);
    for (Node n : diff.getKey()) {
        Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(n));
    }
    for (Node n : diff.getValue()) {
        Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(n));
    }
    StorageAssistant.save(holder, sender, plugin);
    return true;
}
Also used : NodeModel(me.lucko.luckperms.common.node.NodeModel) HashSet(java.util.HashSet) Set(java.util.Set) Node(me.lucko.luckperms.api.Node) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class MetaInfo method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
    if (!node.getLocation().equals(holder.getObjectName())) {
        // inherited.
        Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
        if (group != null) {
            holder = group;
        }
    }
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(), " ", "¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFriendlyName()), '¥'));
    String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
    ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
Also used : SortedSet(java.util.SortedSet) NodeWithContextComparator(me.lucko.luckperms.common.node.NodeWithContextComparator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HoverEvent(net.kyori.text.event.HoverEvent) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) 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) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SharedSubCommand(me.lucko.luckperms.common.command.abstraction.SharedSubCommand) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) CommandManager(me.lucko.luckperms.common.command.CommandManager) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) BuildableComponent(net.kyori.text.BuildableComponent) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Comparator(java.util.Comparator) Predicates(me.lucko.luckperms.common.utils.Predicates) Group(me.lucko.luckperms.common.model.Group) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 5 with PermissionHolder

use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.

the class MetaInfo method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, LocalizedNode node) {
    if (!node.getLocation().equals(holder.getObjectName())) {
        // inherited.
        Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
        if (group != null) {
            holder = group;
        }
    }
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥r" + node.getMeta().getKey() + " ¥7- ¥r" + node.getMeta().getValue(), " ", "¥7Click to remove this meta pair from " + holder.getFriendlyName()), '¥'));
    String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
    ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
    return component -> {
        component.hoverEvent(hoverEvent);
        component.clickEvent(clickEvent);
    };
}
Also used : SortedSet(java.util.SortedSet) NodeWithContextComparator(me.lucko.luckperms.common.node.NodeWithContextComparator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HoverEvent(net.kyori.text.event.HoverEvent) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) 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) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SharedSubCommand(me.lucko.luckperms.common.command.abstraction.SharedSubCommand) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) CommandManager(me.lucko.luckperms.common.command.CommandManager) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) BuildableComponent(net.kyori.text.BuildableComponent) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Comparator(java.util.Comparator) Predicates(me.lucko.luckperms.common.utils.Predicates) Group(me.lucko.luckperms.common.model.Group) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Aggregations

PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)10 List (java.util.List)6 Node (me.lucko.luckperms.api.Node)5 CommandManager (me.lucko.luckperms.common.command.CommandManager)5 CommandResult (me.lucko.luckperms.common.command.CommandResult)5 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)5 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)5 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)5 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)5 Message (me.lucko.luckperms.common.locale.message.Message)5 Group (me.lucko.luckperms.common.model.Group)5 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)5 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)5 Sender (me.lucko.luckperms.common.sender.Sender)5 Predicates (me.lucko.luckperms.common.utils.Predicates)5 TextComponent (net.kyori.text.TextComponent)5 ClickEvent (net.kyori.text.event.ClickEvent)5 HoverEvent (net.kyori.text.event.HoverEvent)5 Comparator (java.util.Comparator)4 Consumer (java.util.function.Consumer)4