Solved Multiple clickable chat components in one message

Discussion in 'Spigot Plugin Development' started by Dakir, Aug 23, 2017.

  1. Hey,

    I want do send a party invitation to a player.
    The player should then be able to click ACCEPT or DENY.
    How can I do that?


    Code (Text):
    TextComponent prefix = new TextComponent("[Prefix] Click: ");
    TextComponent accept = new TextComponent("[ACCEPT]");
    accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept"));
    TextComponent or = new TextComponent(" or ");
    TextComponent deny = new TextComponent("[DENY]");
    deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny"));
    p.sendMessage(prefix + accept + or + deny);

    Thanks for help!
  2. p.spigot().sendMessage(Your components); i believe.
  3. electronicboy

    IRC Staff

    Use the ComponentBuilder, it will allow you to create a chain of text components nicely and cleanly
  4. How can I create a ComponentBuilder?
  5. You can use TextComponent#append
  6. electronicboy

    IRC Staff

  7. That's why you use the String instead of the TextComponent... Create a ComponentBuilder append the strings you want and append the click action.