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 /platform-paper | |
| 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>
Diffstat (limited to 'platform-paper')
2 files changed, 5 insertions, 8 deletions
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) { |
