Skip to content

Commit

Permalink
feat: ๐ŸŽธ ๆ—ฅๆœฌ่ชžๅŒ–ใฎๆœ‰็„กใ‚’ใ‚ณใƒžใƒณใƒ‰ใงๅˆ‡ใ‚Šๆ›ฟใˆใงใใ‚‹ใ‚ˆใ†ใซ
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSheep2804 committed Jul 13, 2023
1 parent d9a1481 commit 069b3d3
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/io/github/bluesheep2804/selenechat/IPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.github.bluesheep2804.selenechat

import io.github.bluesheep2804.selenechat.config.SeleneChatConfigData
import io.github.bluesheep2804.selenechat.config.SeleneChatConfigManager
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayers
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayersManager
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayer
import io.github.bluesheep2804.selenechat.resource.ResourceData
import io.github.bluesheep2804.selenechat.resource.ResourceManager
Expand All @@ -14,6 +16,9 @@ interface IPlugin {
val resourceManager: ResourceManager
val resource: ResourceData
get() = resourceManager.resource
val japanizePlayersManager: JapanizePlayersManager
val japanizePlayers: JapanizePlayers
get() = japanizePlayersManager.japanizePlayers
fun getAllPlayers(): List<SeleneChatPlayer>
fun getPlayer(name: String): SeleneChatPlayer
fun getPlayer(uuid: UUID): SeleneChatPlayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.github.bluesheep2804.selenechat

import io.github.bluesheep2804.selenechat.config.SeleneChatConfigData
import io.github.bluesheep2804.selenechat.config.SeleneChatConfigManager
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayers
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayersManager
import io.github.bluesheep2804.selenechat.resource.ResourceData
import io.github.bluesheep2804.selenechat.resource.ResourceManager

Expand All @@ -13,6 +15,10 @@ object SeleneChat {
lateinit var resourceManager: ResourceManager
val resource: ResourceData
get() = resourceManager.resource
val japanizePlayersManager: JapanizePlayersManager
get() = plugin.japanizePlayersManager
val japanizePlayers: JapanizePlayers
get() = japanizePlayersManager.japanizePlayers

fun setPluginInstance(plugin: IPlugin) {
this.plugin = plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.bluesheep2804.selenechat

import io.github.bluesheep2804.selenechat.command.JapanizeCommandBungee
import io.github.bluesheep2804.selenechat.command.MessageCommandBungee
import io.github.bluesheep2804.selenechat.command.SeleneChatCommandBungee
import io.github.bluesheep2804.selenechat.config.SeleneChatConfigManager
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayersManager
import io.github.bluesheep2804.selenechat.listener.ChatListenerBungee
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayer
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerBungee
Expand All @@ -16,6 +18,7 @@ class SeleneChatBungee : Plugin(), IPlugin {
private lateinit var adventure: BungeeAudiences
override val configManager: SeleneChatConfigManager = SeleneChatConfigManager(dataFolder)
override val resourceManager: ResourceManager = ResourceManager(dataFolder)
override val japanizePlayersManager: JapanizePlayersManager = JapanizePlayersManager(dataFolder)
init {
SeleneChat.setPluginInstance(this)

Expand All @@ -29,12 +32,14 @@ class SeleneChatBungee : Plugin(), IPlugin {

proxy.pluginManager.registerCommand(this, SeleneChatCommandBungee(this))
proxy.pluginManager.registerCommand(this, MessageCommandBungee(this))
proxy.pluginManager.registerCommand(this, JapanizeCommandBungee(this))

logger.info("Loaded!")
}

override fun onDisable() {
adventure.close()
japanizePlayersManager.save()
}

override fun getAllPlayers(): List<SeleneChatPlayerBungee> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.github.bluesheep2804.selenechat

import io.github.bluesheep2804.selenechat.command.MessageCommand
import io.github.bluesheep2804.selenechat.command.MessageCommandSpigot
import io.github.bluesheep2804.selenechat.command.SeleneChatCommand
import io.github.bluesheep2804.selenechat.command.SeleneChatCommandSpigot
import io.github.bluesheep2804.selenechat.command.*
import io.github.bluesheep2804.selenechat.config.SeleneChatConfigManager
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayersManager
import io.github.bluesheep2804.selenechat.listener.ChatListenerSpigot
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayer
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerOffline
Expand All @@ -18,6 +16,7 @@ class SeleneChatSpigot : JavaPlugin(), IPlugin {
private lateinit var adventure: BukkitAudiences
override val configManager: SeleneChatConfigManager = SeleneChatConfigManager(dataFolder)
override val resourceManager: ResourceManager = ResourceManager(dataFolder)
override val japanizePlayersManager: JapanizePlayersManager = JapanizePlayersManager(dataFolder)
init {
SeleneChat.setPluginInstance(this)

Expand All @@ -31,12 +30,14 @@ class SeleneChatSpigot : JavaPlugin(), IPlugin {

this.getCommand(SeleneChatCommand.COMMAND_NAME)?.setExecutor(SeleneChatCommandSpigot(this))
this.getCommand(MessageCommand.COMMAND_NAME)?.setExecutor(MessageCommandSpigot(this))
this.getCommand(JapanizeCommand.COMMAND_NAME)?.setExecutor(JapanizeCommandSpigot(this))

logger.info("Loaded!")
}

override fun onDisable() {
adventure.close()
japanizePlayersManager.save()
}

fun sendPluginMessage(msg: ByteArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package io.github.bluesheep2804.selenechat
import com.google.inject.Inject
import com.velocitypowered.api.event.Subscribe
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent
import com.velocitypowered.api.plugin.Plugin
import com.velocitypowered.api.plugin.annotation.DataDirectory
import com.velocitypowered.api.proxy.ProxyServer
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier
import io.github.bluesheep2804.selenechat.command.MessageCommand
import io.github.bluesheep2804.selenechat.command.MessageCommandVelocity
import io.github.bluesheep2804.selenechat.command.SeleneChatCommand
import io.github.bluesheep2804.selenechat.command.SeleneChatCommandVelocity
import io.github.bluesheep2804.selenechat.command.*
import io.github.bluesheep2804.selenechat.config.SeleneChatConfigManager
import io.github.bluesheep2804.selenechat.japanize.JapanizePlayersManager
import io.github.bluesheep2804.selenechat.listener.ChatListenerVelocity
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayer
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerOffline
Expand All @@ -25,12 +24,18 @@ import java.util.*
class SeleneChatVelocity @Inject constructor(val proxy: ProxyServer, val logger: Logger, @DataDirectory val dataDirectory: Path) : IPlugin {
override val configManager: SeleneChatConfigManager = SeleneChatConfigManager(dataDirectory.toFile())
override val resourceManager: ResourceManager = ResourceManager(dataDirectory.toFile())
override val japanizePlayersManager: JapanizePlayersManager = JapanizePlayersManager(dataDirectory.toFile())
init {
SeleneChat.setPluginInstance(this)

logger.info(configManager.checkVersion())
}

@Subscribe
fun onProxyShutdown(event: ProxyShutdownEvent) {
japanizePlayersManager.save()
}

@Subscribe
fun onProxyInitialize(event: ProxyInitializeEvent) {
proxy.eventManager.register(this, ChatListenerVelocity(this))
Expand All @@ -45,8 +50,13 @@ class SeleneChatVelocity @Inject constructor(val proxy: ProxyServer, val logger:
.aliases(*MessageCommand.COMMAND_ALIASES)
.plugin(this)
.build()
val japanizeCommandMeta = commandManager.metaBuilder(JapanizeCommand.COMMAND_NAME)
.aliases(*JapanizeCommand.COMMAND_ALIASES)
.plugin(this)
.build()
commandManager.register(seleneChatCommandMeta, SeleneChatCommandVelocity(this))
commandManager.register(messageCommandMeta, MessageCommandVelocity(this))
commandManager.register(japanizeCommandMeta, JapanizeCommandVelocity(this))

logger.info("Loaded!")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.bluesheep2804.selenechat.command

import io.github.bluesheep2804.selenechat.player.SeleneChatPlayer
import net.kyori.adventure.text.Component

class JapanizeCommand : ICommand {
override fun execute(sender: SeleneChatPlayer, args: Array<String>): Boolean {
sender.toggleJapanize()
sender.sendMessage(Component.text(sender.isEnabledJapanize))
return true
}

override fun suggest(sender: SeleneChatPlayer, args: Array<String>): List<String> {
return emptyList()
}

companion object {
const val COMMAND_NAME = "japanize"
val COMMAND_ALIASES = arrayOf("jp")
const val PERMISSION = "selenechat.command.japanize"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.bluesheep2804.selenechat.command

import io.github.bluesheep2804.selenechat.SeleneChatBungee
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerBungee
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerBungeeConsole
import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.connection.ProxiedPlayer
import net.md_5.bungee.api.plugin.Command
import net.md_5.bungee.api.plugin.TabExecutor

class JapanizeCommandBungee(val plugin: SeleneChatBungee) : Command(JapanizeCommand.COMMAND_NAME, JapanizeCommand.PERMISSION, *JapanizeCommand.COMMAND_ALIASES), TabExecutor {
val command = JapanizeCommand()
override fun execute(commandSender: CommandSender, args: Array<String>) {
val sender = when (commandSender) {
is ProxiedPlayer -> SeleneChatPlayerBungee(commandSender)
else -> SeleneChatPlayerBungeeConsole(commandSender)
}
command.execute(sender, args)
}

override fun onTabComplete(commandSender: CommandSender, args: Array<String>): List<String> {
val sender = when (commandSender) {
is ProxiedPlayer -> SeleneChatPlayerBungee(commandSender)
else -> SeleneChatPlayerBungeeConsole(commandSender)
}
return command.suggest(sender, args)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.bluesheep2804.selenechat.command

import io.github.bluesheep2804.selenechat.SeleneChatSpigot
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerSpigot
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerSpigotConsole
import org.bukkit.command.*
import org.bukkit.entity.Player

class JapanizeCommandSpigot(val plugin: SeleneChatSpigot) :CommandExecutor, TabExecutor {
val command = JapanizeCommand()
override fun onCommand(commandSender: CommandSender, command: Command, label: String, args: Array<String>): Boolean {
val sender = when (commandSender) {
is Player -> SeleneChatPlayerSpigot(commandSender)
is ConsoleCommandSender -> SeleneChatPlayerSpigotConsole(commandSender)
else -> return false
}
return this.command.execute(sender, args)
}

override fun onTabComplete(commandSender: CommandSender, command: Command, label: String, args: Array<String>): List<String> {
val sender = when (commandSender) {
is Player -> SeleneChatPlayerSpigot(commandSender)
is ConsoleCommandSender -> SeleneChatPlayerSpigotConsole(commandSender)
else -> return emptyList()
}
return this.command.suggest(sender, args)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.bluesheep2804.selenechat.command

import com.velocitypowered.api.command.SimpleCommand
import com.velocitypowered.api.command.SimpleCommand.Invocation
import com.velocitypowered.api.proxy.ConsoleCommandSource
import com.velocitypowered.api.proxy.Player
import io.github.bluesheep2804.selenechat.SeleneChatVelocity
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerVelocity
import io.github.bluesheep2804.selenechat.player.SeleneChatPlayerVelocityConsole

class JapanizeCommandVelocity(val plugin: SeleneChatVelocity) : SimpleCommand {
val command = JapanizeCommand()
override fun execute(invocation: Invocation) {
val source = invocation.source()
val args = invocation.arguments()
val sender = when (source) {
is Player -> SeleneChatPlayerVelocity(source)
is ConsoleCommandSource -> SeleneChatPlayerVelocityConsole(source)
else -> return
}
command.execute(sender, args)
}

override fun hasPermission(invocation: Invocation): Boolean {
return invocation.source().hasPermission(JapanizeCommand.PERMISSION)
}

override fun suggest(invocation: Invocation): List<String> {
val sender = when (val source = invocation.source()) {
is Player -> SeleneChatPlayerVelocity(source)
is ConsoleCommandSource -> SeleneChatPlayerVelocityConsole(source)
else -> return emptyList()
}
val args = if (invocation.arguments().isNotEmpty()) invocation.arguments() else invocation.arguments() + ""
return command.suggest(sender, args)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.bluesheep2804.selenechat.japanize

import kotlinx.serialization.Serializable

@Serializable
data class JapanizePlayers(
val enable: MutableList<String> = mutableListOf(),
val disable: MutableList<String> = mutableListOf()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.bluesheep2804.selenechat.japanize

import com.charleskorn.kaml.Yaml
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream

class JapanizePlayersManager(private val file: File) {
lateinit var japanizePlayers: JapanizePlayers
init {
reload()
}
fun reload() {
val japanizeFile = File(file, "jp.yml")
if (!file.exists()) {
file.mkdir()
}
if (!japanizeFile.exists()) {
japanizeFile.createNewFile()
val japanizePlayers = JapanizePlayers()
val output = FileOutputStream(japanizeFile)
Yaml.default.encodeToStream(JapanizePlayers.serializer(), japanizePlayers, output)
}
val japanizeFileInputStream = FileInputStream(japanizeFile)
japanizePlayers = Yaml.default.decodeFromStream(JapanizePlayers.serializer(), japanizeFileInputStream)
}
fun save() {
val japanizeFile = File(file, "jp.yml")
if (!file.exists()) {
file.mkdir()
}
val output = FileOutputStream(japanizeFile)
Yaml.default.encodeToStream(JapanizePlayers.serializer(), japanizePlayers, output)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ChatListenerSpigot(private val plugin: SeleneChatSpigot) : Listener {
plugin.server.spigot().broadcast(*BungeeComponentSerializer.get().serialize(returnMessage))
event.isCancelled = true
} else {
val returnMessage = ChatMessage.message(message)
val returnMessage = ChatMessage.message(message, sender.isEnabledJapanize)
event.message = LegacyComponentSerializer.legacySection().serialize(returnMessage)
}
if (config.shouldSendPluginMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ChatMessage {
get() = SimpleDateFormat(config.dateFormat)
private val timeFormat: SimpleDateFormat
get() = SimpleDateFormat(config.timeFormat)
fun message(msg: String): Component {
fun message(msg: String, shouldJapanize: Boolean): Component {
val mm = MiniMessage.miniMessage()
val serializedMessage = if (config.useColorCode) {
LegacyComponentSerializer.legacyAmpersand().deserialize(msg.removePrefix("$"))
Expand All @@ -38,7 +38,7 @@ object ChatMessage {
)
val jpTagResolver = TagResolver.resolver("jp")
{ args: ArgumentQueue, _: Context ->
if (config.convertMode == ConvertMode.NONE || !japaneseConversion.shouldConvert() || msg[0] == '$') {
if (!shouldJapanize || config.convertMode == ConvertMode.NONE || !japaneseConversion.shouldConvert() || msg[0] == '$') {
return@resolver Tag.selfClosingInserting(Component.text(""))
}
val prefix = args.popOr("prefix").value()
Expand All @@ -62,7 +62,7 @@ object ChatMessage {
{ args: ArgumentQueue, _: Context ->
return@resolver serverTag(sender, args)
}
val messageTagResolver = Placeholder.component("message", message(msg))
val messageTagResolver = Placeholder.component("message", message(msg, sender.isEnabledJapanize))
val dateTagResolver = Placeholder.component("date", Component.text(dateFormat.format(Date())))
val timeTagResolver = Placeholder.component("time", Component.text(timeFormat.format(Date())))

Expand Down Expand Up @@ -96,7 +96,7 @@ object ChatMessage {
}
val messageTagResolver = Placeholder.component(
"message",
message(msg)
message(msg, sender.isEnabledJapanize)
)
val dateTagResolver = Placeholder.component("date", Component.text(dateFormat.format(Date())))
val timeTagResolver = Placeholder.component("time", Component.text(timeFormat.format(Date())))
Expand Down

0 comments on commit 069b3d3

Please sign in to comment.