Skip to content

Commit eca92c7

Browse files
committed
✨ 增加 executeCommand 方法的 need_color 参数以支持颜色输出
1 parent 0982dd7 commit eca92c7

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

bukkit/src/main/kotlin/org/crashvibe/FGateBukkit/handler/Command.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.crashvibe.FGateBukkit.handler
22

33
import net.kyori.adventure.text.Component
4+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
45
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
56
import org.bukkit.Bukkit
67
import org.crashvibe.FGateBukkit.FGateBukkit
@@ -9,10 +10,15 @@ import java.util.function.Consumer
910

1011

1112
class Command : Command() {
12-
override fun executeCommand(command: String): CommandResult {
13+
override fun executeCommand(command: String, need_color: Boolean): CommandResult {
1314
val messages: MutableList<String> = mutableListOf()
1415
val sender = Bukkit.createCommandSender(Consumer { feedback: Component ->
15-
messages.add(PlainTextComponentSerializer.plainText().serialize(feedback))
16+
val serialized = if (need_color) {
17+
LegacyComponentSerializer.legacyAmpersand().serialize(feedback)
18+
} else {
19+
PlainTextComponentSerializer.plainText().serialize(feedback)
20+
}
21+
messages.add(serialized)
1622
})
1723
val latch = java.util.concurrent.CountDownLatch(1)
1824
var success = false

common/src/main/kotlin/org/crashvibe/FGateClient/websocket/impl/Command.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.crashvibe.FGateClient.websocket.impl
22

33
import com.crashvibe.fgateclient.handler.RequestHandler
4+
import kotlinx.serialization.SerialName
45
import kotlinx.serialization.Serializable
56
import kotlinx.serialization.json.JsonElement
67
import org.crashvibe.FGateClient.websocket.JsonRpcRequest
@@ -12,6 +13,8 @@ abstract class Command : RequestHandler() {
1213
@Serializable
1314
data class Command(
1415
val command: String,
16+
@SerialName("need_color")
17+
val needColor: Boolean,
1518
)
1619

1720
@Serializable
@@ -22,8 +25,8 @@ abstract class Command : RequestHandler() {
2225

2326
override fun handle(request: JsonRpcRequest<JsonElement>) {
2427
val params = parseParams<Command>(request) ?: return
25-
sendResponse(request.id, executeCommand(params.command))
28+
sendResponse(request.id, executeCommand(params.command, params.needColor))
2629
}
2730

28-
abstract fun executeCommand(command: String): CommandResult
31+
abstract fun executeCommand(command: String, need_color: Boolean): CommandResult
2932
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version=0.0.2
2-
apiVersion=0.0.1
2+
apiVersion=0.0.2
33
group=org.crashvibe
44
description=Client plugin for FlowGate Nexus, providing simplified server connectivity.

0 commit comments

Comments
 (0)