Search in sources :

Example 6 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(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)

Example 7 with LocalizedNode

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

the class ParentInfo 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());
    // handle empty
    if (nodes.isEmpty()) {
        Message.PARENT_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.PARENT_INFO.send(sender, holder.getFriendlyName(), page, pages.size(), nodes.size());
    // send content
    for (LocalizedNode node : content) {
        String s = "&3> &a" + node.getGroupName() + 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 8 with LocalizedNode

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

the class NodeWithContextComparator method compare.

@Override
public int compare(LocalizedNode one, LocalizedNode two) {
    Node o1 = one.getNode();
    Node o2 = two.getNode();
    if (o1.equals(o2)) {
        return 0;
    }
    if (o1.isOverride() != o2.isOverride()) {
        return o1.isOverride() ? 1 : -1;
    }
    if (o1.isServerSpecific() != o2.isServerSpecific()) {
        return o1.isServerSpecific() ? 1 : -1;
    }
    if (o1.isWorldSpecific() != o2.isWorldSpecific()) {
        return o1.isWorldSpecific() ? 1 : -1;
    }
    if (o1.getContexts().size() != o2.getContexts().size()) {
        return o1.getContexts().size() > o2.getContexts().size() ? 1 : -1;
    }
    if (o1.isTemporary() != o2.isTemporary()) {
        return o1.isTemporary() ? 1 : -1;
    }
    if (o1.isWildcard() != o2.isWildcard()) {
        return o1.isWildcard() ? 1 : -1;
    }
    if (o1.isTemporary()) {
        return o1.getSecondsTilExpiry() < o2.getSecondsTilExpiry() ? 1 : -1;
    }
    if (o1.isWildcard()) {
        return o1.getWildcardLevel() > o2.getWildcardLevel() ? 1 : -1;
    }
    return CollationKeyCache.compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1;
}
Also used : Node(me.lucko.luckperms.api.Node) LocalizedNode(me.lucko.luckperms.api.LocalizedNode)

Example 9 with LocalizedNode

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

the class PermissionHolder method exportNodesAndShorthand.

public Map<String, Boolean> exportNodesAndShorthand(Contexts context, boolean lowerCase) {
    List<LocalizedNode> entries = getAllEntries(context);
    Map<String, Boolean> perms = new HashMap<>();
    boolean applyShorthand = this.plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
    for (Node node : entries) {
        String perm = lowerCase ? node.getPermission().toLowerCase() : node.getPermission();
        if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null) {
            if (applyShorthand) {
                List<String> shorthand = node.resolveShorthand();
                if (!shorthand.isEmpty()) {
                    for (String s : shorthand) {
                        perms.putIfAbsent(lowerCase ? s.toLowerCase() : s, node.getValuePrimitive());
                    }
                }
            }
        }
    }
    return ImmutableMap.copyOf(perms);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode) Node(me.lucko.luckperms.api.Node) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) ImmutableLocalizedNode(me.lucko.luckperms.common.node.ImmutableLocalizedNode)

Example 10 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) {
    InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph();
    Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
    for (PermissionHolder holder : traversal) {
        List<Node> nodes = holder.getOwnNodes();
        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)

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