11package dev.fruxz.stacked.extension
22
3- import dev.fruxz.ascend.extension.switch
43import dev.fruxz.stacked.StackedBuilder
54import net.kyori.adventure.text.Component
65import net.kyori.adventure.text.ComponentLike
@@ -66,6 +65,18 @@ val ComponentLike.asPlainString: String
6665val String .asComponent: TextComponent
6766 get() = adventureSerializer.deserializeOr(this , Component .text(" FAILED" , NamedTextColor .RED ))!!
6867
68+ /* *
69+ * This function converts this [String] into a [TextComponent]
70+ * by using the [LegacyComponentSerializer], provided by the
71+ * [adventureSerializer] value.
72+ * @see adventureSerializer
73+ * @author Fruxz
74+ * @since 2025.8
75+ * @param builder the process, to modify the component
76+ * @return the modified component as an [TextComponent]
77+ * @see StackedBuilder
78+ * @see String.asComponent
79+ */
6980inline fun String.asComponent (builder : StackedBuilder .() -> Unit ) =
7081 Component .text().append(asComponent).toStackedBuilder().apply (builder).build()
7182
@@ -103,11 +114,23 @@ val Iterable<String>.asComponents: List<TextComponent>
103114val ComponentLike .asStyledString: String
104115 get() = strictMiniMessageSerializer.serialize(asComponent())
105116
117+ /* *
118+ * This function converts this [ComponentLike] into a [String]
119+ * by using the [MiniMessage], provided by the
120+ * [miniMessageSerializer] value.
121+ * This is especially adding the [String]-features like `<rainbow>`!
122+ * @see miniMessageSerializer
123+ * @author Fruxz
124+ * @since 2025.8
125+ * @param serializer the [OpenMiniMessageSerializer] to use for serialization
126+ * @return the serialized string representation of the component
127+ * @see OpenMiniMessageSerializer
128+ * @see ComponentLike.asStyledString
129+ * @see strictMiniMessageSerializer
130+ */
106131fun ComponentLike.asStyledString (
107132 serializer : OpenMiniMessageSerializer = strictMiniMessageSerializer,
108- strict : Boolean = true
109- ) =
110- strict.switch(asStyledString, serializer.serialize(asComponent()))
133+ ) = serializer.serialize(asComponent())
111134
112135/* *
113136 * This computational value converts this [String] into a [TextComponent]
@@ -121,6 +144,21 @@ fun ComponentLike.asStyledString(
121144val String .asStyledComponent: TextComponent
122145 get() = Component .text().append(miniMessageSerializer.deserializeOr(this , Component .empty())!! ).build()
123146
147+ /* *
148+ * This function converts this [String] into a [TextComponent]
149+ * by using the [MiniMessage], provided by the [miniMessageSerializer] value.
150+ * This is especially adding the [String]-features like `<rainbow>`!
151+ * @see miniMessageSerializer
152+ * @author Fruxz
153+ * @since 2025.8
154+ * @param serializer the [OpenMiniMessageSerializer] to use for deserialization
155+ * @param builder the process, to modify the component
156+ * @return the modified component as an [TextComponent]
157+ * @see StackedBuilder
158+ * @see String.asStyledComponent
159+ * @see miniMessageSerializer
160+ * @see OpenMiniMessageSerializer
161+ */
124162inline fun String.asStyledComponent (
125163 serializer : OpenMiniMessageSerializer = miniMessageSerializer,
126164 builder : StackedBuilder .() -> Unit = { },
@@ -140,6 +178,14 @@ inline fun String.asStyledComponent(
140178val String .asStyledComponents: List <TextComponent >
141179 get() = this .lines().asStyledComponents
142180
181+ /* *
182+ * This function converts this [String] into a [TextComponent] list (every entry represents a line)
183+ * by using the [MiniMessage], provided by the [miniMessageSerializer] value.
184+ * This is especially adding the [String]-features like `<rainbow>`!
185+ * @see miniMessageSerializer
186+ * @author Fruxz
187+ * @since 2025.8
188+ */
143189fun String.asStyledComponents (
144190 serializer : OpenMiniMessageSerializer = miniMessageSerializer,
145191): List <TextComponent > = this .lines().asStyledComponents(serializer)
@@ -156,6 +202,15 @@ fun String.asStyledComponents(
156202val Iterable <String >.asStyledComponents: List <TextComponent >
157203 get() = map { it.asStyledComponent }
158204
205+
206+ /* *
207+ * This function converts this [Iterable] of [String]s into a [List] of [TextComponent]s
208+ * by using the [MiniMessage], provided by the [miniMessageSerializer] value.
209+ * This is especially adding the [String]-features like `<rainbow>`!
210+ * @see miniMessageSerializer
211+ * @author Fruxz
212+ * @since 2025.8
213+ */
159214fun Iterable<String>.asStyledComponents (
160215 serializer : OpenMiniMessageSerializer = miniMessageSerializer,
161216): List <TextComponent > = map { it.asStyledComponent(serializer) }
0 commit comments