Optimise legacy item text patch

This commit is contained in:
William Blake Galbreath
2020-07-01 10:31:19 -05:00
parent 1b89d9f8b6
commit 9d66d92566

View File

@@ -1,14 +1,14 @@
From 1f13524432c259a3d5b2e876b3dc204435fa14f4 Mon Sep 17 00:00:00 2001 From 4be77127264751572a421248622c5bd436b4bedf Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com> From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Mon, 29 Jun 2020 08:56:53 -0500 Date: Mon, 29 Jun 2020 08:56:53 -0500
Subject: [PATCH] Convert legacy item text Subject: [PATCH] Convert legacy item text
--- ---
.../java/net/minecraft/server/ItemStack.java | 40 +++++++++++++++++++ .../java/net/minecraft/server/ItemStack.java | 46 +++++++++++++++++++
1 file changed, 40 insertions(+) 1 file changed, 46 insertions(+)
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 54421c56c..54dc3e060 100644 index 54421c56c..bb369c822 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java --- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java +++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -127,6 +127,7 @@ public final class ItemStack { @@ -127,6 +127,7 @@ public final class ItemStack {
@@ -19,43 +19,49 @@ index 54421c56c..54dc3e060 100644
processEnchantOrder(this.tag); // Paper processEnchantOrder(this.tag); // Paper
this.getItem().b(this.tag); this.getItem().b(this.tag);
// CraftBukkit end // CraftBukkit end
@@ -138,6 +139,44 @@ public final class ItemStack { @@ -138,6 +139,50 @@ public final class ItemStack {
} }
+ // Purpur start + // Purpur start
+ public void processText() { + private void processText() {
+ NBTTagCompound display = getSubTag("display"); + NBTTagCompound display = getSubTag("display");
+ if (display != null) { + if (display != null) {
+ if (display.hasKeyOfType("Name", 8)) { + if (display.hasKeyOfType("Name", 8)) {
+ try { + String json = display.getString("Name");
+ display.set("Name", convert(display.getString("Name"))); + if (json != null && json.contains("\u00A7")) {
+ } catch (JsonParseException jsonparseexception) { + try {
+ display.remove("Name"); + display.set("Name", convert(json));
+ } catch (JsonParseException jsonparseexception) {
+ display.remove("Name");
+ }
+ } + }
+ } + }
+ if (display.hasKeyOfType("Lore", 9)) { + if (display.hasKeyOfType("Lore", 9)) {
+ NBTTagList lore = new NBTTagList(); + NBTTagList lore = new NBTTagList();
+ NBTTagList list = display.getList("Lore", 8); + NBTTagList list = display.getList("Lore", 8);
+ boolean legacy = false;
+ for (int index = 0; index < list.size(); index++) { + for (int index = 0; index < list.size(); index++) {
+ String json = list.getString(index);
+ if (json != null && json.contains("\u00A7")) {
+ legacy = true;
+ }
+ try { + try {
+ lore.add(convert(list.getString(index))); + lore.add(convert(json));
+ } catch (JsonParseException ignore) { + } catch (JsonParseException ignore) {
+ } + }
+ } + }
+ display.set("Lore", lore); + if (legacy) {
+ display.set("Lore", lore);
+ }
+ } + }
+ } + }
+ } + }
+ +
+ private NBTTagString convert(String str) { + private NBTTagString convert(String json) {
+ IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(str); + IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(json);
+ if (component != null) { + if (component != null) {
+ String txt = component.getText(); + component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(component.getText())[0];
+ if (txt != null && txt.contains("\u00A7")) {
+ // found legacy text, converting into proper component
+ component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(txt)[0];
+ }
+ } + }
+ return NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component)); + return NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
+ } + }
@@ -64,7 +70,7 @@ index 54421c56c..54dc3e060 100644
private ItemStack(NBTTagCompound nbttagcompound) { private ItemStack(NBTTagCompound nbttagcompound) {
this.load(nbttagcompound); this.load(nbttagcompound);
// CraftBukkit end // CraftBukkit end
@@ -632,6 +671,7 @@ public final class ItemStack { @@ -632,6 +677,7 @@ public final class ItemStack {
} }
} }