2021-06-11 14:02:28 +02:00
|
|
|
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
|
2024-01-21 13:56:22 +01:00
|
|
|
Subject: [PATCH] Catch JsonParseException in entity and block entity names
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2022-10-24 21:43:46 +02:00
|
|
|
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
|
2024-01-26 21:34:40 +01:00
|
|
|
index b08190d604f7f95f771a4da115cc50c38c5f1691..8235d23dc9778b9444288d58ffdb5d515df56bf9 100644
|
2022-10-24 21:43:46 +02:00
|
|
|
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
|
|
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
|
2024-01-26 21:34:40 +01:00
|
|
|
@@ -536,4 +536,19 @@ public final class MCUtil {
|
2023-09-22 00:26:51 +02:00
|
|
|
public static int getTicketLevelFor(net.minecraft.world.level.chunk.ChunkStatus status) {
|
|
|
|
return net.minecraft.server.level.ChunkMap.MAX_VIEW_DISTANCE + net.minecraft.world.level.chunk.ChunkStatus.getDistance(status);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2023-09-22 00:26:51 +02:00
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @Nullable
|
2023-09-22 00:26:51 +02:00
|
|
|
+ public static net.minecraft.network.chat.Component getBaseComponentFromNbt(String key, net.minecraft.nbt.CompoundTag compound) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!compound.contains(key)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String string = compound.getString(key);
|
|
|
|
+ try {
|
2023-09-22 00:26:51 +02:00
|
|
|
+ return net.minecraft.network.chat.Component.Serializer.fromJson(string);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ } catch (com.google.gson.JsonParseException e) {
|
|
|
|
+ org.bukkit.Bukkit.getLogger().warning("Unable to parse " + key + " from " + compound +": " + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
2023-09-22 00:26:51 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
|
2023-12-05 23:21:44 +01:00
|
|
|
index 129f0e6108366dbba1bafb04e01e5e5e6489f577..ac0aeb53176069d0835b6b08c8d871edae846763 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
|
2022-06-08 02:15:06 +02:00
|
|
|
@@ -72,7 +72,7 @@ public abstract class BaseCommandBlock implements CommandSource {
|
2021-06-13 08:48:25 +02:00
|
|
|
this.command = nbt.getString("Command");
|
|
|
|
this.successCount = nbt.getInt("SuccessCount");
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.setName(Component.Serializer.fromJson(nbt.getString("CustomName")));
|
2022-10-24 21:43:46 +02:00
|
|
|
+ this.setName(io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt)); // Paper - Catch ParseException
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-06-13 08:48:25 +02:00
|
|
|
if (nbt.contains("TrackOutput", 1)) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEntity.java
|
2023-09-22 00:26:51 +02:00
|
|
|
index c6194fa1611412ac119fed493d5eab5a160e593d..d89037a83ae1b6d2afa6a589c1b8098cbedf3d2d 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEntity.java
|
2022-06-08 02:15:06 +02:00
|
|
|
@@ -98,7 +98,7 @@ public class BannerBlockEntity extends BlockEntity implements Nameable {
|
2021-06-13 08:48:25 +02:00
|
|
|
public void load(CompoundTag nbt) {
|
|
|
|
super.load(nbt);
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
2022-10-24 21:43:46 +02:00
|
|
|
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-06-13 08:48:25 +02:00
|
|
|
this.itemPatterns = nbt.getList("Patterns", 10);
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
2023-12-05 18:20:55 +01:00
|
|
|
index 25764076fec05b1362aa9b9b608e03bd39817d90..fce3a45d09a93ca68a3d49f2e666afa4c860d042 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
2022-12-07 20:22:28 +01:00
|
|
|
@@ -31,7 +31,7 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
|
2021-06-13 08:48:25 +02:00
|
|
|
super.load(nbt);
|
|
|
|
this.lockKey = LockCode.fromTag(nbt);
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
2022-10-24 21:43:46 +02:00
|
|
|
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
2022-01-06 12:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
2024-01-24 13:07:40 +01:00
|
|
|
index f4e1dc338dd240371694dd7a3455c79d5cea251a..f3b9a692417dbfc67b939a753c29ad1c159e274b 100644
|
2022-01-06 12:40:51 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
2023-09-22 00:26:51 +02:00
|
|
|
@@ -389,7 +389,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
|
|
|
|
this.secondaryPower = BeaconBlockEntity.loadEffect(nbt, "secondary_effect");
|
|
|
|
this.levels = nbt.getInt("Levels"); // CraftBukkit - SPIGOT-5053, use where available
|
2022-01-06 12:40:51 +01:00
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
2022-10-24 21:43:46 +02:00
|
|
|
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
2022-01-06 12:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.lockKey = LockCode.fromTag(nbt);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/EnchantmentTableBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/EnchantmentTableBlockEntity.java
|
2023-09-22 19:59:56 +02:00
|
|
|
index 3a8bdb788b07b0a8cda3d4b872ede52ca9a005c4..65e1381bb2d10bd212463feb602c60f8fdb9ade1 100644
|
2022-01-06 12:40:51 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/EnchantmentTableBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/EnchantmentTableBlockEntity.java
|
2022-06-08 02:15:06 +02:00
|
|
|
@@ -42,7 +42,7 @@ public class EnchantmentTableBlockEntity extends BlockEntity implements Nameable
|
2022-01-06 12:40:51 +01:00
|
|
|
public void load(CompoundTag nbt) {
|
|
|
|
super.load(nbt);
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
2022-10-24 21:43:46 +02:00
|
|
|
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|