Skip to content

Commit

Permalink
fix: fix writeNbt escaping tags due to readUtf raw String
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Dec 19, 2023
1 parent 74a7952 commit 78cdb0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.mineinabyss.emojy.nms
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.mineinabyss.emojy.transform
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.idofront.textcomponents.serialize
import com.mineinabyss.idofront.textcomponents.toPlainText
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
import org.bukkit.Bukkit
import org.bukkit.entity.Player

object EmojyNMSHandlers {
Expand Down Expand Up @@ -32,7 +36,7 @@ object EmojyNMSHandlers {
private val gson = GsonComponentSerializer.gson()
fun JsonObject.formatString() : String {
return if (this.has("args") || this.has("text") || this.has("extra") || this.has("translate")) {
gson.serialize(gson.deserializeFromTree(this).transform(null, true))
gson.serialize(gson.deserialize(this.toString()).toPlainText().miniMsg().transform(null, true))
} else this.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.mineinabyss.emojy.nms.EmojyNMSHandlers
import com.mineinabyss.emojy.nms.EmojyNMSHandlers.formatString
import com.mineinabyss.emojy.nms.IEmojyNMSHandler
import com.mineinabyss.emojy.transform
import com.mineinabyss.idofront.messaging.logVal
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.idofront.textcomponents.serialize
import io.netty.buffer.ByteBuf
Expand All @@ -18,6 +17,8 @@ import io.netty.handler.codec.ByteToMessageDecoder
import io.netty.handler.codec.MessageToByteEncoder
import io.papermc.paper.adventure.PaperAdventure
import net.kyori.adventure.text.Component
import net.minecraft.core.IdMap
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
import net.minecraft.nbt.StringTag
Expand All @@ -28,6 +29,8 @@ import net.minecraft.network.protocol.PacketFlow
import net.minecraft.network.protocol.game.ServerboundChatPacket
import net.minecraft.server.MinecraftServer
import net.minecraft.server.network.ServerConnectionListener
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import org.bukkit.Bukkit
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer
import org.bukkit.entity.Player
Expand Down Expand Up @@ -179,10 +182,6 @@ class EmojyNMSHandler : IEmojyNMSHandler {
}
}

//TODO Figure out why renaming items doesnt work
// Example, readUtf for §9Backpack will return <blue>Backpack cuz legacy bad
// readNbt seems to then be called but the Tag/CompoundTag in form of StringTag is {"text":"<blue>Backpackd"}
// Aka the json is not parsing the serialized component correctly even when transformer here uses GsonComponentSerializer
private fun transform(compound: CompoundTag, transformer: Function<String, String>) {
for (key in compound.allKeys) when (val base = compound.get(key)) {
is CompoundTag -> transform(base, transformer)
Expand Down

0 comments on commit 78cdb0c

Please sign in to comment.