Paper/Spigot-Server-Patches/0528-Update-itemstack-legacy-name-and-lore.patch
Daniel Ennis c97ce029e9
1.16.2 Release (#4123)
PaperMC believes that 1.16.2 is now ready for general release as we fixed the main issue plagueing the 1.16.x release, the MapLike data conversion issues.

Until now, it was not safe for a server to convert a world to 1.16.2 without data conversion issues around villages and potentially other things. If you did, those MapLike errors meant something went wrong.

This is now resolved.

Big thanks to all those that helped, notably @BillyGalbreath and @Proximyst who did large parts of the update process with me.

Please as always, backup your worlds and test before updating to 1.16.2!

If you update to 1.16.2, there is no going back to an older build than this.

---------------------------------

Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com>
Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com>
Co-authored-by: krolik-exe <69214078+krolik-exe@users.noreply.github.com>
Co-authored-by: BillyGalbreath <BillyGalbreath@users.noreply.github.com>
Co-authored-by: stonar96 <minecraft.stonar96@gmail.com>
Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
Co-authored-by: Jason <jasonpenilla2@me.com>
Co-authored-by: kashike <kashike@vq.lc>
Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com>
Co-authored-by: KennyTV <kennytv@t-online.de>
Co-authored-by: commandblockguy <commandblockguy1@gmail.com>
Co-authored-by: DigitalRegent <misterwener@gmail.com>
Co-authored-by: ishland <ishlandmc@yeah.net>
2020-08-24 22:40:19 -04:00

84 lines
4.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Wed, 1 Jul 2020 11:57:40 -0500
Subject: [PATCH] Update itemstack legacy name and lore
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 8c82f80bb21611b54a35e61c04f5ba3ee9efbd7d..ace50805bfebbf4c3485ba1de334d975830a7d3c 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -83,6 +83,44 @@ public final class ItemStack {
list.sort((Comparator<? super NBTBase>) enchantSorter); // Paper
} catch (Exception ignored) {}
}
+
+ private void processText() {
+ NBTTagCompound display = getSubTag("display");
+ if (display != null) {
+ if (display.hasKeyOfType("Name", 8)) {
+ String json = display.getString("Name");
+ if (json != null && json.contains("\u00A7")) {
+ try {
+ display.set("Name", convert(json));
+ } catch (JsonParseException jsonparseexception) {
+ display.remove("Name");
+ }
+ }
+ }
+ if (display.hasKeyOfType("Lore", 9)) {
+ NBTTagList list = display.getList("Lore", 8);
+ for (int index = 0; index < list.size(); index++) {
+ String json = list.getString(index);
+ if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json
+ try {
+ list.set(index, convert(json));
+ } catch (JsonParseException e) {
+ list.set(index, NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(new ChatComponentText(""))));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private NBTTagString convert(String json) {
+ IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(json);
+ if (component instanceof ChatComponentText && component.getText().contains("\u00A7") && component.getSiblings().isEmpty()) {
+ // Only convert if the root component is a single comp with legacy in it, don't convert already normal components
+ component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(component.getText())[0];
+ }
+ return NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
+ }
// Paper end
public ItemStack(IMaterial imaterial) {
@@ -128,6 +166,7 @@ public final class ItemStack {
// CraftBukkit start - make defensive copy as this data may be coming from the save thread
this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone();
processEnchantOrder(this.tag); // Paper
+ processText(); // Paper
this.getItem().b(this.tag);
// CraftBukkit end
}
@@ -611,6 +650,7 @@ public final class ItemStack {
}
}
+ @Nullable public NBTTagCompound getSubTag(String s) { return b(s); } // Paper - OBFHELPER
@Nullable
public NBTTagCompound b(String s) {
return this.tag != null && this.tag.hasKeyOfType(s, 10) ? this.tag.getCompound(s) : null;
diff --git a/src/main/java/net/minecraft/server/NBTTagString.java b/src/main/java/net/minecraft/server/NBTTagString.java
index 7ef2378311edd0645472d895cf3756426f25605d..a4747d5dc04ff1e1ec5fd35f927db7d452ea5ae4 100644
--- a/src/main/java/net/minecraft/server/NBTTagString.java
+++ b/src/main/java/net/minecraft/server/NBTTagString.java
@@ -40,6 +40,7 @@ public class NBTTagString implements NBTBase {
this.data = s;
}
+ public static NBTTagString create(String s) { return a(s); } // Paper - OBFHELPER
public static NBTTagString a(String s) {
return s.isEmpty() ? NBTTagString.b : new NBTTagString(s);
}