Sanitize sent BlockEntity NBT

This commit is contained in:
Owen1212055
2021-12-03 16:55:50 -05:00
parent 01eab6be00
commit 37bf078394
3 changed files with 33 additions and 5 deletions

View File

@@ -27,7 +27,7 @@
}
private void validateBlockState(BlockState state) {
@@ -74,8 +85,17 @@
@@ -74,7 +85,16 @@
return this.level != null;
}
@@ -35,17 +35,16 @@
+ // CraftBukkit start - read container
+ protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registries) {
+ this.persistentDataContainer.clear(); // Paper - clear instead of init
+
+ net.minecraft.nbt.Tag persistentDataTag = nbt.get("PublicBukkitValues");
+ if (persistentDataTag instanceof CompoundTag) {
+ this.persistentDataContainer.putAll((CompoundTag) persistentDataTag);
+ }
+ }
+ // CraftBukkit end
+
public final void loadWithComponents(CompoundTag nbt, HolderLookup.Provider registries) {
this.loadAdditional(nbt, registries);
BlockEntity.ComponentHelper.COMPONENTS_CODEC.parse(registries.createSerializationContext(NbtOps.INSTANCE), nbt).resultOrPartial((s) -> {
@@ -114,6 +134,11 @@
}).ifPresent((nbtbase) -> {
nbttagcompound.merge((CompoundTag) nbtbase);
@@ -109,7 +108,7 @@
}
protected void collectImplicitComponents(DataComponentMap.Builder builder) {}
@@ -321,6 +361,22 @@
@@ -321,6 +361,30 @@
}
}
@@ -128,6 +127,14 @@
+ return null;
+ }
+ // CraftBukkit end
+
+ // Paper start - Sanitize sent data
+ public CompoundTag sanitizeSentNbt(CompoundTag tag) {
+ tag.remove("PublicBukkitValues");
+
+ return tag;
+ }
+ // Paper end - Sanitize sent data
+
private static class ComponentHelper {