2021-06-11 12:02:28 +00: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/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
2021-12-23 10:32:26 +00:00
|
|
|
index ccdee183f02ab55723e16f41efce55dc51e96297..162aa7718488a74980843944e0d026ccfd5a65a5 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
2021-11-04 02:42:18 +00:00
|
|
|
@@ -7,6 +7,8 @@ import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet;
|
|
|
|
import java.lang.ref.Cleaner;
|
2021-06-11 12:02:28 +00:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
+import net.minecraft.nbt.CompoundTag;
|
|
|
|
+import net.minecraft.network.chat.Component;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.level.ChunkPos;
|
2021-12-23 10:32:26 +00:00
|
|
|
@@ -524,6 +526,21 @@ public final class MCUtil {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-13 06:48:25 +00:00
|
|
|
|
2021-06-11 12:02:28 +00: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 17:48:25 +00:00
|
|
|
+ return Component.Serializer.fromJson(string);
|
2021-06-11 12:02:28 +00: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 06:48:25 +00: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 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
|
2022-01-06 11:40:51 +00:00
|
|
|
index 04a3627667498b841fbff547d1874d99cc708af4..5b125aa77e769983a0aee7c5f6eb6a8a146fead0 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
|
2022-01-06 11:40:51 +00:00
|
|
|
@@ -73,7 +73,7 @@ public abstract class BaseCommandBlock implements CommandSource {
|
2021-06-13 06:48:25 +00: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-01-06 11:40:51 +00:00
|
|
|
+ this.setName(net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt)); // Paper - Catch ParseException
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 06:48:25 +00:00
|
|
|
if (nbt.contains("TrackOutput", 1)) {
|
2021-06-11 12:02:28 +00: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-01-06 11:40:51 +00:00
|
|
|
index 8854901b439cdeddc528e02fa5f8539869556a3c..aec30b264e2e24ea101f8b3296a93293b4c9eef4 100644
|
2021-06-11 12:02:28 +00: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-01-06 11:40:51 +00:00
|
|
|
@@ -97,7 +97,7 @@ public class BannerBlockEntity extends BlockEntity implements Nameable {
|
2021-06-13 06:48:25 +00:00
|
|
|
public void load(CompoundTag nbt) {
|
|
|
|
super.load(nbt);
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
2022-01-06 11:40:51 +00:00
|
|
|
+ this.name = net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 06:48:25 +00:00
|
|
|
this.itemPatterns = nbt.getList("Patterns", 10);
|
2021-06-11 12:02:28 +00: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-01-06 11:40:51 +00:00
|
|
|
index cfd1e2fbc029d928daa2d9f12df393c8cf30e850..72c4c367b3531b21f1f28601735a5250069b8713 100644
|
2021-06-11 12:02:28 +00: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-01-06 11:40:51 +00:00
|
|
|
@@ -31,7 +31,7 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
|
2021-06-13 06:48:25 +00:00
|
|
|
super.load(nbt);
|
|
|
|
this.lockKey = LockCode.fromTag(nbt);
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
2022-01-06 11:40:51 +00:00
|
|
|
+ this.name = net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
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
|
|
|
|
index 76a401bcfdacded2137142ed38d739ed65d9fae6..7c8809e679670ba0e0ea7a1e193913e45b34a97a 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
|
|
|
@@ -360,7 +360,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider {
|
|
|
|
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 = net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
|
|
|
}
|
|
|
|
|
|
|
|
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 b03621ebd0a94ab2dceb9006aee43fd5320094e3..424ad38b5522d9b76aa1bf726a9fe2c1e934598d 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/EnchantmentTableBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/EnchantmentTableBlockEntity.java
|
|
|
|
@@ -43,7 +43,7 @@ public class EnchantmentTableBlockEntity extends BlockEntity implements Nameable
|
|
|
|
public void load(CompoundTag nbt) {
|
|
|
|
super.load(nbt);
|
|
|
|
if (nbt.contains("CustomName", 8)) {
|
|
|
|
- this.name = Component.Serializer.fromJson(nbt.getString("CustomName"));
|
|
|
|
+ this.name = net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|