1.12.2 Make text suggest command while viewing a book

Discussion in 'Spigot Plugin Development' started by RandomGuy12345, Jan 18, 2020.

  1. Hey!

    I've been trying to create a book with text inside. I want the make the text so when clicked,
    it will suggest a command in chat. I have worked with TextComponents before and when I
    tested it, it didn't do anything.
    Is there any way to make the text suggest the command while the player is viewing the book?

    Current Code:
    Code (Java):
    TextComponent invite = new TextComponent("§2§l[INVITE PLAYER]");

    invite.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/game invite "));
  2. I've never done this with books before, however I've a method for it which I use.

    Code (Java):
        public static void hover(Player p, String chat, String click, String hover) {
                    .sendMessage(new ComponentBuilder(color(chat))
                            .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(color(hover)).create()))
                            .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, click)).create());
    However, as you're trying to do it for books rather than chat I'm not sure this will help.
    • Like Like x 1
  3. Yeah, this doesn't work on books...
  4. Well, you'll have to edit it slightly. Perhaps something along the lines of

    Code (Java):

        public static void hover(String text, String commandSuggestion) {
            new ComponentBuilder(ChatColor.translateAlternateColorCodes('&', text))
                    .event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandSuggestion)).create();