2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-24 02:10:24 +02: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/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
2021-03-16 08:19:45 +01:00
|
|
|
index cd7dc7d90efddb8a1bb50cd964b43d18cf9c83d1..67806eaab081e938cd99a0d74225b1b7744ff2d7 100644
|
2018-09-24 02:10:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -514,4 +514,19 @@ public final class MCUtil {
|
2018-09-24 02:10:24 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ public static IChatBaseComponent getBaseComponentFromNbt(String key, NBTTagCompound compound) {
|
2018-09-24 03:22:57 +02:00
|
|
|
+ if (!compound.hasKey(key)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String string = compound.getString(key);
|
2018-09-24 02:10:24 +02:00
|
|
|
+ try {
|
2018-09-24 03:22:57 +02: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 02:10:24 +02:00
|
|
|
+ }
|
|
|
|
+
|
2018-09-24 03:22:57 +02:00
|
|
|
+ return null;
|
2018-09-24 02:10:24 +02:00
|
|
|
+ }
|
|
|
|
}
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java b/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
|
|
|
|
index 94adf4d3b3a367e2a7fa383f1da6fb3b02b35c85..0f966c5defdda58fd7d31072b625f16928cddeb7 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
|
|
|
|
@@ -72,7 +72,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/world/level/block/entity/TileEntityBanner.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntityBanner.java
|
|
|
|
index fd8d39d04f39ea8aa389deb66ca0ddaa3e282c40..e2d3ade6565b10ebed3c001f4a1c5bbb3a7f0b12 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntityBanner.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntityBanner.java
|
|
|
|
@@ -70,7 +70,7 @@ public class TileEntityBanner extends TileEntity implements INamableTileEntity {
|
2020-06-25 16:09:55 +02:00
|
|
|
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
|
|
|
|
super.load(iblockdata, nbttagcompound);
|
2018-09-24 02:10:24 +02:00
|
|
|
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()) {
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntityContainer.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntityContainer.java
|
|
|
|
index 19739ad1fb01c767288da2667a48909e4c1c36cc..5841422beb972f28fb9e9d10bcf711b2c20a4bb0 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntityContainer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntityContainer.java
|
|
|
|
@@ -30,7 +30,7 @@ public abstract class TileEntityContainer extends TileEntity implements IInvento
|
2020-06-25 16:09:55 +02:00
|
|
|
super.load(iblockdata, nbttagcompound);
|
2019-05-05 10:33:44 +02:00
|
|
|
this.chestLock = ChestLock.b(nbttagcompound);
|
2018-09-24 02:10:24 +02:00
|
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
2019-05-05 10:33:44 +02:00
|
|
|
- this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
|
|
|
|
+ this.customName = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
|
2018-09-24 02:10:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|