Skip to content

Create a custom message with clickables

This example shows how to create a custom message and add clickable + hover components.

Custom messages allow combining normal text with interactive elements like clickables.

→ Deep dive: [[MessageBuilder|Core-API/Adventure/MessageBuilder]] & [[ComponentBuilder|Core-API/Adventure/ComponentBuilder]]


Steps

  1. Create a base message using MessageBuilder
  2. Create a clickable component using ComponentBuilder
  3. Append the component to the message
  4. Send the message to the player

Implementation

// create base message


MessageBuilder messageBuilder = MessageBuilder.create(
        "<red>Your inventory got cleared!</red>"
);

// create clickable + hover component


Component reportButton = ComponentBuilder.create("[REPORT]")
        .color(PixelColor.RED)
        .hover("<aqua>Click to report for abuse!</aqua>")
        .execute("report " + teamPlayer.getName())
        .build();

// append interactive component to message


messageBuilder
        .append(" ")
        .append(reportButton);

// send message to player


player.sendMessage(messageBuilder);

Explanation

  • MessageBuilder is used to create the base message
  • ComponentBuilder creates interactive elements
  • .hover(...) adds a hover tooltip
  • .execute(...) runs a command when clicked
  • .append(...) combines text and components

Notes

  • Messages can consist of multiple components
  • Use clickable elements for better user interaction
  • Keep messages clear and simple

Next step

[[Create a custom inventory|Core-API/Build-your-first-feature/Inventories-&-UI/Create-a-custom-inventory]]