Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/server/0263-Catch-JsonParseException-in-Entity-and-TE-names.patch

115 Zeilen
6.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 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/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
index b19850ae31f6c796cb3491dd5070d28e0ffd242c..d1a59c2af0557a816c094983ec60097fb4de060c 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -14,6 +14,8 @@ import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
2021-06-11 14:02:28 +02:00
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.MinecraftServer;
2021-06-11 14:02:28 +02:00
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.DistanceManager;
@@ -529,6 +531,21 @@ public final class MCUtil {
2021-06-11 14:02:28 +02:00
}
}
2021-06-13 08:48:25 +02:00
2021-06-11 14:02:28 +02:00
+ @Nullable
+ public static Component getBaseComponentFromNbt(String key, CompoundTag compound) {
+ if (!compound.contains(key)) {
+ return null;
+ }
+ String string = compound.getString(key);
+ try {
2021-06-16 19:48:25 +02:00
+ return 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;
+ }
2021-06-13 08:48:25 +02:00
+
public static ChunkStatus getChunkStatus(ChunkHolder chunk) {
return chunk.getChunkHolderStatus();
2021-06-13 08:48:25 +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
index a0728e95251e8110bcecd00512c7a266fe120794..7dac559fd35e7ba646b84bb28315001375723643 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")));
+ 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
2022-12-07 20:22:28 +01:00
index 6b983e3e867bdd8cdffaf4575bbf67ad96b57ec7..66e2137f9379e885294f2b9f67f7e35296792770 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"));
+ 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
2022-12-07 20:22:28 +01:00
index 084e26de66c8204cb9aaad51bad3270228889ea3..a782994e2e53f2c4212c2d59ce740ebf00a826b0 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"));
+ 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
2022-12-07 20:22:28 +01:00
index 3a17c143de499d81109ae7d6e9fe18718139c5b7..04c2872e2a492adef5aec98289a8cf2af6611757 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
2022-12-07 20:22:28 +01:00
@@ -367,7 +367,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2022-01-06 12:40:51 +01:00
this.levels = nbt.getInt("Levels"); // SPIGOT-5053, use where available
// CraftBukkit end
if (nbt.contains("CustomName", 8)) {
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
+ 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
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"));
+ this.name = io.papermc.paper.util.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
2021-06-11 14:02:28 +02:00
}
}