diff --git a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitFormatChatChannelPipelineComponent.kt b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitFormatChatChannelPipelineComponent.kt index e87a51bc5..278ae120d 100644 --- a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitFormatChatChannelPipelineComponent.kt +++ b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitFormatChatChannelPipelineComponent.kt @@ -3,6 +3,7 @@ package com.seventh_root.elysium.chat.bukkit.chatchannel.pipeline import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent.Type.FORMATTER import com.seventh_root.elysium.api.chat.ChatMessageContext +import com.seventh_root.elysium.api.chat.ChatMessagePostProcessContext import com.seventh_root.elysium.api.chat.exception.ChatChannelMessageFormattingFailureException import com.seventh_root.elysium.characters.bukkit.character.BukkitCharacterProvider import com.seventh_root.elysium.chat.bukkit.ElysiumChatBukkit @@ -56,4 +57,39 @@ class BukkitFormatChatChannelPipelineComponent(private val plugin: ElysiumChatBu return formattedMessage } + override fun postProcess(message: String, context: ChatMessagePostProcessContext): String? { + val characterProvider = plugin.core.serviceManager.getServiceProvider(BukkitCharacterProvider::class.java) + val sender = context.sender + val senderCharacter = characterProvider.getActiveCharacter(sender) + val chatChannel = context.chatChannel + var formattedMessage = ChatColor.translateAlternateColorCodes('&', formatString) + if (formattedMessage.contains("\$message")) { + formattedMessage = formattedMessage.replace("\$message", message) + } + if (formattedMessage.contains("\$sender-player")) { + formattedMessage = formattedMessage.replace("\$sender-player", sender.name) + } + if (formattedMessage.contains("\$sender-character")) { + if (senderCharacter != null) { + formattedMessage = formattedMessage.replace("\$sender-character", senderCharacter.name) + } else { + throw ChatChannelMessageFormattingFailureException(ChatColor.translateAlternateColorCodes('&', plugin.config.getString("messages.no-character"))) + } + } + if (formattedMessage.contains("\$receiver-player")) { + formattedMessage = formattedMessage.replace("\$receiver-player", "\$receiver-player") + } + if (formattedMessage.contains("\$receiver-character")) { + formattedMessage = formattedMessage.replace("\$receiver-character", "\$receiver-character") + } + if (formattedMessage.contains("\$channel")) { + formattedMessage = formattedMessage.replace("\$channel", chatChannel.name) + } + if (formattedMessage.contains("\$color") || formattedMessage.contains("\$colour")) { + val chatColorString = ChatColorUtils.closestChatColorToColor(chatChannel.color).toString() + formattedMessage = formattedMessage.replace("\$color", chatColorString).replace("\$colour", chatColorString) + } + return formattedMessage + } + } diff --git a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitGarbleChatChannelPipelineComponent.kt b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitGarbleChatChannelPipelineComponent.kt index d52db5fe2..685835b69 100644 --- a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitGarbleChatChannelPipelineComponent.kt +++ b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitGarbleChatChannelPipelineComponent.kt @@ -3,6 +3,7 @@ package com.seventh_root.elysium.chat.bukkit.chatchannel.pipeline import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent.Type.PRE_PROCESSOR import com.seventh_root.elysium.api.chat.ChatMessageContext +import com.seventh_root.elysium.api.chat.ChatMessagePostProcessContext import com.seventh_root.elysium.core.util.MathUtils import com.seventh_root.elysium.players.bukkit.BukkitPlayer import org.bukkit.ChatColor @@ -35,6 +36,10 @@ class BukkitGarbleChatChannelPipelineComponent(var clearRange: Double) : ChatCha return message } + override fun postProcess(message: String, context: ChatMessagePostProcessContext): String? { + return message + } + private fun garbleMessage(message: String, clarity: Double): String { val newMessage = StringBuilder() val random = Random() diff --git a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitIRCChatChannelPipelineComponent.kt b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitIRCChatChannelPipelineComponent.kt index 083ce78ac..685d736cc 100644 --- a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitIRCChatChannelPipelineComponent.kt +++ b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitIRCChatChannelPipelineComponent.kt @@ -3,6 +3,7 @@ package com.seventh_root.elysium.chat.bukkit.chatchannel.pipeline import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent.Type.POST_PROCESSOR import com.seventh_root.elysium.api.chat.ChatMessageContext +import com.seventh_root.elysium.api.chat.ChatMessagePostProcessContext class BukkitIRCChatChannelPipelineComponent(var ircChannel: String?, var isWhitelist: Boolean) : ChatChannelPipelineComponent() { @@ -13,4 +14,8 @@ class BukkitIRCChatChannelPipelineComponent(var ircChannel: String?, var isWhite return message } + override fun postProcess(message: String, context: ChatMessagePostProcessContext): String? { + return message + } + } diff --git a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitLogChatChannelPipelineComponent.kt b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitLogChatChannelPipelineComponent.kt index 8952b67e2..3e771763b 100644 --- a/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitLogChatChannelPipelineComponent.kt +++ b/bukkit/elysium-chat-bukkit/src/main/kotlin/com/seventh_root/elysium/chat/bukkit/chatchannel/pipeline/BukkitLogChatChannelPipelineComponent.kt @@ -3,20 +3,24 @@ package com.seventh_root.elysium.chat.bukkit.chatchannel.pipeline import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent import com.seventh_root.elysium.api.chat.ChatChannelPipelineComponent.Type.POST_PROCESSOR import com.seventh_root.elysium.api.chat.ChatMessageContext +import com.seventh_root.elysium.api.chat.ChatMessagePostProcessContext import java.io.IOException -class BukkitLogChatChannelPipelineComponent : ChatChannelPipelineComponent() { +class BukkitLogChatChannelPipelineComponent: ChatChannelPipelineComponent() { override val type: ChatChannelPipelineComponent.Type get() = POST_PROCESSOR override fun process(message: String, context: ChatMessageContext): String { + return message + } + + override fun postProcess(message: String, context: ChatMessagePostProcessContext): String { try { context.chatChannel.log(message) } catch (exception: IOException) { exception.printStackTrace() } - return message }