mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 09:23:42 +01:00
7ae47d4eb3
Mojang fixed it in MC-63720
77 lines
4.2 KiB
Diff
77 lines
4.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Zach Brown <zach.brown@destroystokyo.com>
|
|
Date: Sat, 22 Sep 2018 15:56:59 -0400
|
|
Subject: [PATCH] Catch JsonParseException in Entity and TE names
|
|
|
|
As a result, data that no longer parses correctly will not crash the server
|
|
instead just logging the exception and continuing (and in most cases should
|
|
fix the data)
|
|
|
|
Player data is fixed pretty much immediately but some block data (like
|
|
Shulkers) may need to be changed in order for it to re-save properly
|
|
|
|
No more crashing though.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
|
|
index 850e79b764513bd68a28b675e075f804f59b75a8..7e13b1cf6d92c3e0f2dab1ba1d42bd4f250e256c 100644
|
|
--- a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
|
|
+++ b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
|
|
@@ -60,7 +60,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
|
|
this.command = nbttagcompound.getString("Command");
|
|
this.successCount = nbttagcompound.getInt("SuccessCount");
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
|
- this.setName(IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName")));
|
|
+ this.setName(MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound)); // Paper - Catch ParseException
|
|
}
|
|
|
|
if (nbttagcompound.hasKeyOfType("TrackOutput", 1)) {
|
|
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
|
index 39174bca00b4535e92f6b325b3fd058ceae41f8b..816d55b17ea531bc2f25b92c003b127fe6e04112 100644
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
|
@@ -507,4 +507,19 @@ public final class MCUtil {
|
|
return null;
|
|
}
|
|
}
|
|
+
|
|
+ @Nullable
|
|
+ public static IChatBaseComponent getBaseComponentFromNbt(String key, NBTTagCompound compound) {
|
|
+ if (!compound.hasKey(key)) {
|
|
+ return null;
|
|
+ }
|
|
+ String string = compound.getString(key);
|
|
+ try {
|
|
+ return IChatBaseComponent.ChatSerializer.jsonToComponent(string);
|
|
+ } catch (com.google.gson.JsonParseException e) {
|
|
+ org.bukkit.Bukkit.getLogger().warning("Unable to parse " + key + " from " + compound +": " + e.getMessage());
|
|
+ }
|
|
+
|
|
+ return null;
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityBanner.java b/src/main/java/net/minecraft/server/TileEntityBanner.java
|
|
index 4f886c4145325d8fd8217ae3f681632f0396689f..5397d8a69a0326cf73fe0ee1175d1871cac3769d 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntityBanner.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityBanner.java
|
|
@@ -60,7 +60,7 @@ public class TileEntityBanner extends TileEntity implements INamableTileEntity {
|
|
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
|
|
super.load(iblockdata, nbttagcompound);
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
|
- this.a = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
|
|
+ this.a = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
|
|
}
|
|
|
|
if (this.hasWorld()) {
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityContainer.java b/src/main/java/net/minecraft/server/TileEntityContainer.java
|
|
index 8f94b9c52c3842b9c32280499aee1b551dc16095..74390aebd353c969353a6efc0904bafe30774d65 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntityContainer.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityContainer.java
|
|
@@ -17,7 +17,7 @@ public abstract class TileEntityContainer extends TileEntity implements IInvento
|
|
super.load(iblockdata, nbttagcompound);
|
|
this.chestLock = ChestLock.b(nbttagcompound);
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
|
- this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
|
|
+ this.customName = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
|
|
}
|
|
|
|
}
|