A lightweight Kotlin DSL wrapper around adventure, the powerful text component library from KyoriPowered and PaperMC.
This project provides a fully type-safe, idiomatic Kotlin DSL for building Adventure Components with a clean and expressive syntax, while preserving the full flexibility of the original API.
While adventure is extremely powerful, its builder-based Java design can feel verbose in Kotlin.
This wrapper:
- ✅ Provides a Kotlin-first DSL
- ✅ Uses Kotlin contracts for safer builders
- ✅ Reduces boilerplate
- ✅ Keeps full compatibility with Adventure components
- ✅ Adds clean, scoped styling and event builders
Create complex components using a clean DSL instead of nested builders.
val component: Component = textComponent {
text("Hello ")
text {
content("World")
bold()
}
}This builds a regular Adventure Component and is fully compatible with any Adventure platform.
Easily apply styles using Kotlin extension functions.
color(TextColor)shadowColor(ARGBLike)bold()italic()underlined()strikethrough()obfuscated()font(Key)insertion(String)- Custom
Stylevia DSL
textComponent {
text("Styled Text") {
color(NamedTextColor.RED)
bold()
italic()
}
}You can also build standalone Style objects:
val style = styleBuilder {
bold()
}Full support for all ClickEvent types from adventure:
- Open URL
- Open file
- Run command
- Suggest command
- Change page
- Copy to clipboard
- Callback
- Show dialog
- Custom events
textComponent {
text("Click me!") {
clickEvent(KClickEventType.OpenUrl) {
url("https://example.com")
}
}
}Callback events with options:
clickEvent(KClickEventType.Callback) {
callback { audience ->
audience.sendMessage(Component.text("Clicked!"))
}
uses(1)
}Supports all Adventure hover types:
- Show text
- Show item
- Show entity
hoverEvent(KHoverEventType.ShowText) {
text("Hover text")
}hoverEvent(KHoverEventType.ShowItem) {
item(myItemKey)
count(1)
}hoverEvent(KHoverEventType.ShowEntity) {
entity(entityType)
uuid(uuid)
name {
text("Zombie")
}
}Full support for translatable keys and arguments.
textComponent {
translatable("chat.type.text") {
args {
arg { // this: KTextComponent
content("Player")
}
component { // this: KTextComponent
content("Hello!")
}
}
}
}The difference between component and arg is that component goes through TranslationArgument.
That does nothing on its own, but some platforms may use it to resolve placeholders.
This DSL supports nearly all advanced component types from Adventure:
text("content")- Nested text blocks
- Color overloads
- With arguments builder
keybind {
keybind("key.jump")
}score {
name("Player")
objective("kills")
}selector {
pattern("@a")
}blockNBTentityNBTstorageNBT
Example:
blockNBT {
nbtPath("Items[0].tag.display.Name")
}Supports Adventure's object components:
- Sprites
- Player heads
objectComponent {
playerHead {
name("Notch")
}
}Convenience helpers for layout:
newLine()space()append(ComponentLike)
All DSL entry points use Kotlin's contracts API:
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }This ensures:
- Safe builder usage
- Improved smart-casting
- Better IDE assistance
The custom @ComponentDsl marker prevents accidental scope leakage between nested builders, ensuring clean and predictable DSL usage.
- Fully compatible with all platforms using adventure
- Produces standard Adventure
Componentobjects - Zero reflection
- Zero overhead beyond builder usage
This project does not replace Adventure.
It enhances it.
You still use:
ComponentStyleClickEventHoverEvent
But now in an idiomatic Kotlin way.
val message = textComponent {
text("Welcome ") {
color(NamedTextColor.GREEN)
}
text("Player") {
bold()
clickEvent(KClickEventType.RunCommand) {
command("/profile")
}
hoverEvent(KHoverEventType.ShowText) {
text("View profile")
}
}
newLine()
translatable("chat.type.announcement") {
args {
arg { content("Server") }
arg { content("Maintenance starts soon.") }
}
}
}This Kotlin DSL wrapper for adventure provides:
- Clean Kotlin syntax
- Full feature coverage
- Advanced event support
- Object components support
- NBT component support
- Type-safe builders
- Zero abstraction overhead
If you love Adventure but want a more expressive Kotlin experience — this library is for you.
- adventure by KyoriPowered and PaperMC
Fantamomo