diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ChatRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ChatRewriter.java index c70eb5e38..19a94ad78 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ChatRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ChatRewriter.java @@ -3,27 +3,26 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2; import com.google.gson.JsonElement; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer; import us.myles.ViaVersion.api.rewriters.ComponentRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ComponentRewriter1_13; import us.myles.ViaVersion.util.GsonUtil; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class ChatRewriter { private static final BaseComponent[] EMPTY_COMPONENTS = new BaseComponent[0]; private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13(); // Based on https://github.com/SpigotMC/BungeeCord/blob/master/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java - public static String fromLegacyTextAsString(String message, ChatColor defaultColor) { - List components = new ArrayList<>(); - StringBuilder builder = new StringBuilder(); + public static String fromLegacyTextAsString(String message, ChatColor defaultColor, boolean lore) { + TextComponent headComponent = new TextComponent(); TextComponent component = new TextComponent(); + StringBuilder builder = new StringBuilder(); + if (lore) { + // Workaround for all italic lore + headComponent.setItalic(false); + component.setItalic(true); + } for (int i = 0; i < message.length(); i++) { char c = message.charAt(i); @@ -44,7 +43,7 @@ public class ChatRewriter { component = new TextComponent(old); old.setText(builder.toString()); builder = new StringBuilder(); - components.add(old); + headComponent.addExtra(old); } if (ChatColor.BOLD.equals(format)) { component.setBold(true); @@ -71,13 +70,13 @@ public class ChatRewriter { } component.setText(builder.toString()); - components.add(component); + headComponent.addExtra(component); - return ComponentSerializer.toString(components.toArray(EMPTY_COMPONENTS)); + return ComponentSerializer.toString(headComponent); } public static JsonElement fromLegacyText(String message, ChatColor defaultColor) { - return GsonUtil.getJsonParser().parse(fromLegacyTextAsString(message, defaultColor)); + return GsonUtil.getJsonParser().parse(fromLegacyTextAsString(message, defaultColor, false)); } public static JsonElement legacyTextToJson(String legacyText) { @@ -85,7 +84,7 @@ public class ChatRewriter { } public static String legacyTextToJsonString(String legacyText) { - return fromLegacyTextAsString(legacyText, ChatColor.WHITE); + return fromLegacyTextAsString(legacyText, ChatColor.WHITE, false); } public static String jsonTextToLegacy(String value) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index 15226777c..c93b973f8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -8,6 +8,7 @@ import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.collect.Sets; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.md_5.bungee.api.ChatColor; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -248,7 +249,8 @@ public class InventoryPackets { display.put(new ListTag(NBT_TAG_NAME + "|Lore", lore.clone().getValue())); // Save old lore for (Tag loreEntry : lore) { if (loreEntry instanceof StringTag) { - ((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJsonString(((StringTag) loreEntry).getValue())); + String jsonText = ChatRewriter.fromLegacyTextAsString(((StringTag) loreEntry).getValue(), ChatColor.WHITE, true); + ((StringTag) loreEntry).setValue(jsonText); } } }