diff --git a/src/main/kotlin/io/github/bluesheep2804/selenechat/command/JapanizeCommand.kt b/src/main/kotlin/io/github/bluesheep2804/selenechat/command/JapanizeCommand.kt index ddca5f1..a75e1eb 100644 --- a/src/main/kotlin/io/github/bluesheep2804/selenechat/command/JapanizeCommand.kt +++ b/src/main/kotlin/io/github/bluesheep2804/selenechat/command/JapanizeCommand.kt @@ -1,7 +1,7 @@ package io.github.bluesheep2804.selenechat.command +import io.github.bluesheep2804.selenechat.SeleneChat.resource import io.github.bluesheep2804.selenechat.player.SeleneChatPlayer -import net.kyori.adventure.text.Component class JapanizeCommand : ICommand { override val COMMAND_NAME: String = JapanizeCommand.COMMAND_NAME @@ -9,13 +9,27 @@ class JapanizeCommand : ICommand { override val PERMISSION: String = JapanizeCommand.PERMISSION override fun execute(sender: SeleneChatPlayer, args: Array): Boolean { - sender.toggleJapanize() - sender.sendMessage(Component.text(sender.isEnabledJapanize)) + if (args.isEmpty()) { + sender.sendMessage(resource.command.japanizeSuccessCurrentValueComponent(sender.isEnabledJapanize)) + } else { + if (args[0] == "on") { + sender.enableJapanize() + } else if (args[0] == "off") { + sender.disableJapanize() + } else { + sender.sendMessage(resource.command.japanizeErrorUnexpectedArgs) + return false + } + sender.sendMessage(resource.command.japanizeSuccessChangedComponent(sender.isEnabledJapanize)) + } return true } override fun suggest(sender: SeleneChatPlayer, args: Array): List { - return emptyList() + return when (args.size) { + 1 -> listOf("on", "off") + else -> emptyList() + } } companion object { diff --git a/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/CommandResourceData.kt b/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/CommandResourceData.kt index be620db..56e1583 100644 --- a/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/CommandResourceData.kt +++ b/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/CommandResourceData.kt @@ -1,5 +1,6 @@ package io.github.bluesheep2804.selenechat.resource +import io.github.bluesheep2804.selenechat.SeleneChat import kotlinx.serialization.Serializable import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor @@ -16,11 +17,35 @@ data class CommandResourceData( @Serializable(with = ComponentSerializer::class) val selenechatErrorSubCommandEmpty: Component = Component.text("empty", NamedTextColor.RED), // TODO: 後で書き直す @Serializable(with = ComponentSerializer::class) - val selenechatSuccessReload: Component = Component.text("reloaded!") // TODO: 書き直す + val selenechatSuccessReload: Component = Component.text("reloaded!"), // TODO: 書き直す + @Serializable(with = ComponentSerializer::class) + val japanizeErrorUnexpectedArgs: Component = Component.text("The argument must be one of [on, off].", NamedTextColor.RED), + val japanizeSuccessCurrentValue: String = "Your Japanize conversion is currently set to .", + val japanizeSuccessChanged: String = "Your Japanize conversion is set to ." ) { fun messageErrorPlayerNotFoundComponent(playerName: String): Component { val mm = MiniMessage.miniMessage() val playerTagResolver = Placeholder.component("player", Component.text(playerName)) return mm.deserialize(messageErrorPlayerNotFound, playerTagResolver) } + fun japanizeSuccessCurrentValueComponent(value: Boolean): Component { + val mm = MiniMessage.miniMessage() + val valueComponent = if (value) { + SeleneChat.resource.enabled + } else { + SeleneChat.resource.disabled + } + val valueTagResolver = Placeholder.component("value", valueComponent) + return mm.deserialize(japanizeSuccessCurrentValue, valueTagResolver) + } + fun japanizeSuccessChangedComponent(value: Boolean): Component { + val mm = MiniMessage.miniMessage() + val valueComponent = if (value) { + SeleneChat.resource.enabled + } else { + SeleneChat.resource.disabled + } + val valueTagResolver = Placeholder.component("value", valueComponent) + return mm.deserialize(japanizeSuccessChanged, valueTagResolver) + } } diff --git a/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/ResourceData.kt b/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/ResourceData.kt index 2e1ae36..7cd398f 100644 --- a/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/ResourceData.kt +++ b/src/main/kotlin/io/github/bluesheep2804/selenechat/resource/ResourceData.kt @@ -2,6 +2,7 @@ package io.github.bluesheep2804.selenechat.resource import kotlinx.serialization.Serializable import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor @Serializable data class ResourceData( @@ -9,6 +10,10 @@ data class ResourceData( val configVersionNewer: String = "The config file has been created with a newer version than the current one. The config file will be loaded, but unexpected glitches may occur.", val configVersionLatest: String = "The config file is up-to-date!", @Serializable(with = ComponentSerializer::class) + val enabled: Component = Component.text("Enabled", NamedTextColor.GREEN), + @Serializable(with = ComponentSerializer::class) + val disabled: Component = Component.text("Disabled", NamedTextColor.RED), + @Serializable(with = ComponentSerializer::class) val hoverTextServer: Component = Component.translatable("selectServer.select"), val command: CommandResourceData = CommandResourceData() )