2019-05-14 21:54:32 +00:00
|
|
|
From 091bf5c1ff4b65cdb0a60a83545e5f42724c0f46 Mon Sep 17 00:00:00 2001
|
2018-09-24 00:10:24 +00:00
|
|
|
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
|
2019-05-14 21:54:32 +00:00
|
|
|
index 4b7aefb7a7..9e568d5d15 100644
|
2018-09-24 00:10:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -56,7 +56,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
|
2019-05-05 08:33:44 +00:00
|
|
|
this.command = nbttagcompound.getString("Command");
|
|
|
|
this.successCount = nbttagcompound.getInt("SuccessCount");
|
2018-09-24 00:10:24 +00:00
|
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
2019-05-05 08:33:44 +00:00
|
|
|
- this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
|
|
|
|
+ this.customName = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
|
2018-09-24 00:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nbttagcompound.hasKeyOfType("TrackOutput", 1)) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-14 21:54:32 +00:00
|
|
|
index b060a74a1e..b1cf9b85fa 100644
|
2018-09-24 00:10:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-12 23:42:49 +00:00
|
|
|
@@ -1647,7 +1647,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-05-05 08:33:44 +00:00
|
|
|
this.setPosition(this.locX, this.locY, this.locZ);
|
|
|
|
this.setYawPitch(this.yaw, this.pitch);
|
|
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
|
|
|
- this.setCustomName(IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName")));
|
|
|
|
+ this.setCustomName(MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound)); // Paper - Catch ParseException
|
|
|
|
}
|
2018-09-24 00:10:24 +00:00
|
|
|
|
2019-05-05 08:33:44 +00:00
|
|
|
this.setCustomNameVisible(nbttagcompound.getBoolean("CustomNameVisible"));
|
2018-09-24 00:10:24 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
2019-05-14 21:54:32 +00:00
|
|
|
index 6d278a0da5..ec3732193f 100644
|
2018-09-24 00:10:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
2018-10-05 03:18:46 +00:00
|
|
|
@@ -339,4 +339,19 @@ public final class MCUtil {
|
2018-09-24 00:10:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public static IChatBaseComponent getBaseComponentFromNbt(String key, NBTTagCompound compound) {
|
2018-09-24 01:22:57 +00:00
|
|
|
+ if (!compound.hasKey(key)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String string = compound.getString(key);
|
2018-09-24 00:10:24 +00:00
|
|
|
+ try {
|
2018-09-24 01:22:57 +00:00
|
|
|
+ return IChatBaseComponent.ChatSerializer.jsonToComponent(string);
|
|
|
|
+ } catch (com.google.gson.JsonParseException e) {
|
|
|
|
+ org.bukkit.Bukkit.getLogger().warning("Unable to parse " + key + " from " + compound +": " + e.getMessage());
|
2018-09-24 00:10:24 +00:00
|
|
|
+ }
|
|
|
|
+
|
2018-09-24 01:22:57 +00:00
|
|
|
+ return null;
|
2018-09-24 00:10:24 +00:00
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityBanner.java b/src/main/java/net/minecraft/server/TileEntityBanner.java
|
2019-05-14 21:54:32 +00:00
|
|
|
index 1f26d8a022..12264c4d03 100644
|
2018-09-24 00:10:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntityBanner.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityBanner.java
|
2019-05-05 08:33:44 +00:00
|
|
|
@@ -57,7 +57,7 @@ public class TileEntityBanner extends TileEntity implements INamableTileEntity {
|
2018-09-24 00:10:24 +00:00
|
|
|
public void load(NBTTagCompound nbttagcompound) {
|
|
|
|
super.load(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()) {
|
2019-05-05 08:33:44 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityContainer.java b/src/main/java/net/minecraft/server/TileEntityContainer.java
|
2019-05-14 21:54:32 +00:00
|
|
|
index 3590b4e317..ea7d5a430a 100644
|
2019-05-05 08:33:44 +00:00
|
|
|
--- 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(nbttagcompound);
|
|
|
|
this.chestLock = ChestLock.b(nbttagcompound);
|
2018-09-24 00:10:24 +00:00
|
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
2019-05-05 08:33:44 +00:00
|
|
|
- this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
|
|
|
|
+ this.customName = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
|
2018-09-24 00:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
--
|
2019-05-05 11:32:20 +00:00
|
|
|
2.21.0
|
2018-09-24 00:10:24 +00:00
|
|
|
|