Search in sources :

Example 16 with HoverEvent

use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.

the class ParentInfo method makeFancy.

private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> &f" + node.getGroupName(), " ", "&7Click to remove this parent from " + holder.getFriendlyName()), CommandManager.AMPERSAND_CHAR));
    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 : 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) 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) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) SharedSubCommand(me.lucko.luckperms.common.command.abstraction.SharedSubCommand) CollationKeyCache(me.lucko.luckperms.common.utils.CollationKeyCache) LocalizedNode(me.lucko.luckperms.api.LocalizedNode) CommandManager(me.lucko.luckperms.common.command.CommandManager) SortType(me.lucko.luckperms.common.command.utils.SortType) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) SortMode(me.lucko.luckperms.common.command.utils.SortMode) BuildableComponent(net.kyori.text.BuildableComponent) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Comparator(java.util.Comparator) Collections(java.util.Collections) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent)

Example 17 with HoverEvent

use of net.kyori.text.event.HoverEvent 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 18 with HoverEvent

use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.

the class EditorCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    Type type = Type.ALL;
    // parse type
    String typeString = ArgumentParser.parseStringOrElse(0, args, null);
    if (typeString != null) {
        try {
            type = Type.valueOf(typeString.toUpperCase());
        } catch (IllegalArgumentException e) {
        // ignored
        }
    }
    // collect holders
    List<PermissionHolder> holders = new ArrayList<>();
    if (type.includingGroups) {
        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(holders::add);
    }
    if (type.includingUsers) {
        plugin.getUserManager().getAll().values().stream().sorted((o1, o2) -> o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName())).forEach(holders::add);
    }
    // remove holders which the sender doesn't have perms to view
    holders.removeIf(holder -> ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder));
    // they don't have perms to view any of them
    if (holders.isEmpty()) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message.EDITOR_START.send(sender);
    // form the payload data
    JsonObject payload = WebEditor.formPayload(holders, sender, label, plugin);
    // upload the payload data to gist
    String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
    if (pasteId == null) {
        Message.EDITOR_UPLOAD_FAILURE.send(sender);
        return CommandResult.STATE_ERROR;
    }
    // form a url for the editor
    String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
    Message.EDITOR_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : JsonObject(com.google.gson.JsonObject) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) 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) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) CommandResult(me.lucko.luckperms.common.command.CommandResult) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) TextColor(net.kyori.text.format.TextColor) List(java.util.List) Component(net.kyori.text.Component) ClickEvent(net.kyori.text.event.ClickEvent) Message(me.lucko.luckperms.common.locale.message.Message) WebEditor(me.lucko.luckperms.common.web.WebEditor) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) 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) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Example 19 with HoverEvent

use of net.kyori.text.event.HoverEvent 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 20 with HoverEvent

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

HoverEvent (net.kyori.text.event.HoverEvent)21 TextComponent (net.kyori.text.TextComponent)20 ClickEvent (net.kyori.text.event.ClickEvent)13 List (java.util.List)11 Message (me.lucko.luckperms.common.locale.message.Message)11 Sender (me.lucko.luckperms.common.sender.Sender)11 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)10 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)10 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)10 CommandResult (me.lucko.luckperms.common.command.CommandResult)9 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)9 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)9 Predicates (me.lucko.luckperms.common.utils.Predicates)9 TextUtils (me.lucko.luckperms.common.utils.TextUtils)9 ArrayList (java.util.ArrayList)8 CommandManager (me.lucko.luckperms.common.command.CommandManager)8 Consumer (java.util.function.Consumer)7 Node (me.lucko.luckperms.api.Node)7 Map (java.util.Map)6 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)6