Make bad custom name resolution more specific

Avoids interfering with other places in vanilla where these issues
are tolerated and expected.
This commit is contained in:
Zach Brown 2018-09-23 20:10:24 -04:00
parent 5d7bf5d57a
commit 7a57f23710
No known key found for this signature in database
GPG key ID: CC9DA35FC5450B76
2 changed files with 155 additions and 41 deletions

View file

@ -0,0 +1,155 @@
From 6ed05ed8dce0c0fda2374cd0f6e529bd1f7643da 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 729859d13..2a1dffbf4 100644
--- a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
+++ b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
@@ -57,7 +57,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
this.g = nbttagcompound.getString("Command");
this.d = nbttagcompound.getInt("SuccessCount");
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.h = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.h = 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 f6c43bab4..8c2ce7006 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1733,7 +1733,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 f7856897f..a50224734 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -363,4 +363,16 @@ public final class MCUtil {
return null;
}
}
+
+ @Nullable
+ public static IChatBaseComponent getBaseComponentFromNbt(String key, NBTTagCompound compound) {
+ IChatBaseComponent component = null;
+ try {
+ component = IChatBaseComponent.ChatSerializer.a(compound.getString("CustomName"));
+ } catch (com.google.gson.JsonParseException ignored) {
+ org.bukkit.Bukkit.getLogger().warning("Unable to load " + key + " from " + compound);
+ }
+
+ return component;
+ }
}
diff --git a/src/main/java/net/minecraft/server/TileEntityBanner.java b/src/main/java/net/minecraft/server/TileEntityBanner.java
index b4fae0d30..364a9fa7a 100644
--- a/src/main/java/net/minecraft/server/TileEntityBanner.java
+++ b/src/main/java/net/minecraft/server/TileEntityBanner.java
@@ -74,7 +74,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/TileEntityBrewingStand.java b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java
index 480faa66e..f3ddb86d0 100644
--- a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java
+++ b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java
@@ -236,7 +236,7 @@ public class TileEntityBrewingStand extends TileEntityContainer implements IWorl
ContainerUtil.b(nbttagcompound, this.items);
this.brewTime = nbttagcompound.getShort("BrewTime");
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.k = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.k = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
this.fuelLevel = nbttagcompound.getByte("Fuel");
diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java
index 7594c16e9..803793072 100644
--- a/src/main/java/net/minecraft/server/TileEntityChest.java
+++ b/src/main/java/net/minecraft/server/TileEntityChest.java
@@ -83,7 +83,7 @@ public class TileEntityChest extends TileEntityLootable { // Paper - Remove ITic
}
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.i = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.i = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
}
diff --git a/src/main/java/net/minecraft/server/TileEntityDispenser.java b/src/main/java/net/minecraft/server/TileEntityDispenser.java
index ddd2e0eb0..21bd156e9 100644
--- a/src/main/java/net/minecraft/server/TileEntityDispenser.java
+++ b/src/main/java/net/minecraft/server/TileEntityDispenser.java
@@ -107,7 +107,7 @@ public class TileEntityDispenser extends TileEntityLootable {
}
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.i = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.i = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
}
diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java
index a537d35b7..f6bc6403f 100644
--- a/src/main/java/net/minecraft/server/TileEntityFurnace.java
+++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java
@@ -219,7 +219,7 @@ public class TileEntityFurnace extends TileEntityContainer implements IWorldInve
}
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.l = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.l = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
// Paper start - cook speed API
diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java
index a8cf160fe..c56422170 100644
--- a/src/main/java/net/minecraft/server/TileEntityHopper.java
+++ b/src/main/java/net/minecraft/server/TileEntityHopper.java
@@ -61,7 +61,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
}
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.setCustomName(IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName")));
+ this.setCustomName(MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound)); // Paper - Catch ParseException
}
this.f = nbttagcompound.getInt("TransferCooldown");
diff --git a/src/main/java/net/minecraft/server/TileEntityShulkerBox.java b/src/main/java/net/minecraft/server/TileEntityShulkerBox.java
index df9a30560..65a685452 100644
--- a/src/main/java/net/minecraft/server/TileEntityShulkerBox.java
+++ b/src/main/java/net/minecraft/server/TileEntityShulkerBox.java
@@ -254,7 +254,7 @@ public class TileEntityShulkerBox extends TileEntityLootable implements IWorldIn
}
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
- this.i = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
+ this.i = MCUtil.getBaseComponentFromNbt("CustomName", nbttagcompound); // Paper - Catch ParseException
}
}
--
2.19.0

View file

@ -1,41 +0,0 @@
From 691b112b9931b505d5acb88a4ccdf7e994f03677 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] Return null if we get a ParseException in IChatBaseComponent
This is allowed as the method is explicitly marked as nullable and is
preferable to returning an empty string in this instance.
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/IChatBaseComponent.java b/src/main/java/net/minecraft/server/IChatBaseComponent.java
index ff14b3e09..03c148f4f 100644
--- a/src/main/java/net/minecraft/server/IChatBaseComponent.java
+++ b/src/main/java/net/minecraft/server/IChatBaseComponent.java
@@ -357,7 +357,15 @@ public interface IChatBaseComponent extends Message, Iterable<IChatBaseComponent
@Nullable public static IChatBaseComponent jsonToComponent(String json) { return a(json);} // Paper - OBFHELPER
@Nullable
public static IChatBaseComponent a(String s) {
- return (IChatBaseComponent)ChatDeserializer.a(a, s, IChatBaseComponent.class, false);
+ // Paper start - Catch parse exception and return null
+ try {
+ return (IChatBaseComponent)ChatDeserializer.a(a, s, IChatBaseComponent.class, false);
+ } catch (JsonParseException ex) {
+ org.bukkit.Bukkit.getLogger().severe("Unable to deserialize component: " + s);
+ ex.printStackTrace();
+ return null;
+ }
+ // Paper end
}
@Nullable
--
2.19.0