From b04e76be78398b5739e27cc0cc606a6c1ac8c232 Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Sun, 2 Aug 2026 19:20:25 +0900 Subject: refactor: express command outcomes as message keys Eighty-nine call sites spelled out the same four-line nest to say "fail with localized message X": CommandResult.Failure( MessageFormatter.formatError( languageManager.getMessage("channel.ban.noPermission"), ), ) The pairing of formatError with getMessage was a convention held together only by copy-paste, so changing how command errors are presented meant touching all eighty-nine. fail() and ok() on LunaticCommandBase own that pairing now, and the call sites read as the intent: fail("channel.ban.noPermission"). Three when(error) blocks turned out to map every arm to the same message, and ChannelCreateCommand ran two parallel whens over one error to pick a key and its parameters separately. Both were only visible once the noise around them was gone. Co-Authored-By: Claude --- .../paper/command/core/LunaticCommandBase.kt | 26 +++++-- .../lunaticChat/paper/command/impl/ReplyCommand.kt | 21 ++---- .../lunaticChat/paper/command/impl/TellCommand.kt | 39 ++-------- .../paper/command/impl/lc/ChannelCommand.kt | 2 +- .../paper/command/impl/lc/LunaticChatCommand.kt | 2 +- .../paper/command/impl/lc/SettingsCommand.kt | 2 +- .../paper/command/impl/lc/StatusCommand.kt | 2 +- .../command/impl/lc/channel/ChannelBanCommand.kt | 82 ++++++---------------- .../impl/lc/channel/ChannelCreateCommand.kt | 37 +++------- .../impl/lc/channel/ChannelDeleteCommand.kt | 35 +++------ .../command/impl/lc/channel/ChannelInfoCommand.kt | 24 ++----- .../impl/lc/channel/ChannelInviteCommand.kt | 82 ++++++---------------- .../command/impl/lc/channel/ChannelJoinCommand.kt | 81 ++++++--------------- .../command/impl/lc/channel/ChannelKickCommand.kt | 78 +++++--------------- .../command/impl/lc/channel/ChannelLeaveCommand.kt | 25 ++----- .../command/impl/lc/channel/ChannelListCommand.kt | 8 +-- .../command/impl/lc/channel/ChannelModCommand.kt | 68 ++++-------------- .../impl/lc/channel/ChannelOwnershipCommand.kt | 68 ++++-------------- .../impl/lc/channel/ChannelStatusCommand.kt | 8 +-- .../impl/lc/channel/ChannelSwitchCommand.kt | 49 ++++--------- .../command/impl/lc/channel/ChannelUnbanCommand.kt | 57 ++++----------- .../command/impl/lcv/VelocityStatusCommand.kt | 2 +- 22 files changed, 209 insertions(+), 589 deletions(-) (limited to 'platform-paper') 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 596d70d..89b9acc 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 @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder import dev.m1sk9.lunaticChat.engine.command.CommandResult import dev.m1sk9.lunaticChat.paper.LunaticChat import dev.m1sk9.lunaticChat.paper.command.annotation.PlayerOnly +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 @@ -23,17 +24,32 @@ abstract class LunaticCommandBase( this::class.annotations.any { it is PlayerOnly } } + /** Source of localized text for [fail] and [ok]. */ + protected open val languageManager: LanguageManager get() = plugin.languageManager + + /** + * A failed result carrying the localized message at [key], formatted as an error. + */ + protected fun fail( + key: String, + args: Map = emptyMap(), + ): CommandResult = CommandResult.Failure(MessageFormatter.formatError(languageManager.getMessage(key, args))) + + /** + * A successful result carrying the localized message at [key]. + */ + protected fun ok( + key: String, + args: Map = emptyMap(), + ): CommandResult = CommandResult.SuccessWithMessage(MessageFormatter.format(languageManager.getMessage(key, args))) + /** * Helper method for checking player-only restriction. * Called at the beginning of execute methods. */ protected fun checkPlayerOnly(ctx: CommandContext): CommandResult? { if (isPlayerOnly && !ctx.isPlayer) { - return CommandResult.Failure( - MessageFormatter.formatError( - plugin.languageManager.getMessage("general.playerOnlyCommand"), - ), - ) + return fail("general.playerOnlyCommand") } return null diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/ReplyCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/ReplyCommand.kt index 1e24430..86cac38 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/ReplyCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/ReplyCommand.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.LunaticCommand import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager -import dev.m1sk9.lunaticChat.paper.i18n.MessageFormatter import dev.m1sk9.lunaticChat.paper.velocity.CrossServerDirectMessageManager import io.papermc.paper.command.brigadier.CommandSourceStack import io.papermc.paper.command.brigadier.Commands @@ -29,7 +28,7 @@ import org.bukkit.Bukkit class ReplyCommand( plugin: LunaticChat, private val dmHandler: DirectMessageHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, private val crossServerDirectMessageManager: CrossServerDirectMessageManager? = null, ) : LunaticCommand(plugin) { override val description: String @@ -59,32 +58,20 @@ class ReplyCommand( val sender = ctx.requirePlayer() val target = dmHandler.getReplyTarget(sender) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.replyTargetNotFound"), - ), - ) + ?: return fail("directMessage.replyTargetNotFound") return when (target) { is ReplyTarget.Local -> { val recipient = Bukkit.getPlayer(target.uuid) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.replyTargetNotFound"), - ), - ) + ?: return fail("directMessage.replyTargetNotFound") dmHandler.sendDirectMessage(sender, recipient, message) CommandResult.Success } is ReplyTarget.Remote -> { val manager = crossServerDirectMessageManager - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.replyTargetNotFound"), - ), - ) + ?: return fail("directMessage.replyTargetNotFound") manager.sendCrossServerMessage(sender, target.playerName, target.serverName, message) CommandResult.Success } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/TellCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/TellCommand.kt index ed2312d..990399e 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/TellCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/TellCommand.kt @@ -14,7 +14,6 @@ import dev.m1sk9.lunaticChat.paper.command.annotation.PlayerOnly import dev.m1sk9.lunaticChat.paper.command.core.CommandContext import dev.m1sk9.lunaticChat.paper.command.core.LunaticCommand import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager -import dev.m1sk9.lunaticChat.paper.i18n.MessageFormatter import dev.m1sk9.lunaticChat.paper.velocity.CrossServerDirectMessageManager import dev.m1sk9.lunaticChat.paper.velocity.RemotePlayerRegistry import io.papermc.paper.command.brigadier.CommandSourceStack @@ -34,7 +33,7 @@ import com.mojang.brigadier.context.CommandContext as BrigadierCommandContext class TellCommand( plugin: LunaticChat, private val directMessageHandler: DirectMessageHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, private val crossServerDirectMessageManager: CrossServerDirectMessageManager? = null, private val remotePlayerRegistry: RemotePlayerRegistry? = null, private val localServerName: String = "", @@ -73,11 +72,7 @@ class TellCommand( val targetName = parts[0] val message = parts.getOrNull(1) if (targetName.isEmpty() || message.isNullOrBlank()) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.usage"), - ), - ) + return fail("directMessage.usage") } return execute(ctx, targetName, message) } @@ -93,28 +88,16 @@ class TellCommand( if (targetName.contains('@')) { val manager = crossServerDirectMessageManager - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.crossServerDisabled"), - ), - ) + ?: return fail("directMessage.crossServerDisabled") val name = targetName.substringBefore('@') val server = targetName.substringAfter('@') if (name.isEmpty() || server.isEmpty()) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.targetOffline", mapOf("target" to targetName)), - ), - ) + return fail("directMessage.targetOffline", mapOf("target" to targetName)) } if (name.equals(sender.name, ignoreCase = true) && server.equals(localServerName, ignoreCase = true) ) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.yourself"), - ), - ) + return fail("directMessage.yourself") } manager.sendCrossServerMessage(sender, name, server, message) return CommandResult.Success @@ -122,18 +105,10 @@ class TellCommand( val recipient = Bukkit.getPlayerExact(targetName) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.targetOffline", mapOf("target" to targetName)), - ), - ) + ?: return fail("directMessage.targetOffline", mapOf("target" to targetName)) if (recipient.uniqueId == sender.uniqueId) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("directMessage.yourself"), - ), - ) + return fail("directMessage.yourself") } directMessageHandler.sendDirectMessage(sender, recipient, message) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/ChannelCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/ChannelCommand.kt index b3a1981..e40ff3b 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/ChannelCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/ChannelCommand.kt @@ -36,7 +36,7 @@ class ChannelCommand( private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, private val notificationHandler: ChannelNotificationHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "channel" override val permissionNode = LunaticChatPermissionNode.Channel diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt index bd9ca9b..5b2ff6e 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/LunaticChatCommand.kt @@ -27,7 +27,7 @@ import io.papermc.paper.command.brigadier.Commands class LunaticChatCommand( plugin: LunaticChat, private val settingHandlerRegistry: SettingHandlerRegistry, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, private val configuration: LunaticChatConfiguration, ) : LunaticCommand(plugin) { override val description: String diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt index e8f66d4..a7afbf5 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/SettingsCommand.kt @@ -27,7 +27,7 @@ import io.papermc.paper.command.brigadier.Commands class SettingsCommand( plugin: LunaticChat, private val settingHandlerRegistry: SettingHandlerRegistry, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "settings" override val permissionNode = LunaticChatPermissionNode.Settings diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt index f47285e..526f1d3 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt @@ -20,7 +20,7 @@ import net.kyori.adventure.text.format.NamedTextColor class StatusCommand( plugin: LunaticChat, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, private val configuration: LunaticChatConfiguration, ) : LunaticSubCommand(plugin) { override val literal = "status" diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelBanCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelBanCommand.kt index c459ca0..a372b26 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelBanCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelBanCommand.kt @@ -27,7 +27,7 @@ class ChannelBanCommand( private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, private val notificationHandler: ChannelNotificationHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "ban" override val permissionNode = LunaticChatPermissionNode.ChannelBan @@ -72,20 +72,12 @@ class ChannelBanCommand( val channelId = channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ban.noActiveChannel"), - ), - ) + ?: return fail("channel.ban.noActiveChannel") // Check if sender has permission (OWNER or MODERATOR) val senderRole = membershipManager.getMemberRoleOrNull(sender.uniqueId, channelId) if (senderRole == null || senderRole == ChannelRole.MEMBER) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ban.noPermission"), - ), - ) + return fail("channel.ban.noPermission") } // Find target player @@ -93,13 +85,9 @@ class ChannelBanCommand( // Check if player exists (has played before or is online) if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.ban.playerNotFound", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.ban.playerNotFound", + mapOf("player" to playerName), ) } @@ -107,23 +95,15 @@ class ChannelBanCommand( // Check if banning self if (targetPlayerId == sender.uniqueId) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ban.cannotBanSelf"), - ), - ) + return fail("channel.ban.cannotBanSelf") } // Check if target has bypass permission val onlineTargetPlayer = Bukkit.getPlayer(playerName) if (onlineTargetPlayer != null && onlineTargetPlayer.hasPermission(LunaticChatPermissionNode.ChannelBypass.permissionNode)) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.ban.cannotBanBypass", - mapOf("player" to onlineTargetPlayer.name), - ), - ), + return fail( + "channel.ban.cannotBanBypass", + mapOf("player" to onlineTargetPlayer.name), ) } @@ -149,50 +129,30 @@ class ChannelBanCommand( // Broadcast ban notification to remaining members notificationHandler.broadcastBan(channelId, playerName, sender.name) - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.ban.success", - mapOf("player" to playerName, "channel" to channelName), - ), - ), + ok( + "channel.ban.success", + mapOf("player" to playerName, "channel" to channelName), ) }, onFailure = { error -> when (error) { is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ban.error"), - ), - ) + fail("channel.ban.error") } is ChannelPlayerBypassBanException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.ban.cannotBanBypass", - mapOf("player" to playerName), - ), - ), + fail( + "channel.ban.cannotBanBypass", + mapOf("player" to playerName), ) } is ChannelPlayerAlreadyBannedException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.ban.alreadyBanned", - mapOf("player" to playerName), - ), - ), + fail( + "channel.ban.alreadyBanned", + mapOf("player" to playerName), ) } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ban.error"), - ), - ) + fail("channel.ban.error") } } }, 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 83382c6..d1db42d 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 @@ -21,7 +21,7 @@ import io.papermc.paper.command.brigadier.Commands class ChannelCreateCommand( plugin: LunaticChat, private val channelManager: ChannelManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "create" override val permissionNode = LunaticChatPermissionNode.ChannelCreate @@ -89,13 +89,9 @@ class ChannelCreateCommand( // Validate channel ID pattern if (!channelId.matches(Channel.CHANNEL_ID_PATTERN)) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.create.invalidId", - mapOf("id" to channelId), - ), - ), + return fail( + "channel.create.invalidId", + mapOf("id" to channelId), ) } @@ -130,25 +126,12 @@ class ChannelCreateCommand( ) }, onFailure = { error -> - val messageKey = - when (error) { - is ChannelLimitExceededException -> - "channel.create.limitExceeded" - else -> - "channel.create.alreadyExists" - } - val params = - when (error) { - is ChannelLimitExceededException -> - mapOf("limit" to error.limit.toString()) - else -> - mapOf("id" to channelId) - } - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage(messageKey, params), - ), - ) + when (error) { + is ChannelLimitExceededException -> + fail("channel.create.limitExceeded", mapOf("limit" to error.limit.toString())) + else -> + fail("channel.create.alreadyExists", mapOf("id" to channelId)) + } }, ) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelDeleteCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelDeleteCommand.kt index 6ac6c00..457151d 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelDeleteCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelDeleteCommand.kt @@ -12,7 +12,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 @@ -20,7 +19,7 @@ import io.papermc.paper.command.brigadier.Commands class ChannelDeleteCommand( plugin: LunaticChat, private val channelManager: ChannelManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "delete" override val permissionNode = LunaticChatPermissionNode.ChannelDelete @@ -79,40 +78,24 @@ class ChannelDeleteCommand( val result = channelManager.deleteChannel(channelId, sender.uniqueId, hasBypass) return result.fold( onSuccess = { - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.delete.success", - mapOf("id" to channelId), - ), - ), + ok( + "channel.delete.success", + mapOf("id" to channelId), ) }, onFailure = { error -> when (error) { is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.delete.notFound", - mapOf("id" to channelId), - ), - ), + fail( + "channel.delete.notFound", + mapOf("id" to channelId), ) } is ChannelNoOwnerPermissionException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.delete.noPermission"), - ), - ) + fail("channel.delete.noPermission") } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.delete.error"), - ), - ) + fail("channel.delete.error") } } }, diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt index a9b464b..43d4515 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt @@ -21,7 +21,7 @@ import org.bukkit.Bukkit class ChannelInfoCommand( plugin: LunaticChat, private val channelManager: ChannelManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { companion object { private const val MAX_MEMBERS_DISPLAY = 10 @@ -69,33 +69,21 @@ class ChannelInfoCommand( // Determine which channel to show info for val channelId = channelIdArg ?: channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.info.noActiveChannel"), - ), - ) + ?: return fail("channel.info.noActiveChannel") // Get channel val channel = channelManager.getChannel(channelId).getOrElse { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.info.notFound", - mapOf("channelId" to channelId), - ), - ), + return fail( + "channel.info.notFound", + mapOf("channelId" to channelId), ) } // Get members val members = channelManager.getChannelMembers(channelId).getOrElse { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.info.error"), - ), - ) + return fail("channel.info.error") } // Get owner name diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInviteCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInviteCommand.kt index 096d80c..e645967 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInviteCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInviteCommand.kt @@ -25,7 +25,7 @@ class ChannelInviteCommand( plugin: LunaticChat, private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "invite" override val permissionNode = LunaticChatPermissionNode.ChannelInvite @@ -64,53 +64,33 @@ class ChannelInviteCommand( // Get sender's active channel val channelId = channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.invite.noActiveChannel"), - ), - ) + ?: return fail("channel.invite.noActiveChannel") // Check if sender has permission (OWNER or MODERATOR) val senderRole = membershipManager.getMemberRoleOrNull(sender.uniqueId, channelId) if (senderRole == null || senderRole == ChannelRole.MEMBER) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.invite.noPermission"), - ), - ) + return fail("channel.invite.noPermission") } // Find target player val targetPlayer = Bukkit.getPlayer(playerName) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.invite.playerNotFound", - mapOf("player" to playerName), - ), - ), + ?: return fail( + "channel.invite.playerNotFound", + mapOf("player" to playerName), ) // Check if inviting self if (targetPlayer.uniqueId == sender.uniqueId) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.invite.cannotInviteSelf"), - ), - ) + return fail("channel.invite.cannotInviteSelf") } // Check if player is banned val isBanned = channelManager.isPlayerBanned(channelId, targetPlayer.uniqueId).getOrElse { false } if (isBanned) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.invite.playerBanned", - mapOf("player" to targetPlayer.name), - ), - ), + return fail( + "channel.invite.playerBanned", + mapOf("player" to targetPlayer.name), ) } @@ -132,50 +112,30 @@ class ChannelInviteCommand( ), ) - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.invite.success", - mapOf("player" to targetPlayer.name, "channel" to channelName), - ), - ), + ok( + "channel.invite.success", + mapOf("player" to targetPlayer.name, "channel" to channelName), ) }, onFailure = { error -> when (error) { is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.invite.error"), - ), - ) + fail("channel.invite.error") } is ChannelMemberLimitExceededException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.invite.channelFull", - mapOf("limit" to error.limit.toString()), - ), - ), + fail( + "channel.invite.channelFull", + mapOf("limit" to error.limit.toString()), ) } is ChannelPlayerBannedException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.invite.playerBanned", - mapOf("player" to targetPlayer.name), - ), - ), + fail( + "channel.invite.playerBanned", + mapOf("player" to targetPlayer.name), ) } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.invite.error"), - ), - ) + fail("channel.invite.error") } } }, diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelJoinCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelJoinCommand.kt index 119e89a..9b154b3 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelJoinCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelJoinCommand.kt @@ -20,7 +20,6 @@ import dev.m1sk9.lunaticChat.paper.command.core.CommandContext import dev.m1sk9.lunaticChat.paper.command.core.LunaticSubCommand import dev.m1sk9.lunaticChat.paper.common.playChannelJoinNotification 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 @@ -30,7 +29,7 @@ class ChannelJoinCommand( private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, private val notificationHandler: ChannelNotificationHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "join" override val permissionNode = LunaticChatPermissionNode.ChannelJoin @@ -76,89 +75,53 @@ class ChannelJoinCommand( // Broadcast join notification to all channel members notificationHandler.broadcastJoin(channelId, sender.name) - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.join.success", - mapOf("channelName" to (channel?.name ?: channelId), "channelId" to channelId), - ), - ), + ok( + "channel.join.success", + mapOf("channelName" to (channel?.name ?: channelId), "channelId" to channelId), ) }, onFailure = { error -> when (error) { is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.join.notFound", - mapOf("channelId" to channelId), - ), - ), + fail( + "channel.join.notFound", + mapOf("channelId" to channelId), ) } is ChannelAlreadyActiveException -> { val channel = channelManager.getChannel(channelId).getOrNull() - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.join.alreadyActive", - mapOf("channelName" to (channel?.name ?: channelId)), - ), - ), + fail( + "channel.join.alreadyActive", + mapOf("channelName" to (channel?.name ?: channelId)), ) } is ChannelMemberAlreadyException -> { val channel = channelManager.getChannel(channelId).getOrNull() - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.join.alreadyMember", - mapOf("channelName" to (channel?.name ?: channelId)), - ), - ), + fail( + "channel.join.alreadyMember", + mapOf("channelName" to (channel?.name ?: channelId)), ) } is ChannelMemberLimitExceededException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.join.channelMemberLimitExceeded", - mapOf("limit" to error.limit.toString()), - ), - ), + fail( + "channel.join.channelMemberLimitExceeded", + mapOf("limit" to error.limit.toString()), ) } is ChannelPlayerMembershipLimitExceededException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.join.playerChannelLimitExceeded", - mapOf("limit" to error.limit.toString()), - ), - ), + fail( + "channel.join.playerChannelLimitExceeded", + mapOf("limit" to error.limit.toString()), ) } is ChannelPlayerBannedException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.join.playerBanned"), - ), - ) + fail("channel.join.playerBanned") } is ChannelPrivateRequiresInvitationException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.join.privateChannel"), - ), - ) + fail("channel.join.privateChannel") } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.join.error"), - ), - ) + fail("channel.join.error") } } }, diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelKickCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelKickCommand.kt index 9443e5f..7aae219 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelKickCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelKickCommand.kt @@ -4,7 +4,6 @@ import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.builder.LiteralArgumentBuilder import dev.m1sk9.lunaticChat.engine.chat.channel.ChannelRole import dev.m1sk9.lunaticChat.engine.command.CommandResult -import dev.m1sk9.lunaticChat.engine.exception.ChannelNotFoundException import dev.m1sk9.lunaticChat.engine.permission.LunaticChatPermissionNode import dev.m1sk9.lunaticChat.paper.LunaticChat import dev.m1sk9.lunaticChat.paper.chat.channel.ChannelManager @@ -25,7 +24,7 @@ class ChannelKickCommand( private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, private val notificationHandler: ChannelNotificationHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "kick" override val permissionNode = LunaticChatPermissionNode.ChannelKick @@ -72,20 +71,12 @@ class ChannelKickCommand( // Get sender's active channel val channelId = channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.kick.noActiveChannel"), - ), - ) + ?: return fail("channel.kick.noActiveChannel") // Check if sender has permission (OWNER or MODERATOR) val senderRole = membershipManager.getMemberRoleOrNull(sender.uniqueId, channelId) if (senderRole == null || senderRole == ChannelRole.MEMBER) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.kick.noPermission"), - ), - ) + return fail("channel.kick.noPermission") } // Find target player @@ -93,13 +84,9 @@ class ChannelKickCommand( // Check if player exists (has played before or is online) if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.kick.playerNotFound", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.kick.playerNotFound", + mapOf("player" to playerName), ) } @@ -107,36 +94,24 @@ class ChannelKickCommand( // Check if kicking self if (targetPlayerId == sender.uniqueId) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.kick.cannotKickSelf"), - ), - ) + return fail("channel.kick.cannotKickSelf") } // Check if target has bypass permission val onlineTargetPlayer = Bukkit.getPlayer(playerName) if (onlineTargetPlayer != null && onlineTargetPlayer.hasPermission(LunaticChatPermissionNode.ChannelBypass.permissionNode)) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.kick.cannotKickBypass", - mapOf("player" to onlineTargetPlayer.name), - ), - ), + return fail( + "channel.kick.cannotKickBypass", + mapOf("player" to onlineTargetPlayer.name), ) } // Check if target is a member val isMember = membershipManager.isMember(targetPlayerId, channelId).getOrElse { false } if (!isMember) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.kick.notMember", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.kick.notMember", + mapOf("player" to playerName), ) } @@ -167,32 +142,13 @@ class ChannelKickCommand( // Broadcast kick notification to remaining members notificationHandler.broadcastKick(channelId, playerName, sender.name) - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.kick.success", - mapOf("player" to playerName, "channel" to channelName), - ), - ), + ok( + "channel.kick.success", + mapOf("player" to playerName, "channel" to channelName), ) }, onFailure = { error -> - when (error) { - is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.kick.error"), - ), - ) - } - else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.kick.error"), - ), - ) - } - } + fail("channel.kick.error") }, ) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelLeaveCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelLeaveCommand.kt index e329ca3..b90895f 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelLeaveCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelLeaveCommand.kt @@ -12,7 +12,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 @@ -22,7 +21,7 @@ class ChannelLeaveCommand( private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, private val notificationHandler: ChannelNotificationHandler, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "leave" override val permissionNode = LunaticChatPermissionNode.ChannelLeave @@ -52,30 +51,18 @@ class ChannelLeaveCommand( notificationHandler.broadcastLeave(currentChannelId, sender.name) } - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.leave.success", - mapOf("channelName" to (currentChannel?.name ?: currentChannelId ?: "Unknown")), - ), - ), + ok( + "channel.leave.success", + mapOf("channelName" to (currentChannel?.name ?: currentChannelId ?: "Unknown")), ) }, onFailure = { error -> when (error) { is ChannelNotMemberException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.leave.noActiveChannel"), - ), - ) + fail("channel.leave.noActiveChannel") } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.leave.error"), - ), - ) + fail("channel.leave.error") } } }, diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelListCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelListCommand.kt index 949f6cc..92a0815 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelListCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelListCommand.kt @@ -23,7 +23,7 @@ import kotlin.math.ceil class ChannelListCommand( plugin: LunaticChat, private val channelManager: ChannelManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { companion object { private const val CHANNELS_PER_PAGE = 10 @@ -183,11 +183,7 @@ class ChannelListCommand( CommandResult.Success }, onFailure = { error -> - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.list.error"), - ), - ) + fail("channel.list.error") }, ) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelModCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelModCommand.kt index 8d9be52..5a6ada8 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelModCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelModCommand.kt @@ -4,7 +4,6 @@ import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.builder.LiteralArgumentBuilder import dev.m1sk9.lunaticChat.engine.chat.channel.ChannelRole import dev.m1sk9.lunaticChat.engine.command.CommandResult -import dev.m1sk9.lunaticChat.engine.exception.ChannelNotFoundException import dev.m1sk9.lunaticChat.engine.permission.LunaticChatPermissionNode import dev.m1sk9.lunaticChat.paper.LunaticChat import dev.m1sk9.lunaticChat.paper.chat.channel.ChannelManager @@ -23,7 +22,7 @@ class ChannelModCommand( plugin: LunaticChat, private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "mod" override val permissionNode = LunaticChatPermissionNode.ChannelMod @@ -69,20 +68,12 @@ class ChannelModCommand( // Get sender's active channel val channelId = channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.mod.noActiveChannel"), - ), - ) + ?: return fail("channel.mod.noActiveChannel") // Check if sender is OWNER val senderRole = membershipManager.getMemberRoleOrNull(sender.uniqueId, channelId) if (senderRole != ChannelRole.OWNER) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.mod.noPermission"), - ), - ) + return fail("channel.mod.noPermission") } // Find target player @@ -90,13 +81,9 @@ class ChannelModCommand( // Check if player exists (has played before or is online) if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.mod.playerNotFound", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.mod.playerNotFound", + mapOf("player" to playerName), ) } @@ -104,23 +91,15 @@ class ChannelModCommand( // Check if modding self if (targetPlayerId == sender.uniqueId) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.mod.cannotModSelf"), - ), - ) + return fail("channel.mod.cannotModSelf") } // Check if target is a member val targetRole = membershipManager.getMemberRoleOrNull(targetPlayerId, channelId) if (targetRole == null) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.mod.notMember", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.mod.notMember", + mapOf("player" to playerName), ) } @@ -157,32 +136,13 @@ class ChannelModCommand( ) } - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.mod.success", - mapOf("player" to playerName, "action" to action, "channel" to channelName), - ), - ), + ok( + "channel.mod.success", + mapOf("player" to playerName, "action" to action, "channel" to channelName), ) }, onFailure = { error -> - when (error) { - is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.mod.error"), - ), - ) - } - else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.mod.error"), - ), - ) - } - } + fail("channel.mod.error") }, ) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelOwnershipCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelOwnershipCommand.kt index 20928bf..3236db4 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelOwnershipCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelOwnershipCommand.kt @@ -4,7 +4,6 @@ import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.builder.LiteralArgumentBuilder import dev.m1sk9.lunaticChat.engine.chat.channel.ChannelRole import dev.m1sk9.lunaticChat.engine.command.CommandResult -import dev.m1sk9.lunaticChat.engine.exception.ChannelNotFoundException import dev.m1sk9.lunaticChat.engine.permission.LunaticChatPermissionNode import dev.m1sk9.lunaticChat.paper.LunaticChat import dev.m1sk9.lunaticChat.paper.chat.channel.ChannelManager @@ -23,7 +22,7 @@ class ChannelOwnershipCommand( plugin: LunaticChat, private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "ownership" override val permissionNode = LunaticChatPermissionNode.ChannelOwnership @@ -70,20 +69,12 @@ class ChannelOwnershipCommand( // Get sender's active channel val channelId = channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ownership.noActiveChannel"), - ), - ) + ?: return fail("channel.ownership.noActiveChannel") // Check if sender is OWNER val senderRole = membershipManager.getMemberRoleOrNull(sender.uniqueId, channelId) if (senderRole != ChannelRole.OWNER) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ownership.noPermission"), - ), - ) + return fail("channel.ownership.noPermission") } // Find target player @@ -91,13 +82,9 @@ class ChannelOwnershipCommand( // Check if player exists (has played before or is online) if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.ownership.playerNotFound", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.ownership.playerNotFound", + mapOf("player" to playerName), ) } @@ -105,23 +92,15 @@ class ChannelOwnershipCommand( // Check if transferring to self if (targetPlayerId == sender.uniqueId) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ownership.cannotTransferToSelf"), - ), - ) + return fail("channel.ownership.cannotTransferToSelf") } // Check if target is a member val targetRole = membershipManager.getMemberRoleOrNull(targetPlayerId, channelId) if (targetRole == null) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.ownership.notMember", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.ownership.notMember", + mapOf("player" to playerName), ) } @@ -144,32 +123,13 @@ class ChannelOwnershipCommand( ) } - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.ownership.success", - mapOf("player" to playerName, "channel" to channelName), - ), - ), + ok( + "channel.ownership.success", + mapOf("player" to playerName, "channel" to channelName), ) }, onFailure = { error -> - when (error) { - is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ownership.error"), - ), - ) - } - else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.ownership.error"), - ), - ) - } - } + fail("channel.ownership.error") }, ) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt index 2da2bb8..bd0f66f 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt @@ -26,7 +26,7 @@ class ChannelStatusCommand( plugin: LunaticChat, private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { companion object { private const val MAX_MEMBERS_DISPLAY = 10 @@ -55,11 +55,7 @@ class ChannelStatusCommand( // Get all player's channels val playerChannelIds = membershipManager.getPlayerChannels(sender.uniqueId).getOrElse { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.status.error"), - ), - ) + return fail("channel.status.error") } // Display header diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSwitchCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSwitchCommand.kt index 974fd38..2f71b7d 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSwitchCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSwitchCommand.kt @@ -14,7 +14,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 @@ -23,7 +22,7 @@ class ChannelSwitchCommand( plugin: LunaticChat, private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "switch" override val permissionNode = LunaticChatPermissionNode.ChannelSwitch @@ -66,54 +65,34 @@ class ChannelSwitchCommand( onSuccess = { val channel = channelManager.getChannel(channelId).getOrNull() - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.switch.success", - mapOf("channelName" to (channel?.name ?: channelId), "channelId" to channelId), - ), - ), + ok( + "channel.switch.success", + mapOf("channelName" to (channel?.name ?: channelId), "channelId" to channelId), ) }, onFailure = { error -> when (error) { is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.switch.notFound", - mapOf("channelId" to channelId), - ), - ), + fail( + "channel.switch.notFound", + mapOf("channelId" to channelId), ) } is ChannelAlreadyActiveException -> { val channel = channelManager.getChannel(channelId).getOrNull() - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.switch.alreadyActive", - mapOf("channelName" to (channel?.name ?: channelId)), - ), - ), + fail( + "channel.switch.alreadyActive", + mapOf("channelName" to (channel?.name ?: channelId)), ) } is ChannelNotMemberException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.switch.notMember", - mapOf("channelId" to channelId), - ), - ), + fail( + "channel.switch.notMember", + mapOf("channelId" to channelId), ) } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.switch.error"), - ), - ) + fail("channel.switch.error") } } }, diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelUnbanCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelUnbanCommand.kt index 1d89b06..43aeaf2 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelUnbanCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelUnbanCommand.kt @@ -14,7 +14,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 import org.bukkit.Bukkit @@ -24,7 +23,7 @@ class ChannelUnbanCommand( plugin: LunaticChat, private val channelManager: ChannelManager, private val membershipManager: ChannelMembershipManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { override val literal = "unban" override val permissionNode = LunaticChatPermissionNode.ChannelUnban @@ -68,20 +67,12 @@ class ChannelUnbanCommand( // Get sender's active channel val channelId = channelManager.getPlayerChannel(sender.uniqueId) - ?: return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.unban.noActiveChannel"), - ), - ) + ?: return fail("channel.unban.noActiveChannel") // Check if sender has permission (OWNER or MODERATOR) val senderRole = membershipManager.getMemberRoleOrNull(sender.uniqueId, channelId) if (senderRole == null || senderRole == ChannelRole.MEMBER) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.unban.noPermission"), - ), - ) + return fail("channel.unban.noPermission") } // Find target player @@ -89,13 +80,9 @@ class ChannelUnbanCommand( // Check if player exists (has played before or is online) if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline) { - return CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.unban.playerNotFound", - mapOf("player" to playerName), - ), - ), + return fail( + "channel.unban.playerNotFound", + mapOf("player" to playerName), ) } @@ -108,40 +95,24 @@ class ChannelUnbanCommand( val channel = channelManager.getChannel(channelId).getOrNull() val channelName = channel?.name ?: channelId - CommandResult.SuccessWithMessage( - MessageFormatter.format( - languageManager.getMessage( - "channel.unban.success", - mapOf("player" to playerName, "channel" to channelName), - ), - ), + ok( + "channel.unban.success", + mapOf("player" to playerName, "channel" to channelName), ) }, onFailure = { error -> when (error) { is ChannelNotFoundException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.unban.error"), - ), - ) + fail("channel.unban.error") } is ChannelPlayerNotBannedException -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage( - "channel.unban.playerNotBanned", - mapOf("player" to playerName), - ), - ), + fail( + "channel.unban.playerNotBanned", + mapOf("player" to playerName), ) } else -> { - CommandResult.Failure( - MessageFormatter.formatError( - languageManager.getMessage("channel.unban.error"), - ), - ) + fail("channel.unban.error") } } }, diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lcv/VelocityStatusCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lcv/VelocityStatusCommand.kt index 2c81197..cb7829b 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lcv/VelocityStatusCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lcv/VelocityStatusCommand.kt @@ -32,7 +32,7 @@ import net.kyori.adventure.text.format.NamedTextColor class VelocityStatusCommand( plugin: LunaticChat, private val velocityConnectionManager: VelocityConnectionManager, - private val languageManager: LanguageManager, + override val languageManager: LanguageManager, ) : LunaticCommand(plugin) { override val description: String get() = languageManager.getMessage("commandDescription.lcv") -- cgit v1.2.1