Skip to content

Commit

Permalink
fix: per-player locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Feb 3, 2024
1 parent f27ede8 commit 6885b88
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ fun Component.escapeEmoteIDs(player: Player?): Component {
* This is because we handle with a player-context first, and escape that in-which should not be formatted.
*/
fun Component.transformEmoteIDs(player: Player?, insert: Boolean = true, unescape: Boolean): Component {
var msg = GlobalTranslator.render(this, player?.locale() ?: Locale.US)
val locale = emojy.languages.find { it.locale == player?.locale() }?.locale ?: Locale.US
var msg = GlobalTranslator.render(this, locale)
val serialized = this.serialize()

for (emote in emojy.emotes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object EmojyNMSHandlers {
// anvil goes like this, inputItem -> readUtf -> renameField -> writeNbt from raw string, which is why it breaks
fun JsonObject.formatString(player: Player? = null) : String {
return if (this.has("args") || this.has("text") || this.has("extra") || this.has("translate")) {
gson.serialize(gson.deserialize(this.toString())/*.toPlainText()*/.serialize().miniMsg().transform(player, true, true))
gson.serialize(gson.deserializeFromTree(this)/*.toPlainText()*/.serialize().miniMsg().transform(player, true, true))
} else this.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ class EmojyNMSHandler : IEmojyNMSHandler {
private class CustomDataSerializer(val player: Player?, bytebuf: ByteBuf) : FriendlyByteBuf(bytebuf) {

override fun writeComponent(component: Component): FriendlyByteBuf {
return super.writeComponent(component.transformEmoteIDs(player, true, false))
return super.writeComponent(component.transformEmoteIDs(player, true, true))
}

override fun writeComponent(text: net.minecraft.network.chat.Component): FriendlyByteBuf {
val component = (text as? AdventureComponent)?.deepConvertedIfPresent() ?: text
return writeComponent(PaperAdventure.asAdventure(component).transformEmoteIDs(player, true, false))
if (text is AdventureComponent) return writeComponent(text.deepConverted())
return writeComponent(PaperAdventure.asAdventure(text).transformEmoteIDs(player, true, false))
}

override fun readComponent(): net.minecraft.network.chat.Component {
Expand Down

0 comments on commit 6885b88

Please sign in to comment.