Update itemstack legacy name and lore (#3741)

This commit is contained in:
BillyGalbreath 2020-07-04 19:47:24 -05:00
parent f0d5e74089
commit 7de9b9d112

View file

@ -0,0 +1,91 @@
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -0,0 +0,0 @@ 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);
+ boolean legacy = false;
+ for (int index = 0; index < list.size(); index++) {
+ String json = list.getString(index);
+ if (json != null && json.contains("\u00A7")) {
+ legacy = true;
+ break;
+ }
+ }
+ if (legacy) {
+ NBTTagList lore = new NBTTagList();
+ for (int index = 0; index < list.size(); index++) {
+ String json = list.getString(index);
+ try {
+ lore.add(convert(json));
+ } catch (JsonParseException ignore) {
+ }
+ }
+ display.set("Lore", lore);
+ }
+ }
+ }
+ }
+
+ private NBTTagString convert(String json) {
+ IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(json);
+ if (component != null) {
+ 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) {
@@ -0,0 +0,0 @@ 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
}
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/NBTTagString.java
+++ b/src/main/java/net/minecraft/server/NBTTagString.java
@@ -0,0 +0,0 @@ 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);
}