From ba736575f7e7e00d30a121de3b4ac5017dc19a84 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Jul 2020 23:36:04 +0100 Subject: [PATCH] Fix RGB colors on signs causing chunk issues, fix items names not being displayed correctly --- connector/pom.xml | 12 +++++----- .../translators/item/ItemTranslator.java | 23 +++++++++---------- .../translators/nbt/BasicItemTranslator.java | 12 +++++----- .../connector/utils/MessageUtils.java | 10 ++++---- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index b9bf67ce..3fdd5f37 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -127,20 +127,20 @@ net.kyori - text-api - 3.0.3 + adventure-api + 4.0.0-SNAPSHOT compile net.kyori - text-serializer-gson - 3.0.3 + adventure-text-serializer-gson + 4.0.0-SNAPSHOT compile net.kyori - text-serializer-legacy - 3.0.3 + adventure-text-serializer-legacy + 4.0.0-SNAPSHOT compile diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index 7811d9c0..fde799fe 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -28,17 +28,7 @@ package org.geysermc.connector.network.translators.item; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.message.MessageSerializer; -import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag; -import com.github.steveice10.opennbt.tag.builtin.ByteTag; -import com.github.steveice10.opennbt.tag.builtin.DoubleTag; -import com.github.steveice10.opennbt.tag.builtin.FloatTag; -import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; -import com.github.steveice10.opennbt.tag.builtin.ListTag; -import com.github.steveice10.opennbt.tag.builtin.LongArrayTag; -import com.github.steveice10.opennbt.tag.builtin.LongTag; -import com.github.steveice10.opennbt.tag.builtin.ShortTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; +import com.github.steveice10.opennbt.tag.builtin.*; import com.nukkitx.nbt.NbtList; import com.nukkitx.nbt.NbtMap; import com.nukkitx.nbt.NbtMapBuilder; @@ -46,11 +36,14 @@ import com.nukkitx.nbt.NbtType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.ItemRemapper; -import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.LanguageUtils; +import org.geysermc.connector.utils.MessageUtils; import org.reflections.Reflections; import java.util.*; @@ -167,6 +160,12 @@ public abstract class ItemTranslator { if (display != null) { String name = display.getString("Name"); + // If its not a message convert it + if (!MessageUtils.isMessage(name)) { + TextComponent component = LegacyComponentSerializer.legacy().deserialize(name); + name = GsonComponentSerializer.gson().serialize(component); + } + // Check if its a message to translate if (MessageUtils.isMessage(name)) { // Get the translated name diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java index 776cec72..34c7f43d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java @@ -29,13 +29,13 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.serializer.gson.GsonComponentSerializer; -import net.kyori.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.geysermc.connector.network.translators.ItemRemapper; -import org.geysermc.connector.network.translators.item.NbtItemStackTranslator; import org.geysermc.connector.network.translators.item.ItemEntry; +import org.geysermc.connector.network.translators.item.NbtItemStackTranslator; import org.geysermc.connector.utils.MessageUtils; import java.util.ArrayList; @@ -101,7 +101,7 @@ public class BasicItemTranslator extends NbtItemStackTranslator { message = message.replaceFirst("§r", ""); } Component component = TextComponent.of(message); - return GsonComponentSerializer.INSTANCE.serialize(component); + return GsonComponentSerializer.gson().serialize(component); } private String toBedrockMessage(StringTag tag) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 3a35782d..bf196224 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -35,9 +35,9 @@ import com.github.steveice10.mc.protocol.data.message.style.ChatFormat; import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import net.kyori.text.Component; -import net.kyori.text.serializer.gson.GsonComponentSerializer; -import net.kyori.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.geysermc.connector.network.session.GeyserSession; import java.util.*; @@ -263,12 +263,12 @@ public class MessageUtils { } public static Component phraseJavaMessage(String message) { - return GsonComponentSerializer.INSTANCE.deserialize(message); + return GsonComponentSerializer.gson().deserialize(message); } public static String getJavaMessage(String message) { Component component = LegacyComponentSerializer.legacy().deserialize(message); - return GsonComponentSerializer.INSTANCE.serialize(component); + return GsonComponentSerializer.gson().serialize(component); } /**