component

fun component(consumer: ComponentBuilder.() -> Unit): Component

Creates a text component using a DSL builder pattern.

This function provides a convenient way to construct Adventure text components using a builder DSL. The consumer lambda receives a ComponentBuilder instance that allows building the component structure declaratively.

Return

The built Component instance

Example usage:

val message = component {
text("Hello, ")
text("World!") {
color(NamedTextColor.RED)
}
}

Parameters

consumer

A lambda with receiver that configures the component builder


fun component(joiner: (ComponentBuilder) -> Component = ComponentBuilder::join, consumer: ComponentBuilder.() -> Unit): Component

Creates a text component using a DSL builder pattern with a custom joiner function.

This function provides an advanced way to construct Adventure text components using a builder DSL with a customizable joining strategy. Unlike the simpler component overload, this allows you to specify how the built components should be combined.

The consumer lambda receives a ComponentBuilder instance that allows building the component structure declaratively. The joiner function determines how the components are assembled into the final Component result.

Return

The built Component instance as determined by the joiner function

Example usage with default joiner:

val message = component { // Uses default joiner
append("Hello, ")
append("World!")
}

Example usage with custom separator joiner:

val list = component(joiner = { it.join(" | ") }) {
append("Item 1")
append("Item 2")
append("Item 3")
}
// Result: "Item 1 | Item 2 | Item 3"

Example usage with collect joiner:

val collected = component(joiner = ComponentBuilder::collect) {
append("First")
append("Second")
append("Third")
}

Example usage with custom join configuration:

val formatted = component(joiner = {
it.join(JoinConfiguration.separator(", ".convert)
.prefix("[".convert)
.suffix("]".convert))
}) {
append("A")
append("B")
append("C")
}
// Result: "[A, B, C]"

Parameters

joiner

A function that takes a ComponentBuilder and returns a Component. This controls how the built components are joined together. Defaults to ComponentBuilder.join which concatenates components without a separator.

consumer

A lambda with receiver that configures the component builder


@JvmName(name = "componentJoinConfiguration")
fun component(joiner: JoinConfiguration.Builder.() -> Unit, consumer: ComponentBuilder.() -> Unit): Component
fun String.component(style: Style): Component


fun String.component(): Component

Converts this string into a Component by auto-detecting the format type.

Return

The deserialized component.

See also


val String.component: Component

Property accessor for converting this string into a Component.

See also