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
- Create a base message using
MessageBuilder - Create a clickable component using
ComponentBuilder - Append the component to the message
- 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
MessageBuilderis used to create the base messageComponentBuildercreates 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]]