Home›Java›Mods›TextComponentBuilder
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 :D

Simple clickable message (The whole message will be clickable)
Code (Java):

player. spigot ( ). sendMessage (
    new TextComponentBuilder ( ). setMessage ( "§dThis is clickable !!!" ). build ( )
) ;
 
Complex clickable message (Only chosen part will be clickable)
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 ( )
) ;
 
[hr]
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):

public TextComponentBuilder ( ) {
    this. textComponent = new TextComponent ( "" ) ;
}
 
As its name suggests, this method defines the message that will be shown to your player. Nothing special here — put whatever you want! :D
Code (Java):

public TextComponentBuilder setMessage ( String message ) {
    textComponent. addExtra (message ) ;
    return this ;
}
 
Those two methods, setHoverEvent() and setClickAction(), allow you to add interactivity to your messages.

setHoverEvent() — lets you show something when hovering the message.
It takes two arguments:

setClickAction() — lets you trigger an action when clicking the message.
It also takes two arguments:

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 ;
}
 
The compose() method is used to build complex clickable messages.
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 ;
}
 
[hr]
That's it, enjoy!
Quick facts

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.

Explore more