1.8 KiB
1.8 KiB
Literal text API
Create a text object
val text = literalText("base text") {
// the text builder
}
// or
val text = literalText {
// the text builder
}
Add children text objects
literalText("base text") {
text("children text") {
// children text builder
}
}
Format the text
Text formatting:
literalText("base text") {
bold = true
italic = true
underline = true
strikethrough = true
obfuscate = true
}
Color:
literalText("base text") {
color = col(0xFF7463)
color = col("#FF7463")
color = KColors.INDIANRED
}
Events
Hover event
General hover event
literalText("base text") {
hoverEvent = HoverEvent(action, content)
}
Show hover text
literalText("base text") {
hoverText("you hovered me") {
// hover text builder
}
}
Click event
General click event
literalText("base text") {
clickEvent = ClickEvent(action, value)
}
Execute command
literalText("base text") {
onClickCommand("/me hoho", onlySuggest = true)
}
Copy a String
literalText("base text") {
onClickCopy("https://github.com/bluefireoly/KSpigot")
}
Special
literalText("base text") {
// line break
newLine()
// an empty line (two line breaks)
emptyLine()
}
Add bungee components
literalText("base text") {
// e.g. add a TranslatableComponent
text(TranslatableComponent("translation.key")) {
// optional text body
}
}
Add legacy chat components
You can add legacy text if you want to use the old color codes for some reason.
literalText("base text") {
legacyText("§cthis text is red") {
// optional text body to format the legacy text
}
}