PaperMC/Spigot-Server-Patches/Catch-JsonParseException-in-Entity-and-TE-names.patch
Mariell Hoversholm 0750bfaf8c It compiles
2021-03-16 16:50:45 +01:00

110 lines
5.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zach Brown <1254957+zachbr@users.noreply.github.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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
+++ b/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
@@ -0,0 +0,0 @@ import net.minecraft.commands.ICommandListener;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.chat.ChatComponentText;
import net.minecraft.network.chat.IChatBaseComponent;
+import net.minecraft.server.MCUtil;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.util.UtilColor;
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
@@ -0,0 +0,0 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.chat.ChatMessage;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
+import net.minecraft.server.MCUtil;
import net.minecraft.world.INamableTileEntity;
import net.minecraft.world.item.EnumColor;
import net.minecraft.world.item.ItemStack;
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
@@ -0,0 +0,0 @@ import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.chat.ChatMessage;
import net.minecraft.network.chat.IChatBaseComponent;
+import net.minecraft.server.MCUtil;
import net.minecraft.sounds.SoundCategory;
import net.minecraft.sounds.SoundEffects;
import net.minecraft.world.ChestLock;
@@ -0,0 +0,0 @@ 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
}
}