summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorSho Sakuma <me@m1sk9.dev>2026-08-03 15:19:08 +0900
committerSho Sakuma <me@m1sk9.dev>2026-08-05 01:16:03 +0900
commitd45db164428bb4b350c879bf3f43ceb1cc581955 (patch)
tree2c9ccedf53e5a24597631c97e20201e1caeaff29 /engine
parent576c057bb98dab27c2b97931fc5635603fe1bf57 (diff)
downloadLunaticChat-d45db164428bb4b350c879bf3f43ceb1cc581955.tar.gz
LunaticChat-d45db164428bb4b350c879bf3f43ceb1cc581955.tar.bz2
LunaticChat-d45db164428bb4b350c879bf3f43ceb1cc581955.zip
refactor: keep rendering out of CommandResult
CommandResult carried Adventure Components, which was engine's last Minecraft dependency and the reason CLAUDE.md's "engine has no Minecraft platform dependencies" was not quite true. It also meant a command could not report a result without having already decided how it looks: every site had to pick formatError versus format before it could return. Results now carry text, and LunaticCommandBase.handleResult is the single place that styles it - error red for Failure, normal for SuccessWithMessage. The fail()/ok() helpers from #260 already funnelled every call site through two functions, so this is a change to those two plus the one command that composes its own success text. engine's dependency list is down to kotlinx-serialization, and nothing under engine/src references net.kyori, org.bukkit, com.velocitypowered or io.papermc. Not done: the review also proposed collapsing the per-command `when (error)` blocks into one exception-to-key table. Those blocks pick wording, not just a key - "only owners can delete this channel" reads differently in the ban command than the delete command - so a shared table would hand every caller the same sentence and need per-command overrides on top. Left alone deliberately. Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'engine')
-rw-r--r--engine/build.gradle.kts6
-rw-r--r--engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResult.kt9
-rw-r--r--engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResultTest.kt9
3 files changed, 9 insertions, 15 deletions
diff --git a/engine/build.gradle.kts b/engine/build.gradle.kts
index 2d36116..5782890 100644
--- a/engine/build.gradle.kts
+++ b/engine/build.gradle.kts
@@ -7,10 +7,4 @@ dependencies {
// Exposed to platform modules via api(): the plugin messaging protocol is built on it, so
// both platforms need it on their compile and runtime classpath.
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.11.0")
-
- // Adventure API (provided by platform implementations)
- // Matches what every supported platform ships: Paper 26.2 and Velocity 4.x both bundle 5.2.0.
- compileOnly("net.kyori:adventure-api:5.2.0")
-
- testImplementation("net.kyori:adventure-api:5.2.0")
}
diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResult.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResult.kt
index 9c9d882..c9d7771 100644
--- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResult.kt
+++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResult.kt
@@ -1,10 +1,11 @@
package dev.m1sk9.lunaticChat.engine.command
-import net.kyori.adventure.text.Component
-
/**
* Represents the result of a command execution.
* Uses Kotlin sealed classes for type-safe result handling.
+ *
+ * Messages travel as plain text; turning them into styled output is the platform's job, so this
+ * stays free of any Minecraft or Adventure type.
*/
sealed class CommandResult {
/** Command executed successfully */
@@ -12,12 +13,12 @@ sealed class CommandResult {
/** Command executed successfully with a message to display */
data class SuccessWithMessage(
- val message: Component,
+ val message: String,
) : CommandResult()
/** Command failed with an error message */
data class Failure(
- val message: Component,
+ val message: String,
) : CommandResult()
/** Command failed due to invalid usage */
diff --git a/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResultTest.kt b/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResultTest.kt
index b80f116..a9033d0 100644
--- a/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResultTest.kt
+++ b/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/command/CommandResultTest.kt
@@ -1,6 +1,5 @@
package dev.m1sk9.lunaticChat.engine.command
-import net.kyori.adventure.text.Component
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs
@@ -13,13 +12,13 @@ class CommandResultTest {
@Test
fun `SuccessWithMessage toBrigadierResult should return 1`() {
- val result = CommandResult.SuccessWithMessage(Component.text("ok"))
+ val result = CommandResult.SuccessWithMessage("ok")
assertEquals(1, result.toBrigadierResult())
}
@Test
fun `Failure toBrigadierResult should return 0`() {
- val result = CommandResult.Failure(Component.text("error"))
+ val result = CommandResult.Failure("error")
assertEquals(0, result.toBrigadierResult())
}
@@ -31,7 +30,7 @@ class CommandResultTest {
@Test
fun `SuccessWithMessage should preserve message`() {
- val message = Component.text("Test message")
+ val message = "Test message"
val result = CommandResult.SuccessWithMessage(message)
assertIs<CommandResult.SuccessWithMessage>(result)
assertEquals(message, result.message)
@@ -39,7 +38,7 @@ class CommandResultTest {
@Test
fun `Failure should preserve message`() {
- val message = Component.text("Error message")
+ val message = "Error message"
val result = CommandResult.Failure(message)
assertIs<CommandResult.Failure>(result)
assertEquals(message, result.message)