From a668ac03c780416b575fbdf44232677fd991e278 Mon Sep 17 00:00:00 2001 From: Ashli Katt Date: Sat, 23 Mar 2024 17:56:40 -0500 Subject: [PATCH 1/3] Fix bug where minimessage highlighting may produce ClassCastException MiniMessageHighlighter::highlight may return a value that wasn't able to cast into a BuildableComponent. It may be better to move the check to the call-site in ExpressionHighlighting instead? Seems like more of an issue with MiniMessageHighlighter, though, because it's more specific to styled text. --- .../io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt b/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt index 313fac6c..8914123f 100644 --- a/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt +++ b/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt @@ -1,6 +1,7 @@ package io.github.homchom.recode.ui.text import io.github.homchom.recode.util.std.interpolate +import net.kyori.adventure.text.BuildableComponent import net.kyori.adventure.text.Component import net.kyori.adventure.text.ComponentLike import net.kyori.adventure.text.format.TextDecoration @@ -116,7 +117,7 @@ class MiniMessageHighlighter(private val standardTags: TagResolver) { instance.deserializeToTree(input) } catch (e: Exception) { // https://github.com/KyoriPowered/adventure/issues/1011 - return literalText(input, style().red()) + return literalText(input, style().red()).asComponent() } buildNewInput(root) return instance.deserialize(newInput.toString()) From ac6c4b0c434da4a70f7f306586e3a9942ee9fd88 Mon Sep 17 00:00:00 2001 From: Ashli Katt Date: Sat, 23 Mar 2024 17:57:39 -0500 Subject: [PATCH 2/3] Remove leftover useless import --- .../io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt b/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt index 8914123f..1b74ac94 100644 --- a/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt +++ b/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt @@ -1,7 +1,6 @@ package io.github.homchom.recode.ui.text import io.github.homchom.recode.util.std.interpolate -import net.kyori.adventure.text.BuildableComponent import net.kyori.adventure.text.Component import net.kyori.adventure.text.ComponentLike import net.kyori.adventure.text.format.TextDecoration From 418448347e3b35ef69fc7ad57bde7555f505c2ca Mon Sep 17 00:00:00 2001 From: Ashli Katt Date: Sat, 23 Mar 2024 18:30:13 -0500 Subject: [PATCH 3/3] Change return type of `MiniMessageHighlighter::highlight` to `Component` to prevent possible future cast errors --- .../github/homchom/recode/ui/text/MiniMessageHighlighter.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt b/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt index 1b74ac94..117473c3 100644 --- a/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt +++ b/src/main/java/io/github/homchom/recode/ui/text/MiniMessageHighlighter.kt @@ -2,7 +2,6 @@ package io.github.homchom.recode.ui.text import io.github.homchom.recode.util.std.interpolate import net.kyori.adventure.text.Component -import net.kyori.adventure.text.ComponentLike import net.kyori.adventure.text.format.TextDecoration import net.kyori.adventure.text.minimessage.Context import net.kyori.adventure.text.minimessage.MiniMessage @@ -59,7 +58,7 @@ class MiniMessageHighlighter(private val standardTags: TagResolver) { * - All other valid tags are treated as "literals" and colored gray. */ @Suppress("UnstableApiUsage") // TODO: open issue at adventure github - fun highlight(input: String): ComponentLike { + fun highlight(input: String): Component { // handle the special case of inputs with parser directives // TODO: determine if there is a better way to do this val splitByResets = input.split("") @@ -69,7 +68,7 @@ class MiniMessageHighlighter(private val standardTags: TagResolver) { literal("") } append(highlight(splitByResets.last())) - } + }.asComponent() fun TagNode.input() = with(token()) { input.substring(startIndex(), endIndex()) } fun ValueNode.input() = with(token()) { input.substring(startIndex(), endIndex()) }