mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-21 10:27:44 +01:00
Tuinity! \o/
This commit is contained in:
83
patches/server/0096-Convert-legacy-item-text.patch
Normal file
83
patches/server/0096-Convert-legacy-item-text.patch
Normal file
@@ -0,0 +1,83 @@
|
||||
From fa486db80a9ffdc62e4397c12bbbfa34cc09a2c6 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 | 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..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 {
|
||||
if (nbttagcompound.hasKeyOfType("tag", 10)) {
|
||||
// CraftBukkit start - make defensive copy as this data may be coming from the save thread
|
||||
this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone();
|
||||
+ processText(); // Purpur
|
||||
processEnchantOrder(this.tag); // Paper
|
||||
this.getItem().b(this.tag);
|
||||
// CraftBukkit end
|
||||
@@ -138,6 +139,50 @@ public final class ItemStack {
|
||||
|
||||
}
|
||||
|
||||
+ // Purpur start
|
||||
+ 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 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(json));
|
||||
+ } catch (JsonParseException ignore) {
|
||||
+ }
|
||||
+ }
|
||||
+ if (legacy) {
|
||||
+ 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));
|
||||
+ }
|
||||
+ // Purpur end
|
||||
+
|
||||
private ItemStack(NBTTagCompound nbttagcompound) {
|
||||
this.load(nbttagcompound);
|
||||
// CraftBukkit end
|
||||
@@ -632,6 +677,7 @@ public final class ItemStack {
|
||||
}
|
||||
}
|
||||
|
||||
+ @Nullable public NBTTagCompound getSubTag(String s) { return b(s); } // Purpur - OBFHELPER
|
||||
@Nullable
|
||||
public NBTTagCompound b(String s) {
|
||||
return this.tag != null && this.tag.hasKeyOfType(s, 10) ? this.tag.getCompound(s) : null;
|
||||
--
|
||||
2.26.2
|
||||
|
||||
Reference in New Issue
Block a user