Skip to content

Commit

Permalink
fix: partial LiteralContent nms-component incorrectly formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Sep 22, 2024
1 parent 81db7de commit c44d595
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import net.minecraft.core.NonNullList
import net.minecraft.network.Connection
import net.minecraft.network.chat.ChatType
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.contents.PlainTextContents.LiteralContents
import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.common.ClientboundDisconnectPacket
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket
Expand Down Expand Up @@ -153,7 +154,11 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
}

fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false): Component {
return PaperAdventure.asVanilla(PaperAdventure.asAdventure(this).transformEmotes(locale, insert))
return when {
// Sometimes a NMS component is partially Literal, so ensure entire thing is just one LiteralContent with no extra data
contents is LiteralContents && style.isEmpty && siblings.isEmpty() -> (contents as LiteralContents).text.miniMsg()
else -> PaperAdventure.asAdventure(this)
}.transformEmotes(locale, insert).let(PaperAdventure::asVanilla)
}

fun Component.escapeEmoteIDs(player: Player?): Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ class EmojyNMSHandler(emojy: EmojyPlugin) : IEmojyNMSHandler {
}

fun Component.transformEmotes(locale: Locale? = null, insert: Boolean = false): Component {
return PaperAdventure.asVanilla(when (val contents = contents) {
is LiteralContents -> contents.text.miniMsg()
return when {
// Sometimes a NMS component is partially Literal, so ensure entire thing is just one LiteralContent with no extra data
contents is LiteralContents && style.isEmpty && siblings.isEmpty() -> (contents as LiteralContents).text.miniMsg()
else -> PaperAdventure.asAdventure(this)
}.transformEmotes(locale, insert))
}.transformEmotes(locale, insert).let(PaperAdventure::asVanilla)
}

fun Component.escapeEmoteIDs(player: Player?): Component {
Expand Down

0 comments on commit c44d595

Please sign in to comment.