Search in sources :

Example 11 with ClickEvent

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

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

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

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

use of net.kyori.text.event.ClickEvent in project VoxelGamesLibv2 by VoxelGamesLib.

the class LangFormatter method handleClick.

@Nonnull
private static ClickEvent handleClick(@Nonnull String token) {
    String[] args = token.split(":");
    ClickEvent clickEvent;
    if (args.length < 2)
        throw new VoxelGameLibException("Can't parse click action (too few args) " + token);
    switch(args[1]) {
        case "run_command":
            clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, token.replace("click:run_command:", ""));
            break;
        case "suggest_command":
            clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, token.replace("click:suggest_command:", ""));
            break;
        case "open_url":
            clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, token.replace("click:open_url:", ""));
            break;
        case "change_page":
            clickEvent = new ClickEvent(ClickEvent.Action.CHANGE_PAGE, token.replace("click:change_page:", ""));
            break;
        default:
            throw new VoxelGameLibException("Can't parse click action (invalid type " + args[1] + ") " + token);
    }
    return clickEvent;
}
Also used : ClickEvent(net.kyori.text.event.ClickEvent) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Nonnull(javax.annotation.Nonnull)

Aggregations

ClickEvent (net.kyori.text.event.ClickEvent)15 TextComponent (net.kyori.text.TextComponent)13 HoverEvent (net.kyori.text.event.HoverEvent)13 List (java.util.List)10 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)10 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)10 Message (me.lucko.luckperms.common.locale.message.Message)10 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)10 Sender (me.lucko.luckperms.common.sender.Sender)10 CommandResult (me.lucko.luckperms.common.command.CommandResult)9 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)9 Predicates (me.lucko.luckperms.common.utils.Predicates)9 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)8 TextUtils (me.lucko.luckperms.common.utils.TextUtils)8 ArrayList (java.util.ArrayList)7 CommandManager (me.lucko.luckperms.common.command.CommandManager)7 Consumer (java.util.function.Consumer)6 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)6 ArgumentParser (me.lucko.luckperms.common.command.utils.ArgumentParser)6 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)6