Solved Multiple Lines of Clickable Text in a Written Book

Discussion in 'Spigot Plugin Development' started by CoolDCB, Mar 26, 2020.

  1. I am trying to create a book that has multiple clickable links and have been searching for a while but have had no luck. All I have got is a link per page which is not ideal. I am also not looking to use json if possible.

    Code (Java):
    BaseComponent[] page = new ComponentBuilder("§8§lGriefing")
                    .event(new ClickEvent(ClickEvent.Action.OPEN_URL, "-report link-"))
                    .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Report User for griefing").create()))
  2. i guess that would be better if u just use JSON for books. I don't see other ways.
  3. I am almost certain there is an alternative. JSON is not difficult to create but it's just if I want to add more to it later on and also make it fully configurable it's over the top.
  4. I can send you some code to use if you want different click and hover events in a json message using the spigot API. Right now I’m in bed and I’m going to sleep, I’ll send it tomorrow
  5. Right that sounds great
  6. Code (Java):
    final TextComponent message = new TextComponent();
            final TextComponent name = new TextComponent(TextComponent.fromLegacyText(user.getRank().getPrefix() + " §7" + event.getPlayer().getName() + "§7 » "));
            name.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/player " + event.getPlayer().getName()));
            name.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§bMod Menu for " + event.getPlayer().getName())));
            message.addExtra(new TextComponent(TextComponent.fromLegacyText(String.format("§f%s", event.getMessage().replace(users.getName(), String.format([email protected]%s§r", users.getName()))))));
    Of course you can adapt the code, this is just an example. The name can be hovered and clicked, but the rest of the message is not.
  7. Just do ComponentBuilder#append() then you can string multiple components together.
    • Useful Useful x 1
  8. This didn't work for the situation I wanted it to but thanks anyway

    Yes this worked perfectly thanks!