diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java index a36c3e60..ce1e3b7e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java @@ -30,7 +30,7 @@ import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1; import nl.matsv.viabackwards.protocol.protocol1_15_1to1_15_2.Protocol1_15_1To1_15_2; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15to1_15_1.Protocol1_15To1_15_1; -import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_1.Protocol1_16To1_16_1; +import nl.matsv.viabackwards.protocol.protocol1_16to1_16_1.Protocol1_16To1_16_1; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.protocol.ProtocolVersion; @@ -43,7 +43,7 @@ import static us.myles.ViaVersion.api.protocol.ProtocolRegistry.registerProtocol public interface ViaBackwardsPlatform { - String MINIMUM_VV_VERSION = "3.0.0"; + String MINIMUM_VV_VERSION = "3.0.2"; /** * Initialize ViaBackwards. diff --git a/core/src/main/java/nl/matsv/viabackwards/api/data/MappedItem.java b/core/src/main/java/nl/matsv/viabackwards/api/data/MappedItem.java index f1488b3c..e6954867 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/data/MappedItem.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/data/MappedItem.java @@ -10,7 +10,7 @@ public class MappedItem { public MappedItem(int id, String name) { this.id = id; - this.jsonName = ChatRewriter.legacyTextToJson(ChatColor.RESET + name); + this.jsonName = ChatRewriter.legacyTextToJson(ChatColor.RESET + name).toString(); } public int getId() { diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java index bece05a7..d6b17bce 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java @@ -16,7 +16,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; public class EntityData { private final int id; private final int replacementId; - private String mobName; + private Object mobName; private MetaCreator defaultMeta; public EntityData(int id, int replacementId) { @@ -47,8 +47,11 @@ public class EntityData { return id; } + /** + * @return custom mobname, can be either a String or a JsonElement + */ @Nullable - public String getMobName() { + public Object getMobName() { return mobName; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java index a689fd7c..12d7d039 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java @@ -70,7 +70,7 @@ public class EnchantmentRewriter { Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); String loreValue = enchantmentName + " " + getRomanNumber(level.intValue()); if (jsonFormat) { - loreValue = ChatRewriter.legacyTextToJson(loreValue); + loreValue = ChatRewriter.legacyTextToJson(loreValue).toString(); } lore.add(new StringTag("", loreValue)); diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java index 32aac011..827abfa4 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java @@ -40,7 +40,7 @@ public abstract class ItemRewriter extends ItemRewr // Handle name and lore components StringTag name = tag.get("Name"); if (name != null) { - String newValue = translatableRewriter.processText(name.getValue()); + String newValue = translatableRewriter.processText(name.getValue()).toString(); if (name.getValue().equals(newValue)) { textChanged = true; } @@ -53,7 +53,7 @@ public abstract class ItemRewriter extends ItemRewr if (!(loreEntry instanceof StringTag)) continue; StringTag stringTag = (StringTag) loreEntry; - String newValue = translatableRewriter.processText(stringTag.getValue()); + String newValue = translatableRewriter.processText(stringTag.getValue()).toString(); if (stringTag.getValue().equals(newValue)) { textChanged = true; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index 2c9ff2ab..5ebffbf8 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -246,7 +246,7 @@ public abstract class LegacyBlockItemRewriter exten CompoundTag tag = new CompoundTag(""); tag.put(new CompoundTag("display")); text = ChatColor.RESET + text; - ((CompoundTag) tag.get("display")).put(new StringTag("Name", jsonNameFormat ? ChatRewriter.legacyTextToJson(text) : text)); + ((CompoundTag) tag.get("display")).put(new StringTag("Name", jsonNameFormat ? ChatRewriter.legacyTextToJson(text).toString() : text)); return tag; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java index e7901227..c106dd71 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java @@ -5,17 +5,16 @@ import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.data.VBMappingDataLoader; import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.rewriters.ComponentRewriter; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.util.GsonUtil; import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonObject; -import us.myles.viaversion.libs.gson.JsonPrimitive; import java.util.HashMap; import java.util.Map; -public class TranslatableRewriter { +public class TranslatableRewriter extends ComponentRewriter { private static final Map> TRANSLATABLES = new HashMap<>(); protected final BackwardsProtocol protocol; @@ -50,7 +49,7 @@ public class TranslatableRewriter { protocol.registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { - handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); } @@ -59,7 +58,7 @@ public class TranslatableRewriter { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { - handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); } @@ -68,7 +67,7 @@ public class TranslatableRewriter { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { - handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); } @@ -82,7 +81,7 @@ public class TranslatableRewriter { handler(wrapper -> { int action = wrapper.get(Type.VAR_INT, 0); if (action == 0 || action == 3) { - wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))); + processText(wrapper.passthrough(Type.COMPONENT)); } }); } @@ -95,7 +94,7 @@ public class TranslatableRewriter { public void registerMap() { map(Type.UNSIGNED_BYTE); // Id map(Type.STRING); // Window Type - handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); } @@ -106,7 +105,7 @@ public class TranslatableRewriter { public void registerMap() { map(Type.VAR_INT); // Id map(Type.VAR_INT); // Window Type - handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); } @@ -119,7 +118,7 @@ public class TranslatableRewriter { if (wrapper.passthrough(Type.VAR_INT) == 2) { wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.INT); - wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))); + processText(wrapper.passthrough(Type.COMPONENT)); } }); } @@ -133,7 +132,7 @@ public class TranslatableRewriter { handler(wrapper -> { int action = wrapper.passthrough(Type.VAR_INT); if (action >= 0 && action <= 2) { - wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))); + processText(wrapper.passthrough(Type.COMPONENT)); } }); } @@ -145,84 +144,18 @@ public class TranslatableRewriter { @Override public void registerMap() { handler(wrapper -> { - wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))); - wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))); + processText(wrapper.passthrough(Type.COMPONENT)); + processText(wrapper.passthrough(Type.COMPONENT)); }); } }); } - public String processText(String value) { - JsonElement root = GsonUtil.getJsonParser().parse(value); - processText(root); - return root.toString(); - } - - protected void processText(JsonElement element) { - if (element == null || element.isJsonNull()) return; - if (element.isJsonArray()) { - processAsArray(element); - return; - } - if (element.isJsonPrimitive()) { - handleText(element.getAsJsonPrimitive()); - return; - } - - JsonObject object = element.getAsJsonObject(); - JsonPrimitive text = object.getAsJsonPrimitive("text"); - if (text != null) { - handleText(text); - } - - JsonElement translate = object.get("translate"); - if (translate != null) { - handleTranslate(object, translate.getAsString()); - - JsonElement with = object.get("with"); - if (with != null) { - processAsArray(with); - } - } - - JsonElement extra = object.get("extra"); - if (extra != null) { - processAsArray(extra); - } - - JsonObject hoverEvent = object.getAsJsonObject("hoverEvent"); - if (hoverEvent != null) { - handleHoverEvent(hoverEvent); - } - } - - protected void handleText(JsonPrimitive text) { - // In case this is needed in the future - } - + @Override protected void handleTranslate(JsonObject root, String translate) { String newTranslate = newTranslatables.get(translate); if (newTranslate != null) { root.addProperty("translate", newTranslate); } } - - protected void handleHoverEvent(JsonObject hoverEvent) { - String action = hoverEvent.getAsJsonPrimitive("action").getAsString(); - if (action.equals("show_text")) { - JsonElement value = hoverEvent.get("value"); - processText(value != null ? value : hoverEvent.get("contents")); - } else if (action.equals("show_entity")) { - JsonObject contents = hoverEvent.getAsJsonObject("contents"); - if (contents != null) { - processText(contents.get("name")); - } - } - } - - private void processAsArray(JsonElement element) { - for (JsonElement jsonElement : element.getAsJsonArray()) { - processText(jsonElement); - } - } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 3a4373b4..a0653350 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -270,7 +270,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter TO_NEW_FLOAT = new ValueTransformer(Type.FLOAT) { @@ -43,10 +43,8 @@ public class PlayerPackets1_11 { if (action == 2) { // Convert to the old actionbar way PacketWrapper actionbar = new PacketWrapper(0x0F, null, wrapper.user()); // Chat Message packet - String msg = wrapper.read(Type.STRING); - msg = ChatRewriter.jsonTextToLegacy(msg); - msg = "{\"text\":\"" + msg + "\"}"; - actionbar.write(Type.STRING, msg); + JsonElement msg = wrapper.read(Type.COMPONENT); + actionbar.write(Type.COMPONENT, msg); actionbar.write(Type.BYTE, (byte) 2); // Above hotbar actionbar.send(Protocol1_10To1_11.class); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java index 3afdbe8a..768097aa 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java @@ -31,7 +31,7 @@ public class ShoulderTracker extends StoredObject { public void update() { PacketWrapper wrapper = new PacketWrapper(0x0F, null, getUser()); - wrapper.write(Type.STRING, Protocol1_9To1_8.fixJson(generateString())); + wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(generateString())); wrapper.write(Type.BYTE, (byte) 2); try { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java index 344242e3..508285ae 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java @@ -10,22 +10,28 @@ package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets; -import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations; -import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.rewriters.ComponentRewriter; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; -import us.myles.ViaVersion.util.GsonUtil; import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonObject; -import java.util.Map; - public class ChatPackets1_12 extends Rewriter { + private final ComponentRewriter componentRewriter = new ComponentRewriter() { + @Override + protected void handleTranslate(JsonObject object, String translate) { + String text = AdvancementTranslations.get(translate); + if (text != null) { + object.addProperty("translate", text); + } + } + }; + public ChatPackets1_12(Protocol1_11_1To1_12 protocol) { super(protocol); } @@ -35,68 +41,14 @@ public class ChatPackets1_12 extends Rewriter { protocol.registerOutgoing(ClientboundPackets1_12.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { - map(Type.STRING); // 0 - Json Data + map(Type.COMPONENT); // 0 - Json Data map(Type.BYTE); // 1 - Position handler(wrapper -> { - try { - JsonObject object = GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0)).getAsJsonObject(); - // Skip if the root doesn't contain translate - if (object.has("translate")) { - handleTranslations(object); - } - - ChatItemRewriter.toClient(object, wrapper.user()); - wrapper.set(Type.STRING, 0, object.toString()); - } catch (Exception e) { - // Only print if ViaVer debug is enabled - if (Via.getManager().isDebug()) { - ViaBackwards.getPlatform().getLogger().severe("Failed to handle translations"); - e.printStackTrace(); - } - } + JsonElement element = wrapper.passthrough(Type.COMPONENT); + componentRewriter.processText(element); }); } }); - - } - - // improve this, not copying will cause ConcurrentModificationException - public void handleTranslations(JsonObject object) { - JsonObject copiedObj = copy(object); - - if (object.isJsonObject()) { - for (Map.Entry entry : copiedObj.entrySet()) { - // Get the text that doesn't exist for 1.11 < - - if (entry.getKey().equalsIgnoreCase("translate")) { - String translate = entry.getValue().getAsString(); - String text = AdvancementTranslations.get(translate); - if (text != null) { - object.addProperty("translate", text); - } - } - // Handle arrays - if (entry.getValue().isJsonArray()) - for (JsonElement element : object.get(entry.getKey()).getAsJsonArray()) - if (element.isJsonObject()) - handleTranslations(element.getAsJsonObject()); - - // Handle objects - if (entry.getValue().isJsonObject()) - handleTranslations(object.get(entry.getKey()).getAsJsonObject()); - } - } - } - - public JsonObject copy(JsonObject object) { - JsonObject result = new JsonObject(); - for (Map.Entry entry : object.entrySet()) { - if (entry.getValue().isJsonObject()) - result.add(entry.getKey(), copy(entry.getValue().getAsJsonObject())); - else - result.add(entry.getKey(), entry.getValue()); - } - return result; } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 9fc79264..e8ac292f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -441,7 +441,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It byte z = wrapper.read(Type.BYTE); byte direction = wrapper.read(Type.BYTE); if (wrapper.read(Type.BOOLEAN)) { - wrapper.read(Type.STRING); + wrapper.read(Type.COMPONENT); } if (type > 9) { wrapper.set(Type.VAR_INT, 1, wrapper.get(Type.VAR_INT, 1) - 1); @@ -789,7 +789,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It StringTag name = displayTag.get("Name"); if (name instanceof StringTag) { displayTag.put(new StringTag(extraNbtTag + "|Name", name.getValue())); - name.setValue(ChatRewriter.legacyTextToJson(name.getValue())); + name.setValue(ChatRewriter.legacyTextToJson(name.getValue()).toString()); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index 8f440557..310cfc4b 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -21,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12 import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; +import us.myles.viaversion.libs.gson.JsonElement; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -171,7 +172,7 @@ public class PlayerPacket1_13 extends Rewriter { packetWrapper.passthrough(Type.VAR_INT); packetWrapper.passthrough(Type.VAR_INT); if (packetWrapper.passthrough(Type.BOOLEAN)) { - packetWrapper.passthrough(Type.STRING); + packetWrapper.passthrough(Type.COMPONENT); } } else if (action == 1) { // Update Game Mode packetWrapper.passthrough(Type.VAR_INT); @@ -179,7 +180,7 @@ public class PlayerPacket1_13 extends Rewriter { packetWrapper.passthrough(Type.VAR_INT); } else if (action == 3) { // Update Display Name if (packetWrapper.passthrough(Type.BOOLEAN)) { - packetWrapper.passthrough(Type.STRING); + packetWrapper.passthrough(Type.COMPONENT); } } else if (action == 4) { // Remove Player storage.usernames.remove(uuid); @@ -200,9 +201,12 @@ public class PlayerPacket1_13 extends Rewriter { public void handle(PacketWrapper wrapper) throws Exception { byte mode = wrapper.get(Type.BYTE, 0); if (mode == 0 || mode == 2) { - String value = wrapper.read(Type.STRING); + String value = wrapper.read(Type.COMPONENT).toString(); value = ChatRewriter.jsonTextToLegacy(value); - if (value.length() > 32) value = value.substring(0, 32); + if (value.length() > 32) { + value = value.substring(0, 32); + } + wrapper.write(Type.STRING, value); int type = wrapper.read(Type.VAR_INT); wrapper.write(Type.STRING, type == 1 ? "hearts" : "integer"); @@ -237,9 +241,10 @@ public class PlayerPacket1_13 extends Rewriter { colour = -1; } - String prefix = wrapper.read(Type.STRING); - String suffix = wrapper.read(Type.STRING); - prefix = prefix == null || prefix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(prefix); + JsonElement prefixComponent = wrapper.read(Type.COMPONENT); + JsonElement suffixComponent = wrapper.read(Type.COMPONENT); + + String prefix = prefixComponent == null || prefixComponent.isJsonNull() ? "" : ChatRewriter.jsonTextToLegacy(prefixComponent.toString()); if (ViaBackwards.getConfig().addTeamColorTo1_13Prefix()) { prefix += "§" + (colour > -1 && colour <= 15 ? Integer.toHexString(colour) : "r"); } @@ -248,7 +253,7 @@ public class PlayerPacket1_13 extends Rewriter { if (prefix.length() > 16) prefix = prefix.substring(0, 16); if (prefix.endsWith("§")) prefix = prefix.substring(0, prefix.length() - 1); - suffix = suffix == null || suffix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(suffix); + String suffix = suffixComponent == null || suffixComponent.isJsonNull() ? "" : ChatRewriter.jsonTextToLegacy(suffixComponent.toString()); suffix = ChatUtil.removeUnusedColor(suffix, 'f'); if (suffix.length() > 16) suffix = suffix.substring(0, 16); if (suffix.endsWith("§")) suffix = suffix.substring(0, suffix.length() - 1); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index 38664510..dfa29f92 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -34,7 +34,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14 import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -import us.myles.ViaVersion.util.GsonUtil; +import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.opennbt.conversion.ConverterRegistry; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -137,19 +137,19 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It wrapper.write(Type.STRING, stringType); - String title = wrapper.read(Type.COMPONENT_STRING); + JsonElement title = wrapper.read(Type.COMPONENT); if (containerTitle != null) { // Don't rewrite renamed, only translatable titles - JsonObject object = GsonUtil.getGson().fromJson(title, JsonObject.class); - if (object.has("translate")) { + JsonObject object; + 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); } } } - wrapper.write(Type.COMPONENT_STRING, title); + wrapper.write(Type.COMPONENT, title); wrapper.write(Type.UNSIGNED_BYTE, (short) slotSize); } }); @@ -165,7 +165,9 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It public void handle(PacketWrapper wrapper) throws Exception { wrapper.passthrough(Type.UNSIGNED_BYTE); // Window id wrapper.write(Type.STRING, "EntityHorse"); // Type - wrapper.write(Type.STRING, "{\"translate\":\"minecraft.horse\"}"); // Title + JsonObject object = new JsonObject(); + object.addProperty("translate", "minecraft.horse"); + wrapper.write(Type.COMPONENT, object); // Title wrapper.write(Type.UNSIGNED_BYTE, wrapper.read(Type.VAR_INT).shortValue()); // Number of slots wrapper.passthrough(Type.INT); // Entity id } @@ -573,7 +575,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It display.put(ConverterRegistry.convertToTag(nbtTagName + "|Lore", ConverterRegistry.convertToValue(lore))); for (Tag loreEntry : lore) { if (loreEntry instanceof StringTag) { - ((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJson(((StringTag) loreEntry).getValue())); + ((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJson(((StringTag) loreEntry).getValue()).toString()); } } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index 2b64c4c4..8d0dc3d2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -103,7 +103,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol wrapper.write(Type.COMPONENT_STRING, translatableRewriter.processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT))); map(Type.BYTE); map(Type.UUID, Type.NOTHING); // Sender } @@ -64,7 +64,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol wrapper.write(Type.COMPONENT_STRING, translatableRewriter.processText(wrapper.read(Type.COMPONENT_STRING)))); + handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT))); handler(wrapper -> { int windowType = wrapper.get(Type.VAR_INT, 1); if (windowType == 20) { // Smithing table diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java index cf6d20fc..bccd5007 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java @@ -31,7 +31,7 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter { super(protocol); } - protected void processText(JsonElement value) { + public void processText(JsonElement value) { super.processText(value); if (!value.isJsonObject()) return; diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java index 83b49ff0..1cad7fd4 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java @@ -19,6 +19,7 @@ import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; +import us.myles.viaversion.libs.gson.JsonElement; public class EntityPackets1_16 extends EntityRewriter { @@ -143,9 +144,9 @@ public class EntityPackets1_16 extends EntityRewriter { Particle particle = (Particle) meta.getValue(); particle.setId(ParticleMapping.getOldId(particle.getId())); } else if (type == MetaType1_14.OptChat) { - String text = meta.getCastedValue(); + JsonElement text = meta.getCastedValue(); if (text != null) { - meta.setValue(protocol.getTranslatableRewriter().processText(text)); + protocol.getTranslatableRewriter().processText(text); } } return meta; diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_1/Protocol1_16To1_16_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16to1_16_1/Protocol1_16To1_16_1.java similarity index 89% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_1/Protocol1_16To1_16_1.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16to1_16_1/Protocol1_16To1_16_1.java index 8ce88dce..fe777c8a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_1/Protocol1_16To1_16_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16to1_16_1/Protocol1_16To1_16_1.java @@ -1,4 +1,4 @@ -package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_1; +package nl.matsv.viabackwards.protocol.protocol1_16to1_16_1; import nl.matsv.viabackwards.api.BackwardsProtocol; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;