Search in sources :

Example 1 with TextComponent

use of net.kyori.text.TextComponent 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 2 with TextComponent

use of net.kyori.text.TextComponent 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 3 with TextComponent

use of net.kyori.text.TextComponent 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 4 with TextComponent

use of net.kyori.text.TextComponent in project LuckPerms by lucko.

the class CommandManager method sendCommandUsage.

private void sendCommandUsage(Sender sender, String label) {
    MessageUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + this.plugin.getBootstrap().getVersion() + "&2.");
    this.mainCommands.stream().filter(Command::shouldDisplay).filter(c -> c.isAuthorized(sender)).forEach(c -> {
        @SuppressWarnings("unchecked") String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None");
        TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR).toBuilder().applyDeep(comp -> {
            comp.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&bCommand: &2" + c.getName(), "&bDescription: &2" + c.getDescription(), "&bUsage: &2" + String.format(c.getUsage(), label), "&bPermission: &2" + permission, " ", "&7Click to auto-complete."), AMPERSAND_CHAR)));
            comp.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(c.getUsage(), label)));
        }).build();
        sender.sendMessage(component);
    });
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) InfoCommand(me.lucko.luckperms.common.commands.misc.InfoCommand) BulkUpdateCommand(me.lucko.luckperms.common.commands.misc.BulkUpdateCommand) ListGroups(me.lucko.luckperms.common.commands.group.ListGroups) ListIterator(java.util.ListIterator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) ImportCommand(me.lucko.luckperms.common.commands.misc.ImportCommand) HoverEvent(net.kyori.text.event.HoverEvent) ExportCommand(me.lucko.luckperms.common.commands.misc.ExportCommand) CheckCommand(me.lucko.luckperms.common.commands.misc.CheckCommand) EditorCommand(me.lucko.luckperms.common.commands.misc.EditorCommand) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) VerboseCommand(me.lucko.luckperms.common.commands.misc.VerboseCommand) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) ListTracks(me.lucko.luckperms.common.commands.track.ListTracks) UUID(java.util.UUID) TextComponent(net.kyori.text.TextComponent) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) CreateTrack(me.lucko.luckperms.common.commands.track.CreateTrack) Optional(java.util.Optional) TreeCommand(me.lucko.luckperms.common.commands.misc.TreeCommand) Pattern(java.util.regex.Pattern) DeleteGroup(me.lucko.luckperms.common.commands.group.DeleteGroup) MigrationMainCommand(me.lucko.luckperms.common.commands.migration.MigrationMainCommand) TrackMainCommand(me.lucko.luckperms.common.commands.track.TrackMainCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) CompletableFuture(java.util.concurrent.CompletableFuture) LogMainCommand(me.lucko.luckperms.common.commands.log.LogMainCommand) Command(me.lucko.luckperms.common.command.abstraction.Command) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) SearchCommand(me.lucko.luckperms.common.commands.misc.SearchCommand) DebugCommand(me.lucko.luckperms.common.commands.misc.DebugCommand) ImmutableList(com.google.common.collect.ImmutableList) UserMainCommand(me.lucko.luckperms.common.commands.user.UserMainCommand) ClickEvent(net.kyori.text.event.ClickEvent) SyncCommand(me.lucko.luckperms.common.commands.misc.SyncCommand) ExecutorService(java.util.concurrent.ExecutorService) CreateGroup(me.lucko.luckperms.common.commands.group.CreateGroup) ApplyEditsCommand(me.lucko.luckperms.common.commands.misc.ApplyEditsCommand) NetworkSyncCommand(me.lucko.luckperms.common.commands.misc.NetworkSyncCommand) Executor(java.util.concurrent.Executor) Sender(me.lucko.luckperms.common.sender.Sender) ReloadConfigCommand(me.lucko.luckperms.common.commands.misc.ReloadConfigCommand) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) GroupMainCommand(me.lucko.luckperms.common.commands.group.GroupMainCommand) DeleteTrack(me.lucko.luckperms.common.commands.track.DeleteTrack) Collections(java.util.Collections) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) InfoCommand(me.lucko.luckperms.common.commands.misc.InfoCommand) BulkUpdateCommand(me.lucko.luckperms.common.commands.misc.BulkUpdateCommand) ImportCommand(me.lucko.luckperms.common.commands.misc.ImportCommand) ExportCommand(me.lucko.luckperms.common.commands.misc.ExportCommand) CheckCommand(me.lucko.luckperms.common.commands.misc.CheckCommand) EditorCommand(me.lucko.luckperms.common.commands.misc.EditorCommand) VerboseCommand(me.lucko.luckperms.common.commands.misc.VerboseCommand) TreeCommand(me.lucko.luckperms.common.commands.misc.TreeCommand) MigrationMainCommand(me.lucko.luckperms.common.commands.migration.MigrationMainCommand) TrackMainCommand(me.lucko.luckperms.common.commands.track.TrackMainCommand) LogMainCommand(me.lucko.luckperms.common.commands.log.LogMainCommand) Command(me.lucko.luckperms.common.command.abstraction.Command) SearchCommand(me.lucko.luckperms.common.commands.misc.SearchCommand) DebugCommand(me.lucko.luckperms.common.commands.misc.DebugCommand) UserMainCommand(me.lucko.luckperms.common.commands.user.UserMainCommand) SyncCommand(me.lucko.luckperms.common.commands.misc.SyncCommand) ApplyEditsCommand(me.lucko.luckperms.common.commands.misc.ApplyEditsCommand) NetworkSyncCommand(me.lucko.luckperms.common.commands.misc.NetworkSyncCommand) ReloadConfigCommand(me.lucko.luckperms.common.commands.misc.ReloadConfigCommand) GroupMainCommand(me.lucko.luckperms.common.commands.group.GroupMainCommand) ClickEvent(net.kyori.text.event.ClickEvent)

Example 5 with TextComponent

use of net.kyori.text.TextComponent 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

List (java.util.List)7 TextComponent (net.kyori.text.TextComponent)7 ArrayList (java.util.ArrayList)6 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)5 Message (me.lucko.luckperms.common.locale.message.Message)5 Sender (me.lucko.luckperms.common.sender.Sender)5 TextUtils (me.lucko.luckperms.common.utils.TextUtils)5 HoverEvent (net.kyori.text.event.HoverEvent)5 Collectors (java.util.stream.Collectors)4 CommandManager (me.lucko.luckperms.common.command.CommandManager)4 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)4 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)4 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)4 ClickEvent (net.kyori.text.event.ClickEvent)4 UUID (java.util.UUID)3 Consumer (java.util.function.Consumer)3 CommandResult (me.lucko.luckperms.common.command.CommandResult)3 ArgumentParser (me.lucko.luckperms.common.command.utils.ArgumentParser)3 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)3 DateUtil (me.lucko.luckperms.common.utils.DateUtil)3