mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
Only convert lore lines that actually look legacy
Spigot stored previous componenents as new ChatComponentText("legacy codes") which this patch aimed to convert to the new format. However, the impl ended up converting all lines. If a plugin had a section symbol in the lore that isn't a color conversion, it would make trigger this process every single time. So now we will only process it if the pattern looks like the legacy bukkit format Fixes #3869
This commit is contained in:
parent
8c4787e306
commit
071c08d77e
@ -5,10 +5,10 @@ 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 00725529793d6c2fe26ecacf900355b40e31dad8..53dc47ffb48cce2ef160d1d61766e6700f67c6e3 100644
|
||||
index 9a9678ed76b95131df0c12af5bba3440789699aa..3c56053e3075173edd22eccb277f51a12287ab56 100644
|
||||
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
@@ -83,6 +83,52 @@ public final class ItemStack {
|
||||
@@ -83,6 +83,44 @@ public final class ItemStack {
|
||||
list.sort((Comparator<? super NBTBase>) enchantSorter); // Paper
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
@ -28,24 +28,15 @@ index 00725529793d6c2fe26ecacf900355b40e31dad8..53dc47ffb48cce2ef160d1d61766e670
|
||||
+ }
|
||||
+ 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);
|
||||
+ if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json
|
||||
+ try {
|
||||
+ lore.add(convert(json));
|
||||
+ } catch (JsonParseException ignore) {
|
||||
+ list.set(index, convert(json));
|
||||
+ } catch (JsonParseException e) {
|
||||
+ list.set(index, NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(new ChatComponentText(""))));
|
||||
+ }
|
||||
+ }
|
||||
+ display.set("Lore", lore);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
@ -53,7 +44,8 @@ index 00725529793d6c2fe26ecacf900355b40e31dad8..53dc47ffb48cce2ef160d1d61766e670
|
||||
+
|
||||
+ private NBTTagString convert(String json) {
|
||||
+ IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(json);
|
||||
+ if (component != null) {
|
||||
+ if (component instanceof ChatComponentText && component.getText().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.getText())[0];
|
||||
+ }
|
||||
+ return NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
|
||||
@ -61,7 +53,7 @@ index 00725529793d6c2fe26ecacf900355b40e31dad8..53dc47ffb48cce2ef160d1d61766e670
|
||||
// Paper end
|
||||
|
||||
public ItemStack(IMaterial imaterial) {
|
||||
@@ -128,6 +174,7 @@ public final class ItemStack {
|
||||
@@ -128,6 +166,7 @@ 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
|
||||
@ -69,7 +61,7 @@ index 00725529793d6c2fe26ecacf900355b40e31dad8..53dc47ffb48cce2ef160d1d61766e670
|
||||
this.getItem().b(this.tag);
|
||||
// CraftBukkit end
|
||||
}
|
||||
@@ -611,6 +658,7 @@ public final class ItemStack {
|
||||
@@ -611,6 +650,7 @@ public final class ItemStack {
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user