Search in sources :

Example 6 with TextComponent

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

the class ListGroups method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    try {
        plugin.getStorage().loadAllGroups().get();
    } catch (Exception e) {
        e.printStackTrace();
        Message.GROUPS_LOAD_ERROR.send(sender);
        return CommandResult.LOADING_ERROR;
    }
    Message.GROUPS_LIST.send(sender);
    plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
        int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
        return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
    }).forEach(group -> {
        List<String> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(group)).map(Track::getName).collect(Collectors.toList());
        TextComponent component;
        if (tracks.isEmpty()) {
            component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0)), CommandManager.SECTION_CHAR);
        } else {
            component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asString(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0), MessageUtils.toCommaSep(tracks)), CommandManager.SECTION_CHAR);
        }
        component = component.toBuilder().applyDeep(c -> {
            c.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + label + " group " + group.getName() + " info"));
            c.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to view more info about " + group.getName() + ".").color(TextColor.GRAY)));
        }).build();
        sender.sendMessage(component);
    });
    return CommandResult.SUCCESS;
}
Also used : CommandManager(me.lucko.luckperms.common.command.CommandManager) TextUtils(me.lucko.luckperms.common.utils.TextUtils) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) Track(me.lucko.luckperms.common.model.Track) TextColor(net.kyori.text.format.TextColor) List(java.util.List) ClickEvent(net.kyori.text.event.ClickEvent) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Predicates(me.lucko.luckperms.common.utils.Predicates) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 7 with TextComponent

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

the class VerboseListener method sendNotification.

private void sendNotification(CheckData data) {
    String msg = "&a" + data.getCheckTarget() + "&7 - &a" + data.getPermission() + "&7 - " + getTristateColor(data.getResult()) + data.getResult().name().toLowerCase();
    if (this.notifiedSender.isConsole()) {
        // just send as a raw message
        Message.VERBOSE_LOG.send(this.notifiedSender, msg);
        return;
    }
    // form a hoverevent from the check trace
    TextComponent textComponent = TextUtils.fromLegacy(Message.VERBOSE_LOG.asString(this.notifiedSender.getPlatform().getLocaleManager(), msg));
    // build the text
    List<String> hover = new ArrayList<>();
    hover.add("&bOrigin: &2" + data.getCheckOrigin().name());
    hover.add("&bContext: &r" + MessageUtils.contextSetToString(data.getCheckContext()));
    hover.add("&bTrace: &r");
    Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str));
    int overflow;
    if (data.getCheckOrigin() == CheckOrigin.API || data.getCheckOrigin() == CheckOrigin.INTERNAL) {
        overflow = CHAT_UNFILTERED_PRINTER.process(data.getCheckTrace(), printer);
    } else {
        overflow = CHAT_FILTERED_PRINTER.process(data.getCheckTrace(), printer);
    }
    if (overflow != 0) {
        hover.add("&f... and " + overflow + " more");
    }
    // send the message
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), CommandManager.AMPERSAND_CHAR));
    TextComponent text = textComponent.toBuilder().applyDeep(comp -> comp.hoverEvent(hoverEvent)).build();
    this.notifiedSender.sendMessage(text);
}
Also used : TextComponent(net.kyori.text.TextComponent) JsonObject(com.google.gson.JsonObject) CommandManager(me.lucko.luckperms.common.command.CommandManager) Date(java.util.Date) TextUtils(me.lucko.luckperms.common.utils.TextUtils) Tristate(me.lucko.luckperms.api.Tristate) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) StackTracePrinter(me.lucko.luckperms.common.utils.StackTracePrinter) SimpleDateFormat(java.text.SimpleDateFormat) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) JArray(me.lucko.luckperms.common.utils.gson.JArray) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) DateUtil(me.lucko.luckperms.common.utils.DateUtil) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Message(me.lucko.luckperms.common.locale.message.Message) JObject(me.lucko.luckperms.common.utils.gson.JObject) HoverEvent(net.kyori.text.event.HoverEvent) ArrayList(java.util.ArrayList)

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