mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 19:52:55 +01:00
63 lines
3 KiB
Diff
63 lines
3 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/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
index 1f93ad93701339418b554eb3e1e3f74e62468f3f..e643f925623820ffa67217eb3615582c0d0ca3a5 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
@@ -168,6 +168,44 @@ public final class ItemStack {
|
|
list.sort((Comparator<? super net.minecraft.nbt.Tag>) enchantSorter); // Paper
|
|
} catch (Exception ignored) {}
|
|
}
|
|
+
|
|
+ private void processText() {
|
|
+ CompoundTag display = getTagElement("display");
|
|
+ if (display != null) {
|
|
+ if (display.contains("Name", 8)) {
|
|
+ String json = display.getString("Name");
|
|
+ if (json != null && json.contains("\u00A7")) {
|
|
+ try {
|
|
+ display.put("Name", convert(json));
|
|
+ } catch (JsonParseException jsonparseexception) {
|
|
+ display.remove("Name");
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (display.contains("Lore", 9)) {
|
|
+ ListTag 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, net.minecraft.nbt.StringTag.valueOf(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(new TextComponent(""))));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private net.minecraft.nbt.StringTag convert(String json) {
|
|
+ Component component = Component.Serializer.fromJson(json);
|
|
+ if (component instanceof TextComponent && component.getContents().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.getContents())[0];
|
|
+ }
|
|
+ return net.minecraft.nbt.StringTag.valueOf(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
|
|
+ }
|
|
// Paper end
|
|
|
|
public ItemStack(ItemLike item) {
|
|
@@ -214,6 +252,7 @@ public final class ItemStack {
|
|
this.tag = (CompoundTag) nbttagcompound.getCompound("tag").copy();
|
|
// CraftBukkit end
|
|
this.processEnchantOrder(this.tag); // Paper
|
|
+ this.processText(); // Paper
|
|
this.getItem().verifyTagAfterLoad(this.tag);
|
|
}
|
|
|