Search in sources :

Example 1 with LocalizedNode

use of me.lucko.luckperms.api.LocalizedNode 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 2 with LocalizedNode

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

the class MetaInfo method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    SortedSet<Map.Entry<Integer, LocalizedNode>> prefixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    SortedSet<Map.Entry<Integer, LocalizedNode>> suffixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    Set<LocalizedNode> meta = new HashSet<>();
    // Collect data
    for (LocalizedNode node : holder.resolveInheritances()) {
        if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) {
            continue;
        }
        if (node.isPrefix()) {
            prefixes.add(Maps.immutableEntry(node.getPrefix().getKey(), node));
        } else if (node.isSuffix()) {
            suffixes.add(Maps.immutableEntry(node.getSuffix().getKey(), node));
        } else if (node.isMeta()) {
            meta.add(node);
        }
    }
    if (prefixes.isEmpty()) {
        Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
        sendChatMetaMessage(ChatMetaType.PREFIX, prefixes, sender, holder, label);
    }
    if (suffixes.isEmpty()) {
        Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
        sendChatMetaMessage(ChatMetaType.SUFFIX, suffixes, sender, holder, label);
    }
    if (meta.isEmpty()) {
        Message.META_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.META_HEADER.send(sender, holder.getFriendlyName());
        sendMetaMessage(meta, sender, holder, label);
    }
    return CommandResult.SUCCESS;
}
Also used : TreeSet(java.util.TreeSet) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) HashSet(java.util.HashSet)

Example 3 with LocalizedNode

use of me.lucko.luckperms.api.LocalizedNode 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 4 with LocalizedNode

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

the class PermissionInfo method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    int page = ArgumentParser.parseIntOrElse(0, args, 1);
    SortMode sortMode = SortMode.determine(args);
    // get the holders nodes
    List<LocalizedNode> nodes = new ArrayList<>(holder.getEnduringData().asSortedSet());
    // remove irrelevant types (these are displayed in the other info commands)
    nodes.removeIf(node -> (node.isGroupNode() && node.getValuePrimitive() && plugin.getGroupManager().isLoaded(node.getGroupName())) || // remove if the node is a meta node
    node.isPrefix() || node.isSuffix() || node.isMeta());
    // handle empty
    if (nodes.isEmpty()) {
        Message.PERMISSION_INFO_NO_DATA.send(sender, holder.getFriendlyName());
        return CommandResult.SUCCESS;
    }
    // sort the list alphabetically instead
    if (sortMode.getType() == SortType.ALPHABETICALLY) {
        nodes.sort(ALPHABETICAL_NODE_COMPARATOR);
    }
    // reverse the order if necessary
    if (!sortMode.isAscending()) {
        Collections.reverse(nodes);
    }
    int pageIndex = page - 1;
    List<List<LocalizedNode>> pages = Iterators.divideIterable(nodes, 19);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<LocalizedNode> content = pages.get(pageIndex);
    // send header
    Message.PERMISSION_INFO.send(sender, holder.getFriendlyName(), page, pages.size(), nodes.size());
    // send content
    for (LocalizedNode node : content) {
        String s = "&3> " + (node.getValuePrimitive() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValuePrimitive() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(node);
        if (node.isTemporary()) {
            s += "\n&2-    expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime());
        }
        TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
        sender.sendMessage(message);
    }
    return CommandResult.SUCCESS;
}
Also used : TextComponent(net.kyori.text.TextComponent) SortMode(me.lucko.luckperms.common.command.utils.SortMode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalizedNode(me.lucko.luckperms.api.LocalizedNode)

Example 5 with LocalizedNode

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

the class MetaInfo method sendMetaMessage.

private static void sendMetaMessage(Set<LocalizedNode> meta, Sender sender, PermissionHolder holder, String label) {
    for (LocalizedNode m : meta) {
        String location = processLocation(m, holder);
        if (m.hasSpecificContext()) {
            String context = MessageUtils.getAppendableNodeContextString(m);
            TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), CommandManager.SECTION_CHAR).toBuilder();
            builder.applyDeep(makeFancy(holder, label, m));
            sender.sendMessage(builder.build());
        } else {
            TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), CommandManager.SECTION_CHAR).toBuilder();
            builder.applyDeep(makeFancy(holder, label, m));
            sender.sendMessage(builder.build());
        }
    }
}
Also used : TextComponent(net.kyori.text.TextComponent) LocalizedNode(me.lucko.luckperms.api.LocalizedNode)

Aggregations

LocalizedNode (me.lucko.luckperms.api.LocalizedNode)12 Node (me.lucko.luckperms.api.Node)6 ImmutableLocalizedNode (me.lucko.luckperms.common.node.ImmutableLocalizedNode)5 TextComponent (net.kyori.text.TextComponent)5 List (java.util.List)4 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)3 Maps (com.google.common.collect.Maps)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Consumer (java.util.function.Consumer)2 ChatMetaType (me.lucko.luckperms.api.ChatMetaType)2 CommandManager (me.lucko.luckperms.common.command.CommandManager)2 CommandResult (me.lucko.luckperms.common.command.CommandResult)2 SharedSubCommand (me.lucko.luckperms.common.command.abstraction.SharedSubCommand)2