Paper/Spigot-Server-Patches/0315-Catch-JsonParseException-in-Entity-and-TE-names.patch
Spottedleaf 5c7081fecc Update upstream & fix some chunk related issues (#2177)
* Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01f SPIGOT-5047: Correct slot types for 1.14 inventories
e8c08362 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3b SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
2019-06-14 03:27:40 +01:00

94 lines
4.9 KiB
Diff

From b685fe9015afdcd0227b69d06a2a5a4275bf760b 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/CommandBlockListenerAbstract.java b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
index 4b7aefb7a7..9e568d5d15 100644
--- a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
+++ b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
@@ -56,7 +56,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
this.command = nbttagcompound.getString("Command");
this.successCount = nbttagcompound.getInt("SuccessCount");
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.customName = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
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
index 3a41137298..a6e5ac070c 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1651,7 +1651,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
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
}
this.setCustomNameVisible(nbttagcompound.getBoolean("CustomNameVisible"));
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index 6d278a0da5..ec3732193f 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -339,4 +339,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/server/TileEntityBanner.java b/src/main/java/net/minecraft/server/TileEntityBanner.java
index 1f26d8a022..12264c4d03 100644
--- a/src/main/java/net/minecraft/server/TileEntityBanner.java
+++ b/src/main/java/net/minecraft/server/TileEntityBanner.java
@@ -57,7 +57,7 @@ public class TileEntityBanner extends TileEntity implements INamableTileEntity {
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()) {
diff --git a/src/main/java/net/minecraft/server/TileEntityContainer.java b/src/main/java/net/minecraft/server/TileEntityContainer.java
index 473ec2cbde..ab6b86e4e9 100644
--- 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);
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.customName = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
}
--
2.21.0