mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-26 03:55:28 +01:00
Improve 1.13->1.14 lore conversion, remove noisy workaround for a non-issue in legacy to json conversion
If people want to have white, unformatted text in their lore, they should do exactly that; add a white color, not reset to default Fixes #2158
This commit is contained in:
parent
a6043c14cd
commit
510ff4e6a1
@ -20,7 +20,7 @@ public class ChatRewriter {
|
||||
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 JsonElement fromLegacyText(String message, ChatColor defaultColor) {
|
||||
public static String fromLegacyTextAsString(String message, ChatColor defaultColor) {
|
||||
List<BaseComponent> components = new ArrayList<>();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
TextComponent component = new TextComponent();
|
||||
@ -61,23 +61,9 @@ public class ChatRewriter {
|
||||
|
||||
component = new TextComponent();
|
||||
component.setColor(format);
|
||||
// ViaVersion start - Items have style default to italic
|
||||
component.setBold(false);
|
||||
component.setItalic(false);
|
||||
component.setUnderlined(false);
|
||||
component.setStrikethrough(false);
|
||||
component.setObfuscated(false);
|
||||
// ViaVersion end
|
||||
} else {
|
||||
component = new TextComponent();
|
||||
component.setColor(format);
|
||||
// ViaVersion start- Items have style default to italic
|
||||
component.setBold(false);
|
||||
component.setItalic(false);
|
||||
component.setUnderlined(false);
|
||||
component.setStrikethrough(false);
|
||||
component.setObfuscated(false);
|
||||
// ViaVersion end
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -87,14 +73,21 @@ public class ChatRewriter {
|
||||
component.setText(builder.toString());
|
||||
components.add(component);
|
||||
|
||||
final String serializedComponents = ComponentSerializer.toString(components.toArray(EMPTY_COMPONENTS));
|
||||
return GsonUtil.getJsonParser().parse(serializedComponents);
|
||||
return ComponentSerializer.toString(components.toArray(EMPTY_COMPONENTS));
|
||||
}
|
||||
|
||||
public static JsonElement fromLegacyText(String message, ChatColor defaultColor) {
|
||||
return GsonUtil.getJsonParser().parse(fromLegacyTextAsString(message, defaultColor));
|
||||
}
|
||||
|
||||
public static JsonElement legacyTextToJson(String legacyText) {
|
||||
return fromLegacyText(legacyText, ChatColor.WHITE);
|
||||
}
|
||||
|
||||
public static String legacyTextToJsonString(String legacyText) {
|
||||
return fromLegacyTextAsString(legacyText, ChatColor.WHITE);
|
||||
}
|
||||
|
||||
public static String jsonTextToLegacy(String value) {
|
||||
return TextComponent.toLegacyText(ComponentSerializer.parse(value));
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ public class InventoryPackets {
|
||||
if (display.get("Name") instanceof StringTag) {
|
||||
StringTag name = display.get("Name");
|
||||
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
|
||||
name.setValue(ChatRewriter.legacyTextToJson(name.getValue()).toString());
|
||||
name.setValue(ChatRewriter.legacyTextToJsonString(name.getValue()));
|
||||
}
|
||||
}
|
||||
// ench is now Enchantments and now uses identifiers
|
||||
|
@ -55,7 +55,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
|
||||
Tag name = tag.get("CustomName");
|
||||
if (name instanceof StringTag) {
|
||||
((StringTag) name).setValue(ChatRewriter.legacyTextToJson(((StringTag) name).getValue()).toString());
|
||||
((StringTag) name).setValue(ChatRewriter.legacyTextToJsonString(((StringTag) name).getValue()));
|
||||
}
|
||||
|
||||
return blockId;
|
||||
|
@ -14,7 +14,7 @@ public class CommandBlockHandler implements BlockEntityProvider.BlockEntityHandl
|
||||
public int transform(UserConnection user, CompoundTag tag) {
|
||||
Tag name = tag.get("CustomName");
|
||||
if (name instanceof StringTag) {
|
||||
((StringTag) name).setValue(ChatRewriter.legacyTextToJson(((StringTag) name).getValue()).toString());
|
||||
((StringTag) name).setValue(ChatRewriter.legacyTextToJsonString(((StringTag) name).getValue()));
|
||||
}
|
||||
Tag out = tag.get("LastOutput");
|
||||
if (out instanceof StringTag) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
|
||||
|
||||
import com.github.steveice10.opennbt.conversion.ConverterRegistry;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
@ -237,20 +236,19 @@ public class InventoryPackets {
|
||||
if (item == null) return;
|
||||
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getNewItemId(item.getIdentifier()));
|
||||
|
||||
CompoundTag tag;
|
||||
if ((tag = item.getTag()) != null) {
|
||||
// Display Lore now uses JSON
|
||||
Tag displayTag = tag.get("display");
|
||||
if (displayTag instanceof CompoundTag) {
|
||||
CompoundTag display = (CompoundTag) displayTag;
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
display.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|Lore", ConverterRegistry.convertToValue(lore)));
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJson(((StringTag) loreEntry).getValue()).toString());
|
||||
}
|
||||
if (item.getTag() == null) return;
|
||||
|
||||
// Display Lore now uses JSON
|
||||
Tag displayTag = item.getTag().get("display");
|
||||
if (displayTag instanceof CompoundTag) {
|
||||
CompoundTag display = (CompoundTag) displayTag;
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -261,30 +259,24 @@ public class InventoryPackets {
|
||||
if (item == null) return;
|
||||
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getOldItemId(item.getIdentifier()));
|
||||
|
||||
CompoundTag tag;
|
||||
if ((tag = item.getTag()) != null) {
|
||||
// Display Name now uses JSON
|
||||
Tag displayTag = tag.get("display");
|
||||
if (displayTag instanceof CompoundTag) {
|
||||
CompoundTag display = (CompoundTag) displayTag;
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
ListTag via = display.get(NBT_TAG_NAME + "|Lore");
|
||||
if (via != null) {
|
||||
display.put(ConverterRegistry.convertToTag("Lore", ConverterRegistry.convertToValue(via)));
|
||||
} else {
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
((StringTag) loreEntry).setValue(
|
||||
ChatRewriter.jsonTextToLegacy(
|
||||
((StringTag) loreEntry).getValue()
|
||||
)
|
||||
);
|
||||
}
|
||||
if (item.getTag() == null) return;
|
||||
|
||||
// Display Name now uses JSON
|
||||
Tag displayTag = item.getTag().get("display");
|
||||
if (displayTag instanceof CompoundTag) {
|
||||
CompoundTag display = (CompoundTag) displayTag;
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
ListTag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
|
||||
if (savedLore != null) {
|
||||
display.put(new ListTag("Lore", savedLore.getValue()));
|
||||
} else {
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
((StringTag) loreEntry).setValue(ChatRewriter.jsonTextToLegacy(((StringTag) loreEntry).getValue()));
|
||||
}
|
||||
}
|
||||
display.remove(NBT_TAG_NAME + "|Lore");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user