diff --git a/.idea/copyright/viabackwards_gpl.xml b/.idea/copyright/viabackwards_gpl.xml
index bf99558e3..8ac66561b 100644
--- a/.idea/copyright/viabackwards_gpl.xml
+++ b/.idea/copyright/viabackwards_gpl.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java
index 0460f341b..04d0176d0 100644
--- a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java
+++ b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedItem.java
@@ -17,7 +17,7 @@
*/
package com.viaversion.viabackwards.api.data;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public class MappedItem {
@@ -32,7 +32,7 @@ public MappedItem(final int id, final String name) {
public MappedItem(final int id, final String name, @Nullable final Integer customModelData) {
this.id = id;
- this.jsonName = ChatRewriter.legacyTextToJsonString("§f" + name, true);
+ this.jsonName = ComponentUtil.legacyToJsonString("§f" + name, true);
this.customModelData = customModelData;
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java
index 582966373..1d2666b72 100644
--- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java
+++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java
@@ -18,11 +18,10 @@
package com.viaversion.viabackwards.api.entities.storage;
-import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -87,7 +86,7 @@ public int typeId() {
}
if (componentType == ComponentType.JSON) {
- return ChatRewriter.legacyTextToJson(name);
+ return ComponentUtil.legacyToJson(name);
} else if (componentType == ComponentType.TAG) {
return new StringTag(name);
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java
index c11087a59..3f57fd70b 100644
--- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java
+++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java
@@ -24,7 +24,7 @@
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -103,7 +103,7 @@ public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant)
int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt();
String loreValue = remappedName + " " + getRomanNumber(level);
if (jsonFormat) {
- loreValue = ChatRewriter.legacyTextToJsonString(loreValue);
+ loreValue = ComponentUtil.legacyToJsonString(loreValue);
}
loreToAdd.add(new StringTag(loreValue));
diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java
index a995f8b37..5919280cc 100644
--- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java
+++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java
@@ -41,7 +41,7 @@
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -278,7 +278,7 @@ protected CompoundTag getNamedTag(String text) {
CompoundTag tag = new CompoundTag();
tag.put("display", new CompoundTag());
text = "§r" + text;
- ((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ChatRewriter.legacyTextToJsonString(text) : text));
+ ((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ComponentUtil.legacyToJsonString(text) : text));
return tag;
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java
index 751f8039d..7509e769a 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java
@@ -25,10 +25,9 @@
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
-import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
-import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
+import com.viaversion.viaversion.util.ComponentUtil;
public class PlayerPackets1_11 {
private static final ValueTransformer TO_NEW_FLOAT = new ValueTransformer(Type.FLOAT) {
@@ -53,8 +52,8 @@ public void register() {
wrapper.clearPacket();
wrapper.setPacketType(ClientboundPackets1_9_3.CHAT_MESSAGE);
- // https://bugs.mojang.com/browse/MC-119145to
- String legacy = LegacyComponentSerializer.legacySection().serialize(GsonComponentSerializer.gson().deserialize(message.toString()));
+ // https://bugs.mojang.com/browse/MC-119145
+ String legacy = ComponentUtil.jsonToLegacy(message);
message = new JsonObject();
message.getAsJsonObject().addProperty("text", legacy);
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java
index e3fff6f70..7ac0ce0b8 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java
@@ -39,15 +39,13 @@
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonParser;
-import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
-import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public class Protocol1_12_2To1_13 extends BackwardsProtocol {
@@ -167,14 +165,6 @@ public String jsonToLegacy(@Nullable JsonElement value) {
}
translatableToLegacyRewriter.processText(value);
-
- try {
- Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(value);
- return LegacyComponentSerializer.legacySection().serialize(component);
- } catch (Exception e) {
- ViaBackwards.getPlatform().getLogger().warning("Error converting json text to legacy: " + value);
- e.printStackTrace();
- }
- return "";
+ return ComponentUtil.jsonToLegacy(value);
}
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
index df1403aec..79bec7b89 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
@@ -50,11 +50,11 @@
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.BlockIdData;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import java.util.ArrayList;
import java.util.HashMap;
@@ -755,7 +755,7 @@ public Item handleItemToServer(Item item) {
StringTag name = displayTag.get("Name");
if (name != null) {
StringTag via = displayTag.remove(extraNbtTag + "|Name");
- name.setValue(via != null ? via.getValue() : ChatRewriter.legacyTextToJsonString(name.getValue()));
+ name.setValue(via != null ? via.getValue() : ComponentUtil.legacyToJsonString(name.getValue()));
}
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java
index 830e49d7b..54d56f7a9 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java
@@ -25,7 +25,12 @@
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
-import com.viaversion.viaversion.api.minecraft.chunks.*;
+import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
+import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
+import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight;
+import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLightImpl;
+import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
+import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.item.Item;
@@ -42,15 +47,14 @@
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.RecipeRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -143,7 +147,7 @@ protected void registerPackets() {
if (title.isJsonObject() && (object = title.getAsJsonObject()).has("translate")) {
// Don't rewrite other 9x3 translatable containers
if (type != 2 || object.getAsJsonPrimitive("translate").getAsString().equals("container.barrel")) {
- title = ChatRewriter.legacyTextToJson(containerTitle);
+ title = ComponentUtil.legacyToJson(containerTitle);
}
}
}
@@ -479,7 +483,7 @@ public Item handleItemToClient(Item item) {
StringTag loreEntryTag = (StringTag) loreEntry;
String value = loreEntryTag.getValue();
if (value != null && !value.isEmpty()) {
- loreEntryTag.setValue(ChatRewriter.jsonToLegacyText(value));
+ loreEntryTag.setValue(ComponentUtil.jsonToLegacy(value));
}
}
}
@@ -503,7 +507,7 @@ public Item handleItemToServer(Item item) {
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {
StringTag loreEntryTag = (StringTag) loreEntry;
- loreEntryTag.setValue(ChatRewriter.legacyTextToJsonString(loreEntryTag.getValue()));
+ loreEntryTag.setValue(ComponentUtil.legacyToJsonString(loreEntryTag.getValue()));
}
}
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java
index eda6c3fdb..113739890 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java
@@ -38,12 +38,12 @@
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
public class Protocol1_13To1_13_1 extends BackwardsProtocol {
@@ -115,7 +115,7 @@ public void register() {
// https://bugs.mojang.com/browse/MC-124543
JsonObject legacyComponent = new JsonObject();
- legacyComponent.addProperty("text", ChatRewriter.jsonToLegacyText(title.toString()));
+ legacyComponent.addProperty("text", ComponentUtil.jsonToLegacy(title));
wrapper.set(Type.COMPONENT, 0, legacyComponent);
}
});
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java
index 6a0269402..f37b59f02 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java
@@ -17,17 +17,13 @@
*/
package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.chat;
-import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
-import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
-import com.viaversion.viaversion.libs.gson.JsonParseException;
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
-import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
-import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
+import com.viaversion.viaversion.util.ComponentUtil;
public class TranslatableRewriter1_16 extends TranslatableRewriter {
@@ -78,33 +74,8 @@ public void processText(JsonElement value) {
}
// show_text as chat component json, show_entity and show_item serialized as snbt
- // Let adventure handle all of that
- try {
- Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
- JsonObject convertedObject;
- try {
- convertedObject = (JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component);
- } catch (JsonParseException e) {
- JsonObject contents = hoverEvent.getAsJsonObject("contents");
- if (contents.remove("tag") == null) {
- throw e; // Just rethrow if this is not an item with a tag provided
- }
-
- // Most likely an invalid nbt tag - try again after its removal
- component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
- convertedObject = (JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component);
- }
-
- // Remove new format
- JsonObject processedHoverEvent = convertedObject.getAsJsonObject("hoverEvent");
- processedHoverEvent.remove("contents");
- object.add("hoverEvent", processedHoverEvent);
- } catch (Exception e) {
- if (!Via.getConfig().isSuppressConversionWarnings()) {
- ViaBackwards.getPlatform().getLogger().severe("Error converting hover event component: " + object);
- e.printStackTrace();
- }
- }
+ JsonObject convertedObject = (JsonObject) ComponentUtil.convertJson(object, ComponentUtil.SerializerVersion.V1_16, ComponentUtil.SerializerVersion.V1_15);
+ object.add("hoverEvent", convertedObject.getAsJsonObject("hoverEvent"));
}
private String getClosestChatColor(int rgb) {
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java
index 869e597ad..b34ccfa56 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java
@@ -44,8 +44,6 @@
import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
-import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
-import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
@@ -57,8 +55,8 @@
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.CipherUtil;
+import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Pair;
-
import java.util.BitSet;
import java.util.List;
@@ -347,7 +345,7 @@ public void register() {
}
final JsonElement unsignedContent = wrapper.read(Type.OPTIONAL_COMPONENT);
- final JsonElement content = unsignedContent != null ? unsignedContent : GsonComponentSerializer.gson().serializeToTree(Component.text(plainContent));
+ final JsonElement content = unsignedContent != null ? unsignedContent : ComponentUtil.plainToJson(plainContent);
translatableRewriter.processText(content);
final int filterMaskType = wrapper.read(Type.VAR_INT);
if (filterMaskType == 2) {
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java
index 472aaaf84..7eb343fbc 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java
@@ -17,7 +17,6 @@
*/
package com.viaversion.viabackwards.protocol.protocol1_19to1_19_1;
-import com.google.common.base.Preconditions;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
@@ -41,28 +40,25 @@
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
-import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
-import com.viaversion.viaversion.libs.kyori.adventure.text.TranslatableComponent;
-import com.viaversion.viaversion.libs.kyori.adventure.text.format.NamedTextColor;
-import com.viaversion.viaversion.libs.kyori.adventure.text.format.Style;
-import com.viaversion.viaversion.libs.kyori.adventure.text.format.TextDecoration;
-import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
-import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
+import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
+import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
+import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
+import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
+import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To1_19;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.CipherUtil;
+import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Pair;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_19To1_19_1 extends BackwardsProtocol {
@@ -160,7 +156,7 @@ public void register() {
}
if (message == null) {
// If no decorated or unsigned message is given, use the plain one
- message = GsonComponentSerializer.gson().serializeToTree(Component.text(plainMessage));
+ message = ComponentUtil.plainToJson(plainMessage);
}
final int filterMaskType = wrapper.read(Type.VAR_INT);
@@ -408,56 +404,6 @@ public EntityPackets1_19_1 getEntityRewriter() {
return null;
}
- final String translationKey = (String) chatType.get("translation_key").getValue();
- final TranslatableComponent.Builder componentBuilder = Component.translatable().key(translationKey);
-
- // Add the style
- final CompoundTag style = chatType.get("style");
- if (style != null) {
- final Style.Builder styleBuilder = Style.style();
- final StringTag color = style.get("color");
- if (color != null) {
- final NamedTextColor textColor = NamedTextColor.NAMES.value(color.getValue());
- if (textColor != null) {
- styleBuilder.color(NamedTextColor.NAMES.value(color.getValue()));
- }
- }
-
- for (final String key : TextDecoration.NAMES.keys()) {
- if (style.contains(key)) {
- styleBuilder.decoration(TextDecoration.NAMES.value(key), style.get(key).asByte() == 1);
- }
- }
- componentBuilder.style(styleBuilder.build());
- }
-
- // Add the replacements
- final ListTag parameters = chatType.get("parameters");
- if (parameters != null) {
- final List arguments = new ArrayList<>();
- for (final Tag element : parameters) {
- JsonElement argument = null;
- switch ((String) element.getValue()) {
- case "sender":
- argument = senderName;
- break;
- case "content":
- argument = message;
- break;
- case "target":
- Preconditions.checkNotNull(targetName, "Target name is null");
- argument = targetName;
- break;
- default:
- ViaBackwards.getPlatform().getLogger().warning("Unknown parameter for chat decoration: " + element.getValue());
- }
- if (argument != null) {
- arguments.add(GsonComponentSerializer.gson().deserializeFromTree(argument));
- }
- }
- componentBuilder.args(arguments);
- }
-
- return GsonComponentSerializer.gson().serializeToTree(componentBuilder.build());
+ return Protocol1_19_1To1_19.translatabaleComponentFromTag(chatType, senderName, targetName, message);
}
}
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java
index cefe9cf7f..205d57436 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java
@@ -47,10 +47,10 @@
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
-import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
+import com.viaversion.viaversion.util.ComponentUtil;
import java.util.BitSet;
import java.util.UUID;
@@ -368,13 +368,13 @@ private PacketHandler resourcePackHandler() {
private void convertComponent(final PacketWrapper wrapper) throws Exception {
final Tag tag = wrapper.read(Type.TAG);
translatableRewriter.processTag(tag);
- wrapper.write(Type.COMPONENT, ComponentConverter.tagComponentToJson(tag));
+ wrapper.write(Type.COMPONENT, ComponentUtil.tagToJson(tag));
}
private void convertOptionalComponent(final PacketWrapper wrapper) throws Exception {
final Tag tag = wrapper.read(Type.OPTIONAL_TAG);
translatableRewriter.processTag(tag);
- wrapper.write(Type.OPTIONAL_COMPONENT, ComponentConverter.tagComponentToJson(tag));
+ wrapper.write(Type.OPTIONAL_COMPONENT, ComponentUtil.tagToJson(tag));
}
@Override
diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java
index 14e48b32d..3ac8307e5 100644
--- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java
+++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java
@@ -33,7 +33,7 @@
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
-import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter;
+import com.viaversion.viaversion.util.ComponentUtil;
public final class EntityPacketRewriter1_20_3 extends EntityRewriter {
@@ -99,10 +99,10 @@ protected void registerRewrites() {
filter().handler((event, meta) -> {
final MetaType type = meta.metaType();
if (type == Types1_20_3.META_TYPES.componentType) {
- meta.setTypeAndValue(Types1_20_2.META_TYPES.componentType, ComponentConverter.tagComponentToJson(meta.value()));
+ meta.setTypeAndValue(Types1_20_2.META_TYPES.componentType, ComponentUtil.tagToJson(meta.value()));
return;
} else if (type == Types1_20_3.META_TYPES.optionalComponentType) {
- meta.setTypeAndValue(Types1_20_2.META_TYPES.optionalComponentType, ComponentConverter.tagComponentToJson(meta.value()));
+ meta.setTypeAndValue(Types1_20_2.META_TYPES.optionalComponentType, ComponentUtil.tagToJson(meta.value()));
return;
} else if (type == Types1_20_3.META_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue();