replace

abstract fun replace(builder: (TextReplacementConfig.Builder) -> Unit): ComponentBuilder

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

This method allows you to replace text patterns within the component using a lambda that configures a TextReplacementConfig.Builder. You can specify what text to match (using strings, regexes, or patterns) and what to replace it with (static text or dynamic components).

Return

this component builder for chaining

Example usage:

component {
text("Hello {player}, welcome to {server}!")
replace {
matchLiteral("{player}")
replacement("Steve")
}
replace {
matchLiteral("{server}")
replacement(text("Minecraft", GOLD))
}
}

Parameters

builder

A lambda with receiver that configures the TextReplacementConfig.Builder


abstract fun replace(config: TextReplacementConfig): ComponentBuilder

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

This method applies the provided TextReplacementConfig directly to replace text patterns within the component. Use this when you have a reusable replacement configuration or when you need to apply the same replacement logic across multiple components.

Return

this component builder for chaining

Example usage:

val playerNameReplacement = TextReplacementConfig.builder()
.matchLiteral("{player}")
.replacement("Steve")
.build()

component {
text("Hello {player}!")
replace(playerNameReplacement)
}

Parameters

config

The text replacement configuration to apply