diff --git a/module/module-chat/src/main/kotlin/taboolib/module/chat/SimpleComponent.kt b/module/module-chat/src/main/kotlin/taboolib/module/chat/SimpleComponent.kt index 3bcb4ad89..bfd510207 100644 --- a/module/module-chat/src/main/kotlin/taboolib/module/chat/SimpleComponent.kt +++ b/module/module-chat/src/main/kotlin/taboolib/module/chat/SimpleComponent.kt @@ -11,4 +11,9 @@ interface SimpleComponent { /** 构建为 RawMessage */ fun build(transfer: TextTransfer.() -> Unit = {}): ComponentText + + /** 构建为 RawMessage,并上色 */ + fun buildColored(transfer: TextTransfer.() -> Unit = {}): ComponentText { + return build { colored() } + } } \ No newline at end of file diff --git a/module/module-chat/src/main/kotlin/taboolib/module/chat/impl/DefaultSimpleComponent.kt b/module/module-chat/src/main/kotlin/taboolib/module/chat/impl/DefaultSimpleComponent.kt index 2c52b2655..7f49d081d 100644 --- a/module/module-chat/src/main/kotlin/taboolib/module/chat/impl/DefaultSimpleComponent.kt +++ b/module/module-chat/src/main/kotlin/taboolib/module/chat/impl/DefaultSimpleComponent.kt @@ -51,12 +51,25 @@ class DefaultSimpleComponent(val source: String): SimpleComponent { /** 构建为 RawMessage */ fun build(transfer: TextTransfer): ComponentText { val rawMessage = Components.empty() - root.forEach { block -> + var i = 0 + var lastBlock: ComponentText? = null + val clone = root.toMutableList() + // 移除最后一个空白文本块 + if (clone.isNotEmpty() && clone.last().build(transfer).toRawMessage() == rawMessage.toRawMessage()) { + clone.removeLast() + } + clone.forEach { block -> if (block is TextBlock.NewLine) { rawMessage.newLine() } else { - rawMessage.append(block.build(transfer)) + lastBlock = block.build(transfer) + rawMessage.append(lastBlock!!) } + i++ + } + // 直接返回单段文本,避免出现 extra 连套两层的问题 + if (i == 1) { + return lastBlock!! } return rawMessage }