From 528d8abe3fc8109daffc0a2b09bf6053cc8aa82b Mon Sep 17 00:00:00 2001 From: Jakob K Date: Mon, 28 Jun 2021 01:38:53 +0200 Subject: [PATCH] Add support for legacyText --- .../net/axay/kspigot/chat/LiteralTextBuilder.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt b/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt index 631ab222..a7888595 100644 --- a/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt +++ b/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt @@ -71,6 +71,23 @@ class LiteralTextBuilder(val internalText: BaseComponent, ) { siblingText.addExtra(LiteralTextBuilder(text).apply(builder).build()) } + /** + * Append the given legacy text to the parent. This + * allows you to use legacy color codes (e.g. `§c` for red). + * It is **not** recommended to use this. + * + * @param text the text instance + * @param builder the builder which can be used to set the style and add child text components + */ + inline fun legacyText( + text: String, + builder: LiteralTextBuilder.() -> Unit = { } + ) { + TextComponent.fromLegacyText(text).forEach { + siblingText.addExtra(LiteralTextBuilder(it).apply(builder).build()) + } + } + /** * Sets the text which should be displayed when hovering * over the text in the chat.