diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/EmojyCommands.kt b/core/src/main/kotlin/com/mineinabyss/emojy/EmojyCommands.kt index 2382eaa..a4e7162 100644 --- a/core/src/main/kotlin/com/mineinabyss/emojy/EmojyCommands.kt +++ b/core/src/main/kotlin/com/mineinabyss/emojy/EmojyCommands.kt @@ -7,6 +7,7 @@ import com.mineinabyss.idofront.messaging.success import com.mineinabyss.idofront.textcomponents.miniMsg import net.kyori.adventure.inventory.Book import net.kyori.adventure.text.Component +import net.kyori.adventure.text.TranslatableComponent import net.kyori.adventure.translation.GlobalTranslator import org.bukkit.command.Command import org.bukkit.command.CommandSender @@ -16,12 +17,15 @@ import org.bukkit.entity.Player class EmojyCommands : IdofrontCommandExecutor(), TabCompleter { override val commands = commands(emojy.plugin) { "emojy" { + "lang" { + emojy.languages.map { it.locale }.joinToString { it.toString() }.broadcastVal() + sender.sendMessage(emojy.languages.any { it.locale == (sender as Player).locale() }.toString()) + } "test" { action { - val lang = emojy.languages.first() - sender.sendMessage(GlobalTranslator.render(("" + " : ").miniMsg(), lang.locale)) - sender.sendMessage(GlobalTranslator.render(("" + "" + " : ").miniMsg(), lang.locale)) - //emojy.languages.map { it.locale to it.keys }.joinToString(", ").broadcastVal() + val lang = (sender as? Player)?.locale()?.takeIf { it in emojy.languages.map { it.locale } } ?: emojy.languages.last().locale + sender.sendMessage(GlobalTranslator.render(("" + " : ").miniMsg(), lang)) + sender.sendMessage(GlobalTranslator.render(("" + "" + " : ").miniMsg(), lang)) } } "list" { diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt b/core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt index a577706..aeb10ec 100644 --- a/core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt +++ b/core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt @@ -7,6 +7,7 @@ import com.mineinabyss.idofront.textcomponents.serialize import net.kyori.adventure.key.Key import net.kyori.adventure.text.Component import net.kyori.adventure.text.TextReplacementConfig +import net.kyori.adventure.text.TranslatableComponent import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.kyori.adventure.translation.GlobalTranslator import org.bukkit.entity.Player diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/EmojyPlugin.kt b/core/src/main/kotlin/com/mineinabyss/emojy/EmojyPlugin.kt index 5215e6d..54cf5fe 100644 --- a/core/src/main/kotlin/com/mineinabyss/emojy/EmojyPlugin.kt +++ b/core/src/main/kotlin/com/mineinabyss/emojy/EmojyPlugin.kt @@ -63,7 +63,7 @@ class EmojyPlugin : JavaPlugin() { }.toSet() }) - GlobalTranslator.translator().sources().filter { it.name() == Key.key("emojy", "localization") }.forEach(GlobalTranslator.translator()::removeSource) + GlobalTranslator.translator().sources().filter { it.name() == EmojyTranslator.key }.forEach(GlobalTranslator.translator()::removeSource) GlobalTranslator.translator().addSource(EmojyTranslator()) } } diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/translator/EmojyTranslator.kt b/core/src/main/kotlin/com/mineinabyss/emojy/translator/EmojyTranslator.kt index 0da55d3..21972fd 100644 --- a/core/src/main/kotlin/com/mineinabyss/emojy/translator/EmojyTranslator.kt +++ b/core/src/main/kotlin/com/mineinabyss/emojy/translator/EmojyTranslator.kt @@ -1,13 +1,31 @@ package com.mineinabyss.emojy.translator import com.mineinabyss.emojy.emojy +import com.mineinabyss.idofront.textcomponents.IdofrontTextComponents +import com.mineinabyss.idofront.textcomponents.miniMsg import net.kyori.adventure.key.Key +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.TranslatableComponent +import net.kyori.adventure.translation.Translator import java.util.* -class EmojyTranslator : MiniMessageTranslator() { - override fun getMiniMessageString(key: String, locale: Locale) = - emojy.languages.find { it.locale == locale }?.keys?.get(key) +class EmojyTranslator : Translator { - override fun name() = Key.key("emojy", "localization") + companion object { + val key = Key.key("emojy", "localization") + } + + override fun translate(key: String, locale: Locale) = null + + override fun translate(component: TranslatableComponent, locale: Locale): Component? { + val mmString = emojy.languages.find { it.locale == locale }?.keys?.get(component.key()) ?: return null + val resultingComponent = mmString.miniMsg(EmojyArgumentTag(component.args()).takeIf { component.args().isNotEmpty() } ?: IdofrontTextComponents.globalResolver) + return when { + component.children().isEmpty() -> resultingComponent + else -> resultingComponent.children(component.children()) + } + } + + override fun name() = key } diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/translator/MiniMessageTranslator.kt b/core/src/main/kotlin/com/mineinabyss/emojy/translator/MiniMessageTranslator.kt deleted file mode 100644 index 210b3ef..0000000 --- a/core/src/main/kotlin/com/mineinabyss/emojy/translator/MiniMessageTranslator.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.mineinabyss.emojy.translator - -import com.mineinabyss.idofront.textcomponents.IdofrontTextComponents -import com.mineinabyss.idofront.textcomponents.miniMsg -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.TranslatableComponent -import net.kyori.adventure.translation.Translator -import java.text.MessageFormat -import java.util.* - - -abstract class MiniMessageTranslator : Translator { - - protected abstract fun getMiniMessageString(key: String, locale: Locale): String? - override fun translate(key: String, locale: Locale): MessageFormat? { - return null - } - - override fun translate(component: TranslatableComponent, locale: Locale): Component? { - val mmString = getMiniMessageString(component.key(), locale) ?: return null - val resultingComponent = mmString.miniMsg(EmojyArgumentTag(component.arguments()).takeIf { component.arguments().isNotEmpty() } ?: IdofrontTextComponents.globalResolver) - return when { - component.children().isEmpty() -> resultingComponent - else -> resultingComponent.children(component.children()) - } - } -} diff --git a/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt b/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt index aef36d0..d4e5867 100644 --- a/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt +++ b/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt @@ -177,7 +177,7 @@ class EmojyNMSHandler : IEmojyNMSHandler { override fun readNbt(): CompoundTag? { return super.readNbt()?.apply { - transform(this, EmojyNMSHandlers.transformer()) + transform(this, EmojyNMSHandlers.transformer(player)) } }