13
0
geforkt von Mirrors/Paper
Paper/patches/server/0263-Catch-JsonParseException-in-entity-and-block-entity-.patch

117 Zeilen
7.4 KiB
Diff

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
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.
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
2024-04-24 07:43:09 +02:00
index c57e8b6458800fe9bb27050eecc42bd3e5cf5a15..cdb514137797f4265dea5edb094caada5cee46a3 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -558,4 +558,19 @@ public final class MCUtil {
return builder.build();
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
2024-04-24 07:43:09 +02:00
+ public static net.minecraft.network.chat.Component getBaseComponentFromNbt(final String key, final net.minecraft.nbt.CompoundTag compound, final net.minecraft.core.HolderLookup.Provider lookupProvider) {
2021-06-11 14:02:28 +02:00
+ if (!compound.contains(key)) {
+ return null;
+ }
2024-04-24 07:43:09 +02:00
+ final String string = compound.getString(key);
2021-06-11 14:02:28 +02:00
+ try {
2024-04-24 07:43:09 +02:00
+ return net.minecraft.network.chat.Component.Serializer.fromJson(string, lookupProvider);
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
2024-04-24 07:43:09 +02:00
index 626e4fe03dea008907823b49f0dd936bbf7e4e04..2d0eac7a8aa94ed6c4ec024bc6024440cbeac702 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
2024-04-24 07:43:09 +02:00
@@ -75,7 +75,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)) {
2024-04-24 07:43:09 +02:00
- this.setCustomName(Component.Serializer.fromJson(nbt.getString("CustomName"), registries));
+ this.setCustomName(io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt, registries)); // Paper - Catch ParseException
} else {
this.setCustomName((Component) null);
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
2024-04-24 07:43:09 +02:00
index df4cd333ecd5c90e910df0c7c5ab5aa44c182903..2656e06ab2269141a13011eaa906f601887ca3e2 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
2024-04-24 07:43:09 +02:00
@@ -77,7 +77,7 @@ public class BannerBlockEntity extends BlockEntity implements Nameable {
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
super.loadAdditional(nbt, registryLookup);
2021-06-13 08:48:25 +02:00
if (nbt.contains("CustomName", 8)) {
2024-04-24 07:43:09 +02:00
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"), registryLookup);
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt, registryLookup); // Paper - Catch ParseException
2021-06-11 14:02:28 +02:00
}
2024-04-24 07:43:09 +02:00
if (nbt.contains("patterns")) {
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
2024-04-24 07:43:09 +02:00
index ee3b370b6b36914146db33a3211b6bbd2f8f16b7..ff3f26c31bd11b48f48e354ea6b33aa55dcbff5d 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
2024-04-24 07:43:09 +02:00
@@ -39,7 +39,7 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
super.loadAdditional(nbt, registryLookup);
2021-06-13 08:48:25 +02:00
this.lockKey = LockCode.fromTag(nbt);
if (nbt.contains("CustomName", 8)) {
2024-04-24 07:43:09 +02:00
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"), registryLookup);
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt, registryLookup); // 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-04-24 07:43:09 +02:00
index d3ef3d9a67bc54a4c82a39718f01201201dfc44c..18450017bc3df2f0b1a5715e6021e8e5defa24a1 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
2024-04-24 07:43:09 +02:00
@@ -391,7 +391,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2023-09-22 00:26:51 +02:00
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)) {
2024-04-24 07:43:09 +02:00
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"), registryLookup);
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt, registryLookup); // Paper - Catch ParseException
2022-01-06 12:40:51 +01:00
}
this.lockKey = LockCode.fromTag(nbt);
2024-04-24 07:43:09 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
index 767994f493fb0a0e4bf097cd7cc178c10e79e937..c3503eaec5c5ece6e27a52fb703d06ec7c767383 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/EnchantingTableBlockEntity.java
@@ -45,7 +45,7 @@ public class EnchantingTableBlockEntity extends BlockEntity implements Nameable
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
super.loadAdditional(nbt, registryLookup);
2022-01-06 12:40:51 +01:00
if (nbt.contains("CustomName", 8)) {
2024-04-24 07:43:09 +02:00
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"), registryLookup);
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt, registryLookup); // Paper - Catch ParseException
2021-06-11 14:02:28 +02:00
}
}
2024-04-24 07:43:09 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
index ebba6bc5b337d19e32be5a78294501ed8300f2bd..adc87c2da5a4a4a89eb9708850376eaed49cf20a 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
@@ -145,7 +145,7 @@ public class SkullBlockEntity extends BlockEntity {
}
if (nbt.contains("custom_name", 8)) {
- this.customName = Component.Serializer.fromJson(nbt.getString("custom_name"), registryLookup);
+ this.customName = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("custom_name", nbt, registryLookup); // Paper - Catch ParseException
} else {
this.customName = null;
}