ComponentBuilder

A builder interface for creating and manipulating Adventure text components. Provides fluent API methods for appending content, styling, and collecting components.

Properties

Link copied to clipboard

Extension property to append this string directly to the component builder. Provides a convenient property-style syntax for appending strings.

Link copied to clipboard
open val String.convert: Component

Extension property to convert this string into a Component using auto-detection. Automatically detects the component format type (legacy section, legacy ampersand, MiniMessage, or plain text) and deserializes the string accordingly.

Link copied to clipboard

Extension property to append this string as a keybind component. Uses this string as the keybind key to display the player's configured key.

Link copied to clipboard

Extension property to append this string as a selector component. Uses this string as the entity selector pattern (@a, @p, etc.).

Link copied to clipboard

Extension property to append this string as a translatable component. Uses this string as the translation key for localized text.

Functions

Link copied to clipboard
open infix fun append(any: Any?): ComponentBuilder

Appends any value to this component builder with automatic type conversion. String values are appended as text components, Component values are appended directly, and other types are converted to strings via toString() before appending. Null values are converted to empty strings.

abstract infix fun append(content: String): ComponentBuilder

Appends a string content to this component builder.

abstract infix fun append(component: Component): ComponentBuilder

Appends a component to this component builder.

Link copied to clipboard

Sets the text color to aqua.

Link copied to clipboard

Sets the text color to black.

Link copied to clipboard
@ApiStatus.Experimental
abstract fun blockNbt(@Language(value = "NBTPath") nbt: String, consumer: BlockNBTComponent.Builder.() -> Unit): ComponentBuilder

Appends a block NBT component with the specified NBT path and builder configuration. Queries and displays NBT data from a block at a specific position.

Link copied to clipboard

Sets the text color to blue.

Link copied to clipboard

Sets the bold decoration of the last component added to this ComponentBuilder.

Link copied to clipboard
abstract fun collect(): Component

Collects all appended components into a single component without a separator.

abstract fun collect(separator: String): Component

Collects all appended components into a single component with a string separator.

abstract fun collect(separator: Component): Component

Collects all appended components into a single component with a component separator.

Link copied to clipboard
open fun compute(predicate: () -> Boolean, ifTrue: ComponentBuilder.() -> Unit, ifFalse: ComponentBuilder.() -> Unit): ComponentBuilder

Conditionally applies one of two consumer lambdas to this component builder based on a predicate result. Evaluates the predicate function and applies the ifTrue consumer if the result is true, or the ifFalse consumer if the result is false.

Link copied to clipboard
abstract infix fun create(consumer: ComponentBuilder.() -> Unit): ComponentBuilder

Creates a new component builder scope with the given consumer.

Link copied to clipboard

Sets the text color to dark aqua.

Link copied to clipboard

Sets the text color to dark blue.

Link copied to clipboard

Sets the text color to dark gray.

Link copied to clipboard

Sets the text color to dark green.

Link copied to clipboard

Sets the text color to dark purple.

Link copied to clipboard

Sets the text color to dark red.

Link copied to clipboard

Appends an empty component.

Link copied to clipboard
@ApiStatus.Experimental
abstract fun entityNbt(@Language(value = "NBTPath") nbt: String, consumer: EntityNBTComponent.Builder.() -> Unit): ComponentBuilder

Appends an entity NBT component with the specified NBT path and builder configuration. Queries and displays NBT data from entities matching a selector.

Link copied to clipboard
Link copied to clipboard
open fun <T> forEach(array: Array<T>, action: ComponentBuilder.(T) -> Unit): ComponentBuilder

abstract fun <T> forEach(iterable: Iterable<T>, action: ComponentBuilder.(T) -> Unit): ComponentBuilder

Iterates over the given iterable and applies an action to each element. The action receives both the component builder context and the current element, allowing component building per iteration.

Link copied to clipboard

Sets the text color to gold.

Link copied to clipboard

Sets the text color to gray.

Link copied to clipboard

Sets the text color to green.

Link copied to clipboard
abstract infix fun hoverEvent(event: HoverEvent<*>): ComponentBuilder

Applies a hover event to the last appended component. When the player hovers over this component, the specified hover event will be triggered.

Link copied to clipboard
open fun <T : Any> ifPresent(value: T?, consumer: ComponentBuilder.(T) -> Unit): ComponentBuilder

Applies styling if the given value is not null.

Link copied to clipboard
abstract infix fun insertion(text: String): ComponentBuilder

Sets the insertion text for the last appended component. When the player shift-clicks this component, the specified text will be inserted into their chat input field.

Link copied to clipboard
open operator fun Styler.() -> Unit.invoke(): ComponentBuilder

Applies the given styler to the last appended component.

open operator fun String.invoke(consumer: Styler.() -> Unit): ComponentBuilder
open operator fun Component.invoke(consumer: Styler.() -> Unit): ComponentBuilder

Applies the given styler to the last appended component. This operator allows for syntax like +"string" { color(RED) }.

Link copied to clipboard
operator fun ComponentBuilder.invoke(consumer: Styler.() -> Unit): ComponentBuilder

Applies the given styler to the last appended component. This operator allows for syntax like +"string" { color(RED) }.

Link copied to clipboard

Sets the italic decoration of the last component added to this ComponentBuilder.

Link copied to clipboard
abstract fun join(): Component

Joins all appended components into a single component without a separator.

open fun join(consumer: JoinConfiguration.Builder.() -> Unit): Component

Joins all appended components into a single component using a join configuration DSL.

abstract fun join(sep: String): Component

Joins all appended components into a single component with a string separator.

abstract fun join(sep: Component): Component

Joins all appended components into a single component with a component separator.

abstract fun join(conf: JoinConfiguration): Component

Joins all appended components into a single component using a join configuration.

Link copied to clipboard
open fun joinConfiguration(consumer: JoinConfiguration.Builder.() -> Unit): JoinConfiguration

Creates a new component join configuration using a DSL builder.

Link copied to clipboard
abstract infix fun keybind(key: String): ComponentBuilder

Appends a keybind component with the specified keybind key. Displays the key binding configured by the player (e.g., "key.inventory", "key.jump").

open fun keybind(key: String, styler: Styler.() -> Unit): ComponentBuilder

Appends a keybind component with the specified keybind key and applies additional configuration.

Link copied to clipboard
open fun mini(content: String, tags: TagResolverBuilder.() -> Unit): ComponentBuilder

Appends a MiniMessage string content to this component builder with tag resolvers built using a consumer.

abstract fun mini(content: String, vararg tags: TagResolver): ComponentBuilder

Appends a MiniMessage string content to this component builder with optional tag resolvers.

Link copied to clipboard
abstract fun newline(): ComponentBuilder

Appends a newline component to this component builder. Inserts a line break in the text display.

Link copied to clipboard

Sets the obfuscated decoration of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the text color to light purple.

Link copied to clipboard

Sets the text color to red.

Link copied to clipboard
open fun repeat(count: Int, consumer: ComponentBuilder.(Int) -> Unit): ComponentBuilder

Repeats the given action specified number of times.

Link copied to clipboard
abstract fun replace(builder: (TextReplacementConfig.Builder) -> Unit): ComponentBuilder

Applies text replacement to the last appended component using a builder configuration.

abstract fun replace(config: TextReplacementConfig): ComponentBuilder

Applies text replacement to the last appended component using a pre-built configuration.

Link copied to clipboard
abstract fun score(name: String, objective: String): ComponentBuilder

Appends a score component with the specified player name and objective.

open fun score(name: String, objective: String, styler: Styler.() -> Unit): ComponentBuilder

Appends a score component with the specified player name and objective and applies additional configuration.

Link copied to clipboard
abstract infix fun selector(key: String): ComponentBuilder

Appends a selector component with the specified selector pattern. Selectors target entities in the game world (e.g., "@a" for all players, "@p" for nearest player, "@etype=cow" for cows).

open fun selector(key: String, styler: Styler.() -> Unit): ComponentBuilder

Appends a selector component with the specified selector pattern and applies additional configuration.

Link copied to clipboard
abstract fun space(): ComponentBuilder

Appends a space component to this component builder. Inserts a single space character in the text display.

open fun space(count: Int): ComponentBuilder

Appends specified number of space components.

Link copied to clipboard
abstract fun storageNbt(@Language(value = "NBTPath") nbt: String, storage: String, consumer: StorageNBTComponent.Builder.() -> Unit): ComponentBuilder

Appends a storage NBT component that queries data from command storage. Displays NBT data from persistent command storage at the specified key (parsed from string).

@ApiStatus.Experimental
abstract fun storageNbt(@Language(value = "NBTPath") nbt: String, storage: Key, consumer: StorageNBTComponent.Builder.() -> Unit): ComponentBuilder

Appends a storage NBT component that queries data from command storage. Displays NBT data from persistent command storage at the specified key.

Link copied to clipboard

Sets the strikethrough decoration of the last component added to this ComponentBuilder.

Link copied to clipboard
abstract fun styleLast(style: Style): ComponentBuilder

Retroactively applies a styling consumer to the most recently appended component.

Link copied to clipboard
open fun tab(): ComponentBuilder

Appends a tab component to this component builder.

Link copied to clipboard
open fun text(content: String): ComponentBuilder

Appends a text component with the specified string content.

open fun text(content: String, consumer: Styler.() -> Unit): ComponentBuilder

Appends a text component with the specified string content and applies additional configuration. This method combines appending text with a nested component builder scope, allowing you to build complex component hierarchies in a fluent way.

open fun text(content: String, vararg formatters: TextColor): ComponentBuilder

Appends a text component with multiple text colors applied sequentially. Each color in the formatters array is applied to the component's style.

abstract fun text(content: String, regex: Regex, styler: Styler.() -> Unit): ComponentBuilder

Appends text and styles parts of it that match the given regular expression.

Link copied to clipboard
open fun textWithCommand(text: String, command: String): ComponentBuilder

Appends a text component that runs the given command when clicked.

Link copied to clipboard
open fun textWithCopy(text: String, copy: String): ComponentBuilder

Appends a text component that copies the given text to the clipboard when clicked.

Link copied to clipboard
open fun textWithHover(text: String, hover: String): ComponentBuilder

Appends a text component that shows the given text when hovered.

open fun textWithHover(text: String, hover: Component): ComponentBuilder

Appends a text component that shows the given component when hovered.

Link copied to clipboard

Appends a text component that suggests the given command when clicked.

Link copied to clipboard
open fun textWithUrl(text: String, url: String): ComponentBuilder

Appends a text component that opens the given URL when clicked.

Link copied to clipboard
open infix fun translatable(key: String): ComponentBuilder

Appends a translatable component with the specified translation key.

abstract fun translatable(key: String, consumer: ComponentBuilder.() -> Unit): ComponentBuilder

Appends a translatable component with arguments built using a consumer lambda.

abstract fun translatable(key: String, args: List<Component>): ComponentBuilder

Appends a translatable component with the specified translation key and a list of component arguments.

abstract fun translatable(key: String, style: Style): ComponentBuilder

Appends a translatable component with the specified translation key and style.

abstract fun translatable(key: String, vararg args: Component): ComponentBuilder

Appends a translatable component with component arguments. The arguments will be substituted into the translation pattern.

abstract fun translatable(key: String, styler: Styler.() -> Unit, consumer: ComponentBuilder.() -> Unit): ComponentBuilder

Appends a styled translatable component with arguments built using a nested component builder scope.

abstract fun translatable(key: String, styler: Styler.() -> Unit, args: List<Component>): ComponentBuilder

Appends a translatable component with the specified translation key, style, and list of arguments.

abstract fun translatable(key: String, style: Style, vararg args: Component): ComponentBuilder

Appends a translatable component with the specified translation key, style, and component arguments.

Link copied to clipboard
abstract fun translatableAny(key: String, vararg args: Any): ComponentBuilder

Appends a translatable component with mixed type arguments. Accepts any type of arguments (String, Number, Component, etc.) which will be converted appropriately.

Link copied to clipboard
open operator fun unaryPlus(): ComponentBuilder

Operator function that returns this component builder. This is useful for syntax like +"string" { style }.

open operator fun Any?.unaryPlus(): ComponentBuilder

Operator function to append any value to this component builder using the unary + operator. Accepts nullable values of any type and converts them to components appropriately. String values are appended as text components, Component values are appended directly, and other types are converted to strings via toString() before appending.

open operator fun String.unaryPlus(): ComponentBuilder

Operator function to append a string to this component builder using the unary + operator.

open operator fun Component.unaryPlus(): ComponentBuilder

Operator function to append a component to this component builder using the unary + operator.

Link copied to clipboard

Sets the underline decoration of the last component added to this ComponentBuilder.

Link copied to clipboard
open fun whenFalse(condition: Boolean, consumer: ComponentBuilder.() -> Unit): ComponentBuilder

Conditionally applies a consumer lambda to this component builder if the condition is false.

Link copied to clipboard
abstract fun whenTrue(condition: Boolean, consumer: ComponentBuilder.() -> Unit): ComponentBuilder

Conditionally applies a consumer lambda to this component builder if the condition is true.

Link copied to clipboard

Sets the text color to white.

Link copied to clipboard

Sets the color of the last component added to this ComponentBuilder using an integer RGB value.

infix fun ComponentBuilder.withColor(color: TextColor): ComponentBuilder

Sets the color of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the click command of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the copy to clipboard text of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the font of the last component added to this ComponentBuilder using a font key string.

Sets the font of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the hover text of the last component added to this ComponentBuilder.

infix fun ComponentBuilder.withHover(component: Component): ComponentBuilder

Sets the hover component of the last component added to this ComponentBuilder.

Link copied to clipboard
abstract fun withStyle(consumer: Styler.() -> Unit): ComponentBuilder

Applies the given styler to the last appended component. This operator allows for syntax like +"string" { color(RED) }.

Link copied to clipboard
infix inline fun ComponentBuilder.withStyle(crossinline consumer: Styler.() -> Unit): ComponentBuilder

Applies a style to the last component added to this ComponentBuilder using a DSL builder pattern.

Link copied to clipboard

Sets the suggest command of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the URL of the last component added to this ComponentBuilder.

Link copied to clipboard

Sets the text color to yellow.