diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-08-03 15:19:08 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-08-05 01:16:03 +0900 |
| commit | d45db164428bb4b350c879bf3f43ceb1cc581955 (patch) | |
| tree | 2c9ccedf53e5a24597631c97e20201e1caeaff29 | |
| parent | 576c057bb98dab27c2b97931fc5635603fe1bf57 (diff) | |
| download | LunaticChat-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>
5 files changed, 14 insertions, 23 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) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommandBase.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommandBase.kt index 89b9acc..8cfedc7 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommandBase.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/core/LunaticCommandBase.kt @@ -33,7 +33,7 @@ abstract class LunaticCommandBase( protected fun fail( key: String, args: Map<String, String> = emptyMap(), - ): CommandResult = CommandResult.Failure(MessageFormatter.formatError(languageManager.getMessage(key, args))) + ): CommandResult = CommandResult.Failure(languageManager.getMessage(key, args)) /** * A successful result carrying the localized message at [key]. @@ -41,7 +41,7 @@ abstract class LunaticCommandBase( protected fun ok( key: String, args: Map<String, String> = emptyMap(), - ): CommandResult = CommandResult.SuccessWithMessage(MessageFormatter.format(languageManager.getMessage(key, args))) + ): CommandResult = CommandResult.SuccessWithMessage(languageManager.getMessage(key, args)) /** * Helper method for checking player-only restriction. @@ -70,8 +70,8 @@ abstract class LunaticCommandBase( ): Int { when (result) { is CommandResult.Success -> {} - is CommandResult.SuccessWithMessage -> ctx.reply(result.message) - is CommandResult.Failure -> ctx.reply(result.message) + is CommandResult.SuccessWithMessage -> ctx.reply(MessageFormatter.format(result.message)) + is CommandResult.Failure -> ctx.reply(MessageFormatter.formatError(result.message)) is CommandResult.InvalidUsage -> ctx.reply( Component diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelCreateCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelCreateCommand.kt index d1db42d..ac4c78a 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelCreateCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelCreateCommand.kt @@ -13,7 +13,6 @@ import dev.m1sk9.lunaticChat.paper.command.annotation.PlayerOnly import dev.m1sk9.lunaticChat.paper.command.core.CommandContext import dev.m1sk9.lunaticChat.paper.command.core.LunaticSubCommand import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager -import dev.m1sk9.lunaticChat.paper.i18n.MessageFormatter import io.papermc.paper.command.brigadier.CommandSourceStack import io.papermc.paper.command.brigadier.Commands @@ -121,9 +120,7 @@ class ChannelCreateCommand( successMessage } - CommandResult.SuccessWithMessage( - MessageFormatter.format(message), - ) + CommandResult.SuccessWithMessage(message) }, onFailure = { error -> when (error) { |
