Skip to content

Commit

Permalink
feat: add chatty.translation.bypass permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 21, 2024
1 parent cd60c73 commit be770ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object ChattyPermissions {
const val BYPASS_TAG_PERM = "chatty.tags.bypass"
const val BYPASS_CHAT_FILTERS_PERM = "chatty.chat.filters.bypass"
const val MODERATION_PERM = "chatty.moderation"
const val BYPASS_TRANSLATION = "chatty.translation.bypass"
val chatFormattingPerms = mapOf(
Permission("chatty.tags.color") to StandardTags.color(),
Permission("chatty.tags.rainbow") to StandardTags.rainbow(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import com.mineinabyss.idofront.textcomponents.serialize
import korlibs.datastructure.CacheMap
import net.kyori.adventure.chat.SignedMessage
import net.kyori.adventure.text.Component
import org.bukkit.entity.Player

data class TranslatedMessage(val language: TranslationLanguage, val translatedMessage: Component)
val cachedTranslations = CacheMap<SignedMessage, TranslatedMessage>(8)
fun handleMessageTranslation(channel: ChattyChannel, sourceTranslation: ChattyTranslation?, audienceTranslation: ChattyTranslation?, component: Component, signedMessage: SignedMessage): Component {
fun handleMessageTranslation(source: Player, channel: ChattyChannel, sourceTranslation: ChattyTranslation?, audienceTranslation: ChattyTranslation?, component: Component, signedMessage: SignedMessage): Component {
val targetLanguage = when (channel.translation.type) {
// Force translation with targetLanguage
TargetLanguageType.FORCE -> channel.translation.targetLanguage
Expand All @@ -23,7 +24,7 @@ fun handleMessageTranslation(channel: ChattyChannel, sourceTranslation: ChattyTr
TargetLanguageType.ALL_SAME_LANGUAGE -> audienceTranslation?.language?.takeUnless { it != sourceTranslation?.language }
// No translation
TargetLanguageType.NONE -> null
} ?: return component
}?.takeUnless { source.hasPermission(ChattyPermissions.BYPASS_TRANSLATION) } ?: return component

// Only translate if the audience has a different language set, or if it is set to translate same languages
//if (sourceTranslation?.language == targetLanguage) return component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ChatListener : Listener {
playerViewers.forEach { audience ->
val audienceTranslation = audience.toGearyOrNull()?.get<ChattyTranslation>()
var finalMessage = message()
finalMessage = handleMessageTranslation(channel, playerTranslation, audienceTranslation, finalMessage, signedMessage())
finalMessage = handleMessageTranslation(player, channel, playerTranslation, audienceTranslation, finalMessage, signedMessage())
finalMessage = handleChatFilters(finalMessage, player, audience) ?: return@forEach
finalMessage = formatPlayerPingMessage(player, pingedPlayer, audience, finalMessage)
finalMessage = appendChannelFormat(finalMessage, player, channel)
Expand All @@ -107,7 +107,7 @@ class ChatListener : Listener {

val audienceTranslation = audience.toGearyOrNull()?.get<ChattyTranslation>()
var finalMessage = message
finalMessage = handleMessageTranslation(channel, playerTranslation, audienceTranslation, finalMessage, signedMessage())
finalMessage = handleMessageTranslation(player, channel, playerTranslation, audienceTranslation, finalMessage, signedMessage())
finalMessage = handleChatFilters(finalMessage, player, audience) ?: return@renderer Component.empty()
finalMessage = formatPlayerPingMessage(source, pingedPlayer, audience, finalMessage)
finalMessage = appendChannelFormat(finalMessage, player, channel)
Expand Down

0 comments on commit be770ea

Please sign in to comment.