TextComponentBuilder
Create complex clickable messages using the Spigot TextComponent API — in just one line!
With this little builder, you can create clickable messages by combining multiple TextComponents into a single one.
[hr]
Usage Example
Here's a few examples to help you understand how it works
Simple clickable message (The whole message will be clickable)
Code (Java):
player. spigot ( ). sendMessage (
new TextComponentBuilder ( ). setMessage ( "§dThis is clickable !!!" ). build ( )
) ;
Code (Java):
player. spigot ( ). sendMessage (
new TextComponentBuilder ( )
. compose (
new TextComponentBuilder ( ). setMessage ( "§dThis is clickable !!!" )
. setHoverEvent (HoverEvent. Action. SHOW_TEXT, String. format ( "§7Hey §d%s §!", player. getName ( ) ) )
. setClickAction (ClickEvent. Action. RUN_COMMAND, "/say Heyyy !" )
. build ( ),
new TextComponentBuilder ( ). setMessage ( " §7This is non clickable :(" ). build ( )
). build ( )
) ;
Method Explanation
This method is just the constructor — it creates the TextComponent and sets it to empty.
If a message were put there, your whole message would be clickable, and to avoid that, the compose method exists!
Code (Java):
Code (Java):
public TextComponentBuilder setMessage ( String message ) {
textComponent. addExtra (message ) ;
return this ;
}
setHoverEvent() — lets you show something when hovering the message.
It takes two arguments:
- A HoverEvent Action — one of:
- HoverEvent.Action.SHOW_TEXT : Show text when hovering
- HoverEvent.Action.SHOW_ACHIEVEMENT : Show an achievement (UNTESTED)
- HoverEvent.Action.SHOW_ENTITY : Show entity info (UNTESTED)
- HoverEvent.Action.SHOW_ITEM : Show item info (UNTESTED)
- A String — the text shown when using SHOW_TEXT
setClickAction() — lets you trigger an action when clicking the message.
It also takes two arguments:
- A ClickEvent Action — one of:
- ClickEvent.Action.COPY_TO_CLIPBOARD : Copy text to clipboard (UNTESTED)
- ClickEvent.Action.OPEN_FILE : Open a local file (UNTESTED)
- ClickEvent.Action.OPEN_URL : Open a webpage
- ClickEvent.Action.RUN_COMMAND : Run a command
- ClickEvent.Action.SUGGEST_COMMAND : Suggest a command in chat
- A String — the value passed to the action
Code (Java):
public TextComponentBuilder setHoverEvent (net. md_5. bungee. api. chat. HoverEvent. Action hoverAction, String value ) {
textComponent. setHoverEvent ( new HoverEvent (hoverAction, new Text (value ) ) ) ;
return this ;
}
public TextComponentBuilder setClickAction (net. md_5. bungee. api. chat. ClickEvent. Action clickAction, String value ) {
textComponent. setClickEvent ( new ClickEvent (clickAction, value ) ) ;
return this ;
}
It allows you to chain multiple TextComponentBuilder calls to build any number of clickable (or non-clickable) segments, combining them into a single message.
Finally, the build() method just does what its name implies — it builds and returns the final TextComponent.
Code (Java):
public TextComponentBuilder compose ( TextComponent... components ) {
for ( TextComponent component : components ) {
textComponent. addExtra (component ) ;
}
return this ;
}
public TextComponent build ( ) {
return textComponent ;
}
That's it, enjoy!
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft version listed: 1.21
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
TextComponentBuilder is a free Minecraft Java mod. Compatible with Minecraft 1.21. Downloaded 33 times (via Spigot). Download it and open it directly in the game.