mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 17:07:34 +01:00
111 lines
5.9 KiB
Diff
111 lines
5.9 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..3fcdff3649c725580456dfc965d6c83bd5afe3da 100644
|
|
--- a/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
|
|
+++ b/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java
|
|
@@ -12,6 +12,7 @@ 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;
|
|
@@ -72,7 +73,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..45958ffedca64e08e347ae65033700c0d798beb5 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
|
|
@@ -9,6 +9,7 @@ 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;
|
|
@@ -70,7 +71,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..fb7a1a854efcf42f0351ef521aff67d5fcc4ab27 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
|
|
@@ -4,6 +4,7 @@ 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;
|
|
@@ -30,7 +31,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
|
|
}
|
|
|
|
}
|