Skip to content

Commit

Permalink
feat: 🎸 japanizeコマンドをLunaChatの仕様に近い構文に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSheep2804 committed Jul 18, 2023
1 parent e48247f commit 90569df
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
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
override val COMMAND_ALIASES: Array<String> = JapanizeCommand.COMMAND_ALIASES
override val PERMISSION: String = JapanizeCommand.PERMISSION

override fun execute(sender: SeleneChatPlayer, args: Array<String>): 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<String>): List<String> {
return emptyList()
return when (args.size) {
1 -> listOf("on", "off")
else -> emptyList()
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <value>.",
val japanizeSuccessChanged: String = "Your Japanize conversion is set to <value>."
) {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ 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(
val configVersionOutdated: String = "The config file appears to be out of date. The config file will be loaded, but unexpected glitches may occur.",
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()
)

0 comments on commit 90569df

Please sign in to comment.