Paper/Spigot-Server-Patches/0290-Catch-JsonParseException-in-Entity-and-TE-names.patch
Mariell Hoversholm 0f78e95250 More work
2021-03-18 18:03:22 +01:00

87 Zeilen
4.8 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/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index cd7dc7d90efddb8a1bb50cd964b43d18cf9c83d1..35d1444c5b75d9a3a6cface5dd70aea0a08ac89d 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -7,6 +7,8 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.EnumDirection;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.server.level.WorldServer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkCoordIntPair;
@@ -514,4 +516,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/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 {
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/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
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
}
}