Search in sources :

Example 1 with HolderType

use of me.lucko.luckperms.common.references.HolderType 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)

Example 2 with HolderType

use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.

the class GroupListMembers method sendResult.

private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
    results = new ArrayList<>(results);
    // we need a deterministic sort order
    // even though we're comparing uuids here in some cases - it doesn't matter
    // the import thing is that the order is the same each time the command is executed
    results.sort((o1, o2) -> {
        Comparable h1 = (Comparable) o1.getHolder();
        Comparable h2 = (Comparable) o2.getHolder();
        // noinspection unchecked
        return h1.compareTo(h2);
    });
    int pageIndex = page - 1;
    List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<HeldPermission<T>> content = pages.get(pageIndex);
    List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
    // send header
    headerMessage.send(sender, page, pages.size(), results.size());
    for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
        String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
        TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
        sender.sendMessage(message);
    }
}
Also used : TextUtils(me.lucko.luckperms.common.utils.TextUtils) SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) 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) BuildableComponent(net.kyori.text.BuildableComponent) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Predicates(me.lucko.luckperms.common.utils.Predicates) TextComponent(net.kyori.text.TextComponent) HeldPermission(me.lucko.luckperms.api.HeldPermission) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with HolderType

use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.

the class GroupListMembers 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> &b" + perm.asNode().getGroupName(), " ", "&7Click to remove this parent 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) SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) 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) BuildableComponent(net.kyori.text.BuildableComponent) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 4 with HolderType

use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.

the class SearchCommand method sendResult.

private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
    results = new ArrayList<>(results);
    // we need a deterministic sort order
    // even though we're comparing uuids here in some cases - it doesn't matter
    // the import thing is that the order is the same each time the command is executed
    results.sort((o1, o2) -> {
        Comparable h1 = (Comparable) o1.getHolder();
        Comparable h2 = (Comparable) o2.getHolder();
        // noinspection unchecked
        return h1.compareTo(h2);
    });
    int pageIndex = page - 1;
    List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<HeldPermission<T>> content = pages.get(pageIndex);
    List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
    // send header
    headerMessage.send(sender, page, pages.size(), results.size());
    for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
        String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
        TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
        sender.sendMessage(message);
    }
}
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) TextComponent(net.kyori.text.TextComponent) HeldPermission(me.lucko.luckperms.api.HeldPermission) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

Caffeine (com.github.benmanes.caffeine.cache.Caffeine)4 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)4 Maps (com.google.common.collect.Maps)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 UUID (java.util.UUID)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 HeldPermission (me.lucko.luckperms.api.HeldPermission)4 Node (me.lucko.luckperms.api.Node)4 CommandManager (me.lucko.luckperms.common.command.CommandManager)4 CommandResult (me.lucko.luckperms.common.command.CommandResult)4 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)4 ArgumentParser (me.lucko.luckperms.common.command.utils.ArgumentParser)4 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)4 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)4 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)4 Message (me.lucko.luckperms.common.locale.message.Message)4