From 7afddcc411d8d104ff5211a7463fcc0131c623c0 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 6 Jan 2021 18:00:40 +0000 Subject: [PATCH] Fix more NBT mutability issues --- .../boydti/fawe/object/changeset/BlockBagChangeSet.java | 2 +- .../java/com/boydti/fawe/object/extent/StripNBTExtent.java | 7 +++++-- .../worldedit/extent/transform/BlockTransformExtent.java | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java index e1ede0d10..4b9855523 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java @@ -112,7 +112,7 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet { @Override public void addTileCreate(CompoundTag nbt) { if (nbt.containsKey("items")) { - Map map = nbt.getValue(); + Map map = new HashMap<>(nbt.getValue()); map.remove("items"); } super.addTileCreate(nbt); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java index 19b3df573..bdb7c5ab3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java @@ -13,6 +13,7 @@ import com.sk89q.worldedit.world.NbtValued; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; +import java.util.HashMap; import java.util.Map; import java.util.Set; import javax.annotation.Nullable; @@ -55,10 +56,11 @@ public class StripNBTExtent extends AbstractDelegateExtent { return block; } CompoundTag nbt = localBlock.getNbtData(); - Map value = nbt.getValue(); + Map value = new HashMap<>(nbt.getValue()); for (String key : strip) { value.remove(key); } + localBlock.setNbtData(new CompoundTag(value)); return (B) localBlock; } @@ -67,10 +69,11 @@ public class StripNBTExtent extends AbstractDelegateExtent { return entity; } CompoundTag nbt = entity.getNbtData(); - Map value = nbt.getValue(); + Map value = new HashMap<>(nbt.getValue()); for (String key : strip) { value.remove(key); } + entity.setNbtData(new CompoundTag(value)); return entity; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 7a1d67ec9..1bb227c10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -46,6 +46,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -336,8 +337,9 @@ public class BlockTransformExtent extends ResettableExtent { Direction newDirection = Direction.findClosest(applyAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL); if (newDirection != null) { - Map values = tag.getValue(); + Map values = new HashMap<>(tag.getValue()); values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection))); + tag = new CompoundTag(values); } } }