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