From a3e86aeb0440d23c1c37311db1ca80ae76b5af6a Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 6 Jan 2022 12:40:51 +0100 Subject: [PATCH] Catch more json parse errors --- ...arseException-in-Entity-and-TE-names.patch | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/patches/server/Catch-JsonParseException-in-Entity-and-TE-names.patch b/patches/server/Catch-JsonParseException-in-Entity-and-TE-names.patch index 2ffae4e3c0..1d72f29a22 100644 --- a/patches/server/Catch-JsonParseException-in-Entity-and-TE-names.patch +++ b/patches/server/Catch-JsonParseException-in-Entity-and-TE-names.patch @@ -51,20 +51,12 @@ diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java +++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java -@@ -0,0 +0,0 @@ import net.minecraft.commands.CommandSourceStack; - import net.minecraft.nbt.CompoundTag; - import net.minecraft.network.chat.Component; - import net.minecraft.network.chat.TextComponent; -+import net.minecraft.server.MCUtil; - import net.minecraft.server.MinecraftServer; - import net.minecraft.server.level.ServerLevel; - import net.minecraft.util.StringUtil; @@ -0,0 +0,0 @@ public abstract class BaseCommandBlock implements CommandSource { 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(MCUtil.getBaseComponentFromNbt("CustomName", nbt)); // Paper - Catch ParseException ++ this.setName(net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt)); // Paper - Catch ParseException } if (nbt.contains("TrackOutput", 1)) { @@ -72,20 +64,12 @@ diff --git a/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEnt index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/BannerBlockEntity.java -@@ -0,0 +0,0 @@ import net.minecraft.nbt.ListTag; - import net.minecraft.network.chat.Component; - import net.minecraft.network.chat.TranslatableComponent; - import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -+import net.minecraft.server.MCUtil; - import net.minecraft.world.Nameable; - import net.minecraft.world.item.BlockItem; - import net.minecraft.world.item.DyeColor; @@ -0,0 +0,0 @@ public class BannerBlockEntity 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 = MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException ++ this.name = net.minecraft.server.MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException } this.itemPatterns = nbt.getList("Patterns", 10); @@ -93,20 +77,38 @@ diff --git a/src/main/java/net/minecraft/world/level/block/entity/BaseContainerB index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java -@@ -0,0 +0,0 @@ import net.minecraft.core.BlockPos; - import net.minecraft.nbt.CompoundTag; - import net.minecraft.network.chat.Component; - import net.minecraft.network.chat.TranslatableComponent; -+import net.minecraft.server.MCUtil; - import net.minecraft.sounds.SoundEvents; - import net.minecraft.sounds.SoundSource; - import net.minecraft.world.Container; @@ -0,0 +0,0 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co super.load(nbt); this.lockKey = LockCode.fromTag(nbt); if (nbt.contains("CustomName", 8)) { - this.name = Component.Serializer.fromJson(nbt.getString("CustomName")); -+ this.name = MCUtil.getBaseComponentFromNbt("CustomName", nbt); // Paper - Catch ParseException ++ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 +@@ -0,0 +0,0 @@ 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 } }