From aac02ceea167a47ec8fd449c60a972af2bf67080 Mon Sep 17 00:00:00 2001 From: Aurora Date: Thu, 25 Jun 2020 22:13:34 +0200 Subject: [PATCH 01/26] start reimplementing entities --- .../sk89q/worldedit/bukkit/BukkitEntity.java | 2 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 1 - .../object/clipboard/WorldCopyClipboard.java | 5 + .../java/com/sk89q/worldedit/EditSession.java | 19 ++++ .../com/sk89q/worldedit/extent/Extent.java | 1 + .../extent/clipboard/BlockArrayClipboard.java | 8 ++ .../function/operation/ForwardExtentCopy.java | 7 +- .../worldedit/util/io/file/ArchiveDir.java | 26 ++--- .../worldedit/util/io/file/SafeFiles.java | 98 +++++++++---------- .../com/sk89q/worldedit/world/NullWorld.java | 1 + 10 files changed, 101 insertions(+), 67 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java index d21ddcd4c..be50815f3 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java @@ -89,7 +89,7 @@ public class BukkitEntity implements Entity { @Override public com.sk89q.worldedit.world.entity.EntityType getType() { - return EntityTypes.get(type.getName().toUpperCase(Locale.ROOT)); + return EntityTypes.get(type.getName().toLowerCase(Locale.ROOT)); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 2818a8434..d8d613f22 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -92,7 +92,6 @@ public class BukkitWorld extends AbstractWorld { @Override public List getEntities(Region region) { World world = getWorld(); - List ents = world.getEntities(); List entities = new ArrayList<>(); for (Entity ent : ents) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java index 054ecae3e..7bce8a84a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java @@ -63,4 +63,9 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { return hasBiomes; } + @Override + public List getEntities(Region region) { + return getExtent().getEntities(region); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index efc4eaa51..e289dd249 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -46,6 +46,8 @@ import com.boydti.fawe.util.ExtentTraverser; import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -117,6 +119,7 @@ import com.sk89q.worldedit.regions.shape.RegionShape; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; @@ -3039,4 +3042,20 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } return false; } + + @Override + public List getEntities(Region region) { + return world.getEntities(region); + } + + @Override + public List getEntities() { + System.out.println("editsession"); + return world.getEntities(); + } + + @Override + public Entity createEntity(Location location, BaseEntity entity) { + return world.createEntity(location, entity); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java index b9c20c8f0..03731a1c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -132,6 +132,7 @@ public interface Extent extends InputExtent, OutputExtent { * @return a list of entities */ default List getEntities() { + System.out.println("el"); return Collections.emptyList(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 9817dd235..559fbc6a6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -195,11 +195,19 @@ public class BlockArrayClipboard implements Clipboard { @Override public List getEntities(Region region) { + System.out.println("blockarrayclipboard"); region = region.clone(); region.shift(BlockVector3.ZERO.subtract(origin)); return getParent().getEntities(region); } + @Override + public List getEntities() { + System.out.println("blockarrayall"); + return getParent().getEntities(); + } + + @Override @Nullable public Entity createEntity(Location location, BaseEntity entity) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index cedfee026..ca96008b6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -397,7 +397,7 @@ public class ForwardExtentCopy implements Operation { Operations.completeBlindly(blockCopy); if (!entities.isEmpty()) { - ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform); + ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), finalDest, to.toVector3(), currentTransform); entityCopy.setRemoving(removingEntities); List entities2 = Lists.newArrayList(source.getEntities(region)); entities2.removeIf(entity -> { @@ -406,6 +406,7 @@ public class ForwardExtentCopy implements Operation { }); EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); Operations.completeBlindly(entityVisitor); + affectedEntities += entityVisitor.getAffected(); } if (transExt != null) { @@ -427,8 +428,8 @@ public class ForwardExtentCopy implements Operation { return ImmutableList.of( TranslatableComponent.of("worldedit.operation.affected.block", TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), - TranslatableComponent.of("worldedit.operation.affected.biome", - TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), + //TranslatableComponent.of("worldedit.operation.affected.biome", + // TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), TranslatableComponent.of("worldedit.operation.affected.entity", TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) ); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java index b0e48502f..32619f4fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java @@ -18,16 +18,16 @@ */ package com.sk89q.worldedit.util.io.file; - -import java.io.Closeable; -import java.nio.file.Path; - -/** - * Represents an archive opened as a directory. This must be closed after work on the Path is - * done. - */ -public interface ArchiveDir extends Closeable { - - Path getPath(); - -} + +import java.io.Closeable; +import java.nio.file.Path; + +/** + * Represents an archive opened as a directory. This must be closed after work on the Path is + * done. + */ +public interface ArchiveDir extends Closeable { + + Path getPath(); + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java index e790f0d30..5a8363578 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java @@ -18,52 +18,52 @@ */ package com.sk89q.worldedit.util.io.file; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class SafeFiles { - - /** - * A version of {@link Files#list(Path)} that won't leak resources. - * - *

- * Instead, it immediately consumes the entire listing into a {@link List} and - * calls {@link List#stream()}. - *

- * - * @param dir the directory to list - * @return an I/O-resource-free stream of the files in the directory - * @throws IOException if an I/O error occurs - */ - public static Stream noLeakFileList(Path dir) throws IOException { - try (Stream stream = Files.list(dir)) { - return stream.collect(Collectors.toList()).stream(); - } - } - - /** - * {@link Path#getFileName()} includes a slash sometimes for some reason. - * This will get rid of it. - * - * @param path the path to get the file name for - * @return the file name of the given path - */ - public static String canonicalFileName(Path path) { - return dropSlash(path.getFileName().toString()); - } - - private static String dropSlash(String name) { - if (name.isEmpty() || name.codePointBefore(name.length()) != '/') { - return name; - } - return name.substring(0, name.length() - 1); - } - - private SafeFiles() { - } -} + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SafeFiles { + + /** + * A version of {@link Files#list(Path)} that won't leak resources. + * + *

+ * Instead, it immediately consumes the entire listing into a {@link List} and + * calls {@link List#stream()}. + *

+ * + * @param dir the directory to list + * @return an I/O-resource-free stream of the files in the directory + * @throws IOException if an I/O error occurs + */ + public static Stream noLeakFileList(Path dir) throws IOException { + try (Stream stream = Files.list(dir)) { + return stream.collect(Collectors.toList()).stream(); + } + } + + /** + * {@link Path#getFileName()} includes a slash sometimes for some reason. + * This will get rid of it. + * + * @param path the path to get the file name for + * @return the file name of the given path + */ + public static String canonicalFileName(Path path) { + return dropSlash(path.getFileName().toString()); + } + + private static String dropSlash(String name) { + if (name.isEmpty() || name.codePointBefore(name.length()) != '/') { + return name; + } + return name.substring(0, name.length() - 1); + } + + private SafeFiles() { + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index f37665232..446e564af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -187,6 +187,7 @@ public class NullWorld extends AbstractWorld { @Override public List getEntities(Region region) { + System.out.println("nullworld"); return Collections.emptyList(); } From 54008be1a2440c54583150d96deeb1eb70de4813 Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 26 Jun 2020 13:52:18 +0200 Subject: [PATCH 02/26] got paste -e working, still throws IllegalStateException but idc --- .../com/sk89q/worldedit/bukkit/BukkitWorld.java | 16 +++++++++++++++- .../adapter/IDelegateBukkitImplAdapter.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index d8d613f22..458958852 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -54,6 +54,9 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.function.Supplier; import javax.annotation.Nullable; import org.bukkit.Effect; import org.bukkit.TreeType; @@ -61,6 +64,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.inventory.DoubleChestInventory; import org.bukkit.inventory.Inventory; @@ -115,7 +119,7 @@ public class BukkitWorld extends AbstractWorld { @Override public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - if (adapter != null) { + if (adapter != null && Fawe.isMainThread()) { try { Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity); if (createdEntity != null) { @@ -131,6 +135,16 @@ public class BukkitWorld extends AbstractWorld { e.printStackTrace(); return null; } + } else if (adapter != null && !Fawe.isMainThread()){ + Future future = Fawe.get().getQueueHandler().sync((Supplier)() -> this.createEntity(location, entity)); + while (!future.isDone()) { + ((CraftWorld)worldRef.get()).getHandle().getChunkProvider().runTasks(); + } + try { + return future.get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } } else { return null; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java index 6656c032f..f488a1617 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java @@ -85,7 +85,7 @@ public interface IDelegateBukkitImplAdapter extends BukkitImplAdapter { default Entity createEntity(Location location, BaseEntity state) { return getParent().createEntity(location, state); } - + @Override default Map> getProperties(BlockType blockType) { return getParent().getProperties(blockType); From 6fc68da2ce3b920fa137783276bf7769a29a26f0 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 1 Jul 2020 14:52:50 +0200 Subject: [PATCH 03/26] Revert "got paste -e working, still throws IllegalStateException but idc" This reverts commit 54008be1a2440c54583150d96deeb1eb70de4813. --- .../com/sk89q/worldedit/bukkit/BukkitWorld.java | 13 +------------ .../bukkit/adapter/IDelegateBukkitImplAdapter.java | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index b40256059..2fe53dd30 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -61,7 +61,6 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.inventory.DoubleChestInventory; import org.bukkit.inventory.Inventory; @@ -123,7 +122,7 @@ public class BukkitWorld extends AbstractWorld { @Override public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - if (adapter != null && Fawe.isMainThread()) { + if (adapter != null) { try { Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity); if (createdEntity != null) { @@ -139,16 +138,6 @@ public class BukkitWorld extends AbstractWorld { e.printStackTrace(); return null; } - } else if (adapter != null && !Fawe.isMainThread()){ - Future future = Fawe.get().getQueueHandler().sync((Supplier)() -> this.createEntity(location, entity)); - while (!future.isDone()) { - ((CraftWorld)worldRef.get()).getHandle().getChunkProvider().runTasks(); - } - try { - return future.get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } } else { return null; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java index 4d7dc9740..5bf4d88af 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java @@ -77,7 +77,7 @@ public interface IDelegateBukkitImplAdapter extends BukkitImplAdapter { default Entity createEntity(Location location, BaseEntity state) { return getParent().createEntity(location, state); } - + @Override default Map> getProperties(BlockType blockType) { return getParent().getProperties(blockType); From 9fc2387f1160617dac7f091d6a6f36ca74408857 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 1 Jul 2020 14:54:11 +0200 Subject: [PATCH 04/26] Revert "start reimplementing entities" This reverts commit aac02ceea167a47ec8fd449c60a972af2bf67080. --- .../sk89q/worldedit/bukkit/BukkitEntity.java | 2 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 1 + .../object/clipboard/WorldCopyClipboard.java | 5 - .../java/com/sk89q/worldedit/EditSession.java | 18 ---- .../com/sk89q/worldedit/extent/Extent.java | 1 - .../extent/clipboard/BlockArrayClipboard.java | 8 -- .../function/operation/ForwardExtentCopy.java | 7 +- .../worldedit/util/io/file/ArchiveDir.java | 26 ++--- .../worldedit/util/io/file/SafeFiles.java | 98 +++++++++---------- .../com/sk89q/worldedit/world/NullWorld.java | 1 - 10 files changed, 67 insertions(+), 100 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java index be50815f3..d21ddcd4c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java @@ -89,7 +89,7 @@ public class BukkitEntity implements Entity { @Override public com.sk89q.worldedit.world.entity.EntityType getType() { - return EntityTypes.get(type.getName().toLowerCase(Locale.ROOT)); + return EntityTypes.get(type.getName().toUpperCase(Locale.ROOT)); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 2fe53dd30..588071c34 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -99,6 +99,7 @@ public class BukkitWorld extends AbstractWorld { @Override public List getEntities(Region region) { World world = getWorld(); + List ents = world.getEntities(); List entities = new ArrayList<>(); for (Entity ent : ents) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java index 7bce8a84a..054ecae3e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java @@ -63,9 +63,4 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { return hasBiomes; } - @Override - public List getEntities(Region region) { - return getExtent().getEntities(region); - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 29caa5b9c..e3e38757c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -46,8 +46,6 @@ import com.boydti.fawe.util.ExtentTraverser; import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; -import com.sk89q.worldedit.entity.BaseEntity; -import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -3056,20 +3054,4 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } return false; } - - @Override - public List getEntities(Region region) { - return world.getEntities(region); - } - - @Override - public List getEntities() { - System.out.println("editsession"); - return world.getEntities(); - } - - @Override - public Entity createEntity(Location location, BaseEntity entity) { - return world.createEntity(location, entity); - } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java index 03731a1c8..b9c20c8f0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -132,7 +132,6 @@ public interface Extent extends InputExtent, OutputExtent { * @return a list of entities */ default List getEntities() { - System.out.println("el"); return Collections.emptyList(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 559fbc6a6..9817dd235 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -195,19 +195,11 @@ public class BlockArrayClipboard implements Clipboard { @Override public List getEntities(Region region) { - System.out.println("blockarrayclipboard"); region = region.clone(); region.shift(BlockVector3.ZERO.subtract(origin)); return getParent().getEntities(region); } - @Override - public List getEntities() { - System.out.println("blockarrayall"); - return getParent().getEntities(); - } - - @Override @Nullable public Entity createEntity(Location location, BaseEntity entity) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index ca96008b6..cedfee026 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -397,7 +397,7 @@ public class ForwardExtentCopy implements Operation { Operations.completeBlindly(blockCopy); if (!entities.isEmpty()) { - ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), finalDest, to.toVector3(), currentTransform); + ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform); entityCopy.setRemoving(removingEntities); List entities2 = Lists.newArrayList(source.getEntities(region)); entities2.removeIf(entity -> { @@ -406,7 +406,6 @@ public class ForwardExtentCopy implements Operation { }); EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); Operations.completeBlindly(entityVisitor); - affectedEntities += entityVisitor.getAffected(); } if (transExt != null) { @@ -428,8 +427,8 @@ public class ForwardExtentCopy implements Operation { return ImmutableList.of( TranslatableComponent.of("worldedit.operation.affected.block", TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), - //TranslatableComponent.of("worldedit.operation.affected.biome", - // TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), + TranslatableComponent.of("worldedit.operation.affected.biome", + TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), TranslatableComponent.of("worldedit.operation.affected.entity", TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) ); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java index 32619f4fe..b0e48502f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/ArchiveDir.java @@ -18,16 +18,16 @@ */ package com.sk89q.worldedit.util.io.file; - -import java.io.Closeable; -import java.nio.file.Path; - -/** - * Represents an archive opened as a directory. This must be closed after work on the Path is - * done. - */ -public interface ArchiveDir extends Closeable { - - Path getPath(); - -} + +import java.io.Closeable; +import java.nio.file.Path; + +/** + * Represents an archive opened as a directory. This must be closed after work on the Path is + * done. + */ +public interface ArchiveDir extends Closeable { + + Path getPath(); + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java index 5a8363578..e790f0d30 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/SafeFiles.java @@ -18,52 +18,52 @@ */ package com.sk89q.worldedit.util.io.file; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class SafeFiles { - - /** - * A version of {@link Files#list(Path)} that won't leak resources. - * - *

- * Instead, it immediately consumes the entire listing into a {@link List} and - * calls {@link List#stream()}. - *

- * - * @param dir the directory to list - * @return an I/O-resource-free stream of the files in the directory - * @throws IOException if an I/O error occurs - */ - public static Stream noLeakFileList(Path dir) throws IOException { - try (Stream stream = Files.list(dir)) { - return stream.collect(Collectors.toList()).stream(); - } - } - - /** - * {@link Path#getFileName()} includes a slash sometimes for some reason. - * This will get rid of it. - * - * @param path the path to get the file name for - * @return the file name of the given path - */ - public static String canonicalFileName(Path path) { - return dropSlash(path.getFileName().toString()); - } - - private static String dropSlash(String name) { - if (name.isEmpty() || name.codePointBefore(name.length()) != '/') { - return name; - } - return name.substring(0, name.length() - 1); - } - - private SafeFiles() { - } -} + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SafeFiles { + + /** + * A version of {@link Files#list(Path)} that won't leak resources. + * + *

+ * Instead, it immediately consumes the entire listing into a {@link List} and + * calls {@link List#stream()}. + *

+ * + * @param dir the directory to list + * @return an I/O-resource-free stream of the files in the directory + * @throws IOException if an I/O error occurs + */ + public static Stream noLeakFileList(Path dir) throws IOException { + try (Stream stream = Files.list(dir)) { + return stream.collect(Collectors.toList()).stream(); + } + } + + /** + * {@link Path#getFileName()} includes a slash sometimes for some reason. + * This will get rid of it. + * + * @param path the path to get the file name for + * @return the file name of the given path + */ + public static String canonicalFileName(Path path) { + return dropSlash(path.getFileName().toString()); + } + + private static String dropSlash(String name) { + if (name.isEmpty() || name.codePointBefore(name.length()) != '/') { + return name; + } + return name.substring(0, name.length() - 1); + } + + private SafeFiles() { + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index 81e3c9d7a..f3d6dd18a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -192,7 +192,6 @@ public class NullWorld extends AbstractWorld { @Override public List getEntities(Region region) { - System.out.println("nullworld"); return Collections.emptyList(); } From 34298f7dee517d5fa786390ea61d451d6beb3568 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 1 Jul 2020 19:28:38 +0200 Subject: [PATCH 05/26] Add back the getEntity Stuff since it seems to work fine --- .../main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java | 2 +- .../boydti/fawe/object/clipboard/WorldCopyClipboard.java | 4 ++++ .../src/main/java/com/sk89q/worldedit/EditSession.java | 6 ++++++ .../worldedit/function/operation/ForwardExtentCopy.java | 5 +++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java index d21ddcd4c..be50815f3 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java @@ -89,7 +89,7 @@ public class BukkitEntity implements Entity { @Override public com.sk89q.worldedit.world.entity.EntityType getType() { - return EntityTypes.get(type.getName().toUpperCase(Locale.ROOT)); + return EntityTypes.get(type.getName().toLowerCase(Locale.ROOT)); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java index 054ecae3e..7f6912b10 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java @@ -63,4 +63,8 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { return hasBiomes; } + @Override + public List getEntities(Region region) { + return getExtent().getEntities(region); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index e3e38757c..ccfaa0ccc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -46,6 +46,7 @@ import com.boydti.fawe.util.ExtentTraverser; import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; +import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -3054,4 +3055,9 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } return false; } + + @Override + public List getEntities(Region region) { + return world.getEntities(region); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index cedfee026..e12921516 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -406,6 +406,7 @@ public class ForwardExtentCopy implements Operation { }); EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); Operations.completeBlindly(entityVisitor); + affectedEntities += entityVisitor.getAffected(); } if (transExt != null) { @@ -427,8 +428,8 @@ public class ForwardExtentCopy implements Operation { return ImmutableList.of( TranslatableComponent.of("worldedit.operation.affected.block", TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), - TranslatableComponent.of("worldedit.operation.affected.biome", - TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), +// TranslatableComponent.of("worldedit.operation.affected.biome", +// TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), TranslatableComponent.of("worldedit.operation.affected.entity", TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) ); From 94b1233d98e782e0fb609d6c068e8de0a7604a1b Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 3 Jul 2020 19:52:55 +0200 Subject: [PATCH 06/26] implement entities in paste -e --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 25 ----------------- .../beta/implementation/IChunkExtent.java | 27 +++++++++++++++++++ .../com/boydti/fawe/util/ReflectionUtils.java | 16 ++++++++++- .../java/com/sk89q/worldedit/EditSession.java | 13 ++++++++- .../extent/clipboard/BlockArrayClipboard.java | 5 ++++ 5 files changed, 59 insertions(+), 27 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 588071c34..0e6ca78aa 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -119,31 +119,6 @@ public class BukkitWorld extends AbstractWorld { return list; } - @Nullable - @Override - public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - if (adapter != null) { - try { - Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity); - if (createdEntity != null) { - return new BukkitEntity(createdEntity); - } else { - return null; - } - } catch (Exception e) { - logger.warn("Corrupt entity found when creating: " + entity.getType().getId()); - if (entity.getNbtData() != null) { - logger.warn(entity.getNbtData().toString()); - } - e.printStackTrace(); - return null; - } - } else { - return null; - } - } - /** * Get the world handle. * diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index 5ebffe8cc..b299783bb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -1,13 +1,23 @@ package com.boydti.fawe.beta.implementation; import com.boydti.fawe.beta.IChunk; +import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.DoubleTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; +import java.util.List; +import java.util.Map; import org.jetbrains.annotations.Range; public interface IChunkExtent extends Extent { @@ -91,4 +101,21 @@ public interface IChunkExtent extends Extent { final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); return chunk.getOpacity(x & 15, y, z & 15); } + + @Override + default Entity createEntity(Location location, BaseEntity entity) { + final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); + CompoundTag tag = entity.getNbtData(); + Map map = ReflectionUtils.getMap(tag.getValue()); + map.put("Id", new StringTag(entity.getType().getName())); + ListTag pos = (ListTag) map.get("Pos"); + if (pos != null) { + List posList = ReflectionUtils.getList(pos.getValue()); + posList.set(0, new DoubleTag(location.getX() + 0.5)); + posList.set(1, new DoubleTag(location.getY())); + posList.set(2, new DoubleTag(location.getZ() + 0.5)); + } + chunk.setEntity(tag); + return null; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index 97505fd85..dfd78f0aa 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -88,7 +88,21 @@ public class ReflectionUtils { return list; } } - + private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(); + + public static Map getMap(Map map) { + try { + Class clazz = map.getClass(); + if (clazz != UNMODIFIABLE_MAP) return map; + Field m = clazz.getDeclaredField("m"); + m.setAccessible(true); + return (Map) m.get(map); + } catch (Throwable e) { + e.printStackTrace(); + return map; + } + } + public static Object getHandle(Object wrapper) { final Method getHandle = makeMethod(wrapper.getClass(), "getHandle"); return callMethod(getHandle, wrapper); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index ccfaa0ccc..b8e2153a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -46,6 +46,7 @@ import com.boydti.fawe.util.ExtentTraverser; import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; +import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; @@ -118,6 +119,7 @@ import com.sk89q.worldedit.regions.shape.RegionShape; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.eventbus.EventBus; @@ -3059,5 +3061,14 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override public List getEntities(Region region) { return world.getEntities(region); - } + } + + @Override + public Entity createEntity(Location location, BaseEntity entity){ + try { + return this.getExtent().createEntity(location, entity); + } catch (WorldEditException e) { + throw new RuntimeException("Unexpected exception", e); + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 9817dd235..f1716311c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -200,6 +200,11 @@ public class BlockArrayClipboard implements Clipboard { return getParent().getEntities(region); } + @Override + public List getEntities() { + return getParent().getEntities(); + } + @Override @Nullable public Entity createEntity(Location location, BaseEntity entity) { From 05ef46994e81dad0c14d77b0e2f7f8a1f308f68d Mon Sep 17 00:00:00 2001 From: aurorasmiles <21148213+aurorasmiles@users.noreply.github.com> Date: Fri, 3 Jul 2020 20:03:34 +0200 Subject: [PATCH 07/26] Update IChunkExtent.java fix Indentation --- .../fawe/beta/implementation/IChunkExtent.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index b299783bb..d651ef673 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -106,15 +106,15 @@ public interface IChunkExtent extends Extent { default Entity createEntity(Location location, BaseEntity entity) { final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); CompoundTag tag = entity.getNbtData(); - Map map = ReflectionUtils.getMap(tag.getValue()); - map.put("Id", new StringTag(entity.getType().getName())); - ListTag pos = (ListTag) map.get("Pos"); - if (pos != null) { - List posList = ReflectionUtils.getList(pos.getValue()); - posList.set(0, new DoubleTag(location.getX() + 0.5)); - posList.set(1, new DoubleTag(location.getY())); - posList.set(2, new DoubleTag(location.getZ() + 0.5)); - } + Map map = ReflectionUtils.getMap(tag.getValue()); + map.put("Id", new StringTag(entity.getType().getName())); + ListTag pos = (ListTag) map.get("Pos"); + if (pos != null) { + List posList = ReflectionUtils.getList(pos.getValue()); + posList.set(0, new DoubleTag(location.getX() + 0.5)); + posList.set(1, new DoubleTag(location.getY())); + posList.set(2, new DoubleTag(location.getZ() + 0.5)); + } chunk.setEntity(tag); return null; } From 50971ee31147115ac8b188edb8193742397a0415 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Sun, 26 Jul 2020 15:52:51 +0200 Subject: [PATCH 08/26] fix entity undo --- .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 16 ++----- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 17 +++---- .../mc1_16_1/BukkitGetBlocks_1_16_1.java | 16 ++----- .../beta/implementation/IChunkExtent.java | 46 +++++++++++++++++-- .../fawe/object/change/MutableTileChange.java | 7 --- .../extent/AbstractDelegateExtent.java | 6 +++ .../worldedit/extent/PassthroughExtent.java | 5 -- .../sk89q/worldedit/internal/Constants.java | 2 +- 8 files changed, 65 insertions(+), 50 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java index 0f5d33fe0..fd5902df1 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java @@ -269,7 +269,6 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { private void removeEntity(Entity entity) { entity.die(); - entity.valid = false; } public Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) { @@ -449,17 +448,12 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { if (type != null) { Entity entity = type.a(nmsWorld); if (entity != null) { - UUID uuid = entity.getUniqueID(); - entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); - entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); - if (nativeTag != null) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag); - for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { - tag.remove(name); - } - entity.f(tag); + BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag); + for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { + tag.remove(name); } + entity.f(tag); entity.setLocation(x, y, z, yaw, pitch); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java index 4518420a2..a48a7922f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java @@ -277,7 +277,6 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { private void removeEntity(Entity entity) { entity.die(); - entity.valid = false; } public Chunk ensureLoaded(net.minecraft.server.v1_15_R1.World nmsWorld, int X, int Z) { @@ -467,17 +466,13 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { if (type != null) { Entity entity = type.a(nmsWorld); if (entity != null) { - UUID uuid = entity.getUniqueID(); - entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); - entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); - if (nativeTag != null) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag); - for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { - tag.remove(name); - } - entity.f(tag); + BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag); + for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { + tag.remove(name); } + + entity.f(tag); entity.setLocation(x, y, z, yaw, pitch); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java index 2d5ace231..9433308c2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_16_1/BukkitGetBlocks_1_16_1.java @@ -245,7 +245,6 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { private void removeEntity(Entity entity) { entity.die(); - entity.valid = false; } public Chunk ensureLoaded(net.minecraft.server.v1_16_R1.World nmsWorld, int X, int Z) { @@ -438,17 +437,12 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks { if (type != null) { Entity entity = type.a(nmsWorld); if (entity != null) { - UUID uuid = entity.getUniqueID(); - entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); - entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); - if (nativeTag != null) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag); - for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { - tag.remove(name); - } - entity.save(tag); + BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag); + for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { + tag.remove(name); } + entity.load(tag); entity.setLocation(x, y, z, yaw, pitch); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index d651ef673..3cd6a9c31 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -4,7 +4,10 @@ import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.DoubleTag; +import com.sk89q.jnbt.IntArrayTag; +import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.LongTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEditException; @@ -16,8 +19,10 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.UUID; import org.jetbrains.annotations.Range; public interface IChunkExtent extends Extent { @@ -108,14 +113,47 @@ public interface IChunkExtent extends Extent { CompoundTag tag = entity.getNbtData(); Map map = ReflectionUtils.getMap(tag.getValue()); map.put("Id", new StringTag(entity.getType().getName())); + + //Set pos ListTag pos = (ListTag) map.get("Pos"); + List posList; if (pos != null) { - List posList = ReflectionUtils.getList(pos.getValue()); - posList.set(0, new DoubleTag(location.getX() + 0.5)); - posList.set(1, new DoubleTag(location.getY())); - posList.set(2, new DoubleTag(location.getZ() + 0.5)); + posList = ReflectionUtils.getList(pos.getValue()); + } else { + posList = new ArrayList<>(); + pos = new ListTag(DoubleTag.class, posList); + map.put("Pos", pos); } + posList.set(0, new DoubleTag(location.getX() + 0.5)); + posList.set(1, new DoubleTag(location.getY())); + posList.set(2, new DoubleTag(location.getZ() + 0.5)); + + //set new uuid + UUID newuuid = UUID.randomUUID(); + IntArrayTag uuid = (IntArrayTag) map.get("UUID"); + int[] uuidArray; + if (uuid != null) { + uuidArray = uuid.getValue(); + } else { + uuidArray = new int[4]; + uuid = new IntArrayTag(uuidArray); + map.put("UUID", uuid); + } + uuidArray[0] = (int) (newuuid.getMostSignificantBits() >> 32); + uuidArray[1] = (int) newuuid.getMostSignificantBits(); + uuidArray[2] = (int) (newuuid.getLeastSignificantBits() >> 32); + uuidArray[3] = (int) newuuid.getLeastSignificantBits(); + + map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits())); + map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits())); + chunk.setEntity(tag); return null; } + + @Override + default void removeEntity(int x, int y, int z, UUID uuid) { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + chunk.removeEntity(uuid); + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableTileChange.java b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableTileChange.java index b25e764d7..6c8c557fe 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableTileChange.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableTileChange.java @@ -1,16 +1,9 @@ package com.boydti.fawe.object.change; -import com.boydti.fawe.Fawe; -import com.boydti.fawe.beta.IQueueExtent; -import com.boydti.fawe.util.ExtentTraverser; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.IntTag; -import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.change.Change; -import java.util.Map; public class MutableTileChange implements Change { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java index aa0eb90a2..467de473d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java @@ -46,6 +46,7 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.List; +import java.util.UUID; import javax.annotation.Nullable; import org.jetbrains.annotations.Range; @@ -155,6 +156,11 @@ public class AbstractDelegateExtent implements Extent { return extent.createEntity(location, entity); } + @Override + public void removeEntity(int x, int y, int z, UUID uuid) { + extent.removeEntity(x, y, z, uuid); + } + @Override public List getEntities() { return extent.getEntities(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java index 14d8ba7d0..d6b387d94 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/PassthroughExtent.java @@ -36,11 +36,6 @@ public class PassthroughExtent extends AbstractDelegateExtent { super(extent); } - @Override - public void removeEntity(int x, int y, int z, UUID uuid) { - getExtent().removeEntity(x, y, z, uuid); - } - @Override public boolean regenerateChunk(int x, int z, @Nullable BiomeType type, @Nullable Long seed) { return getExtent().regenerateChunk(x, z, type, seed); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java index 9194866b4..996bdb0a6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java @@ -36,7 +36,7 @@ public final class Constants { static { NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList( - "UUIDLeast", "UUIDMost", // Bukkit and Vanilla +// "UUIDLeast", "UUIDMost", // Bukkit and Vanilla "WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla "PersistentIDMSB", "PersistentIDLSB" // Forge )); From 950f34333967fe89bb24fd2183f80a9c42e71259 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Sun, 26 Jul 2020 15:54:02 +0200 Subject: [PATCH 09/26] fix entity undo; amend constants --- .../src/main/java/com/sk89q/worldedit/internal/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java index 996bdb0a6..d074445fc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java @@ -36,7 +36,7 @@ public final class Constants { static { NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList( -// "UUIDLeast", "UUIDMost", // Bukkit and Vanilla +// "UUIDLeast", "UUIDMost", // Bukkit and Vanilla //UUID values need to be set manully to a new UUID "WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla "PersistentIDMSB", "PersistentIDLSB" // Forge )); From a38c82304a9e212238b9dd710b25e014c1ea564f Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Sun, 26 Jul 2020 18:26:21 +0200 Subject: [PATCH 10/26] fix rotation of entities in clipboard --- .../clipboard/DiskOptimizedClipboard.java | 6 +++ .../clipboard/MemoryOptimizedClipboard.java | 7 +++- .../extent/clipboard/BlockArrayClipboard.java | 38 +++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 21b2f5713..fbfcb24ae 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -40,6 +40,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -436,6 +437,11 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable public List getEntities() { return new ArrayList<>(entities); } + + @Override + public List getEntities(Region region) { + return new ArrayList<>(entities.stream().filter(e -> region.contains(e.getLocation().toBlockPoint())).collect(Collectors.toList())); + } @Override public void removeEntity(Entity entity) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 0a9b01282..f169e3fe4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.Nullable; public class MemoryOptimizedClipboard extends LinearClipboard { @@ -291,11 +292,15 @@ public class MemoryOptimizedClipboard extends LinearClipboard { return new ArrayList<>(entities); } + @Override + public List getEntities(Region region) { + return new ArrayList<>(entities.stream().filter(e -> region.contains(e.getLocation().toBlockPoint())).collect(Collectors.toList())); + } + @Override public void removeEntity(Entity entity) { if (entity instanceof ClipboardEntity) { this.entities.remove(entity); } } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index f1716311c..4d0bb889f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -45,6 +45,7 @@ import java.util.UUID; import org.jetbrains.annotations.NotNull; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.stream.Collectors; /** * Stores block data as a multi-dimensional array of {@link BlockState}s and @@ -197,18 +198,49 @@ public class BlockArrayClipboard implements Clipboard { public List getEntities(Region region) { region = region.clone(); region.shift(BlockVector3.ZERO.subtract(origin)); - return getParent().getEntities(region); + return getParent().getEntities(region).stream().map(e -> + { + if (e instanceof ClipboardEntity) { + ClipboardEntity ce = (ClipboardEntity) e; + Location oldloc = ce.getLocation(); + Location loc = new Location(oldloc.getExtent(), + oldloc.getX() + origin.getBlockX(), + oldloc.getY() + origin.getBlockY(), + oldloc.getZ() + origin.getBlockZ(), + oldloc.getYaw(), oldloc.getPitch()); + return new ClipboardEntity(loc, ce.entity); + } + return e; + }).collect(Collectors.toList()); } @Override public List getEntities() { - return getParent().getEntities(); + return getParent().getEntities().stream().map(e -> + { + if (e instanceof ClipboardEntity) { + ClipboardEntity ce = (ClipboardEntity) e; + Location oldloc = ce.getLocation(); + Location loc = new Location(oldloc.getExtent(), + oldloc.getX() + origin.getBlockX(), + oldloc.getY() + origin.getBlockY(), + oldloc.getZ() + origin.getBlockZ(), + oldloc.getYaw(), oldloc.getPitch()); + return new ClipboardEntity(loc, ce.entity); + } + return e; + }).collect(Collectors.toList()); } @Override @Nullable public Entity createEntity(Location location, BaseEntity entity) { - return getParent().createEntity(location, entity); + Location l = new Location(location.getExtent(), + location.getX() - origin.getBlockX(), + location.getY() - origin.getBlockY(), + location.getZ() - origin.getBlockZ(), + location.getYaw(), location.getPitch()); + return getParent().createEntity(l, entity); } @Override From f24ad69f8f26bdc8c817733b48e97e3e64397902 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Sun, 26 Jul 2020 19:05:32 +0200 Subject: [PATCH 11/26] fix entity paste location offsets --- .../com/boydti/fawe/beta/implementation/IChunkExtent.java | 4 ++-- .../sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index 3cd6a9c31..40815ab67 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -124,9 +124,9 @@ public interface IChunkExtent extends Extent { pos = new ListTag(DoubleTag.class, posList); map.put("Pos", pos); } - posList.set(0, new DoubleTag(location.getX() + 0.5)); + posList.set(0, new DoubleTag(location.getX())); posList.set(1, new DoubleTag(location.getY())); - posList.set(2, new DoubleTag(location.getZ() + 0.5)); + posList.set(2, new DoubleTag(location.getZ())); //set new uuid UUID newuuid = UUID.randomUUID(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 1d3228c80..eab35385f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -323,7 +323,7 @@ public class BlockArrayClipboard implements Clipboard { private final float yaw, pitch; public ClipboardEntity(Location loc, BaseEntity entity) { - this((Clipboard) loc.getExtent(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getYaw(), loc.getPitch(), entity); + this((Clipboard) loc.getExtent(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), entity); } public ClipboardEntity(Clipboard clipboard, double x, double y, double z, float yaw, float pitch, BaseEntity entity) { From 51cdd66c62b3fae96b8a9e4b211b9b2554e8f948 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Sun, 26 Jul 2020 19:08:35 +0200 Subject: [PATCH 12/26] fix imports --- .../src/main/java/com/boydti/fawe/util/ReflectionUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index 71572dbcb..eb44ba67e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -14,6 +14,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Map; public class ReflectionUtils { From 84d2c8f2cec4ad99fc07f552dc39da861033e92c Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Sun, 26 Jul 2020 19:52:03 +0200 Subject: [PATCH 13/26] fix redo exception; fix positioning of entities in redo --- .../boydti/fawe/object/change/MutableEntityChange.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableEntityChange.java b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableEntityChange.java index 9df641143..0cee1cb6c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableEntityChange.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableEntityChange.java @@ -78,12 +78,12 @@ public class MutableEntityChange implements Change { return; } List pos = (List) posTag.getValue(); - int x = MathMan.roundInt(pos.get(0).getValue()); - int y = MathMan.roundInt(pos.get(1).getValue()); - int z = MathMan.roundInt(pos.get(2).getValue()); + double x = pos.get(0).getValue(); + double y = pos.get(1).getValue(); + double z = pos.get(2).getValue(); Extent extent = context.getExtent(); Location location = new Location(extent, x, y, z, 0, 0); - String id = tag.getString("id"); + String id = tag.getString("Id"); EntityType type = EntityTypes.parse(id); BaseEntity entity = new BaseEntity(type, tag); context.getExtent().createEntity(location, entity); From 24fbd21ff14820b9b3c758762624cde3bdd15412 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Mon, 27 Jul 2020 23:51:26 +0200 Subject: [PATCH 14/26] added missing entity functions; all or nothing; and nothing did not work --- .../java/com/sk89q/worldedit/EditSession.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 26eb0421f..73216f950 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -150,6 +150,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.regions.Regions.asFlatRegion; import static com.sk89q.worldedit.regions.Regions.maximumBlockY; import static com.sk89q.worldedit.regions.Regions.minimumBlockY; +import java.util.UUID; /** * An {@link Extent} that handles history, {@link BlockBag}s, change limits, @@ -3088,6 +3089,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { return false; } + @Override + public List getEntities() { + return world.getEntities(); + } + @Override public List getEntities(Region region) { return world.getEntities(region); @@ -3101,4 +3107,14 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { throw new RuntimeException("Unexpected exception", e); } } + + @Override + public void removeEntity(int x, int y, int z, UUID uuid) + { + try { + this.getExtent().removeEntity(x, y, z, uuid); + } catch (WorldEditException e) { + throw new RuntimeException("Unexpected exception", e); + } + } } From 26110d336b6b7d16dc1ffa2b0e3f4cfceb79b5fa Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Mon, 27 Jul 2020 23:54:41 +0200 Subject: [PATCH 15/26] cleanup --- .../com/boydti/fawe/object/clipboard/WorldCopyClipboard.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java index 4770b3af8..f56af90d6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java @@ -64,8 +64,4 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { return hasBiomes; } - @Override - public List getEntities(Region region) { - return getExtent().getEntities(region); - } } From ae23794b436601bc86dd55fb1e4eed98e347a22b Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Wed, 29 Jul 2020 22:43:52 +0200 Subject: [PATCH 16/26] fix //cut -e --- .../adapter/impl/FAWE_Spigot_v1_14_R4.java | 7 ++- .../adapter/impl/FAWE_Spigot_v1_15_R2.java | 8 ++- .../adapter/impl/FAWE_Spigot_v1_16_R1.java | 20 +++---- .../beta/implementation/IChunkExtent.java | 54 ++++++++++++++++++- .../com/boydti/fawe/util/ReflectionUtils.java | 13 ----- .../function/entity/ExtentEntityCopy.java | 20 ++++++- .../function/operation/ForwardExtentCopy.java | 2 +- 7 files changed, 89 insertions(+), 35 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java index 35778d1fd..8eed58bbf 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java @@ -78,6 +78,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.StringTag; public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { private final Spigot_v1_14_R4 parent; @@ -235,7 +236,11 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I Supplier saveTag = () -> { NBTTagCompound tag = new NBTTagCompound(); readEntityIntoTag(mcEntity, tag); - return (CompoundTag) toNative(tag); + + //add Id for AbstractChangeSet to work + CompoundTag natve = (CompoundTag) toNative(tag); + natve.getValue().put("Id", new StringTag(id)); + return natve; }; return new LazyBaseEntity(type, saveTag); } else { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java index 85dd26089..febca28de 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java @@ -48,7 +48,6 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.entity.EntityType; @@ -82,6 +81,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.StringTag; public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { private final Spigot_v1_15_R2 parent; @@ -245,7 +245,11 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I Supplier saveTag = () -> { NBTTagCompound tag = new NBTTagCompound(); readEntityIntoTag(mcEntity, tag); - return (CompoundTag) toNative(tag); + + //add Id for AbstractChangeSet to work + CompoundTag natve = (CompoundTag) toNative(tag); + natve.getValue().put("Id", new StringTag(id)); + return natve; }; return new LazyBaseEntity(type, saveTag); } else { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java index 3a5f2af11..10eb88d51 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java @@ -22,17 +22,12 @@ package com.sk89q.worldedit.bukkit.adapter.impl; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkGet; -import com.boydti.fawe.beta.IQueueChunk; -import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.implementation.packet.ChunkPacket; -import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent; import com.boydti.fawe.bukkit.adapter.mc1_16_1.*; import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1; -import com.google.common.io.Files; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -42,7 +37,6 @@ import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.LazyBaseEntity; import com.sk89q.worldedit.internal.wna.WorldNativeAccess; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; @@ -55,7 +49,6 @@ import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.server.v1_16_R1.*; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.World.Environment; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_16_R1.CraftChunk; import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; @@ -65,22 +58,17 @@ import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.generator.ChunkGenerator; import javax.annotation.Nullable; -import java.io.File; -import java.io.IOException; import java.lang.ref.WeakReference; import java.util.Map; import java.util.OptionalInt; import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.function.Supplier; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.StringTag; public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { private final Spigot_v1_16_R1 parent; @@ -244,7 +232,11 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I Supplier saveTag = () -> { NBTTagCompound tag = new NBTTagCompound(); readEntityIntoTag(mcEntity, tag); - return (CompoundTag) toNative(tag); + + //add Id for AbstractChangeSet to work + CompoundTag natve = (CompoundTag) toNative(tag); + natve.getValue().put("Id", new StringTag(id)); + return natve; }; return new LazyBaseEntity(type, saveTag); } else { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index 40815ab67..f355cecea 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -20,6 +20,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -111,7 +112,7 @@ public interface IChunkExtent extends Extent { default Entity createEntity(Location location, BaseEntity entity) { final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); CompoundTag tag = entity.getNbtData(); - Map map = ReflectionUtils.getMap(tag.getValue()); + Map map = new HashMap<>(tag.getValue()); //do not modify original entity data map.put("Id", new StringTag(entity.getType().getName())); //Set pos @@ -147,8 +148,11 @@ public interface IChunkExtent extends Extent { map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits())); map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits())); + map.put("PersistentIDMSB", new LongTag(newuuid.getMostSignificantBits())); + map.put("PersistentIDLSB", new LongTag(newuuid.getLeastSignificantBits())); + chunk.setEntity(tag); - return null; + return new IChunkEntity(this, location, newuuid, entity); } @Override @@ -156,4 +160,50 @@ public interface IChunkExtent extends Extent { final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); chunk.removeEntity(uuid); } + + class IChunkEntity implements Entity { + + private final Extent extent; + private final Location location; + private final UUID uuid; + private final BaseEntity base; + + public IChunkEntity(Extent extent, Location location, UUID uuid, BaseEntity base) { + this.extent = extent; + this.location = location; + this.uuid = uuid; + this.base = base; + } + + @Override + public BaseEntity getState() { + return base; + } + + @Override + public boolean remove() { + extent.removeEntity(location.getBlockX(), location.getBlockY(), location.getBlockZ(), uuid); + return true; + } + + @Override + public T getFacet(Class cls) { + return null; + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public boolean setLocation(Location location) { + return false; + } + + @Override + public Extent getExtent() { + return extent; + } + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index eb44ba67e..f55c8651e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -90,19 +90,6 @@ public class ReflectionUtils { } private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(); - public static Map getMap(Map map) { - try { - Class clazz = map.getClass(); - if (clazz != UNMODIFIABLE_MAP) return map; - Field m = clazz.getDeclaredField("m"); - m.setAccessible(true); - return (Map) m.get(map); - } catch (Throwable e) { - e.printStackTrace(); - return map; - } - } - public static Object getHandle(Object wrapper) { final Method getHandle = makeMethod(wrapper.getClass(), "getHandle"); return callMethod(getHandle, wrapper); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index b097b9eca..0b38902da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -37,6 +37,8 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.entity.EntityTypes; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.jnbt.LongTag; +import java.util.UUID; /** * Copies entities provided to the function to the provided destination @@ -44,6 +46,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class ExtentEntityCopy implements EntityFunction { + private final Extent source; private final Extent destination; private final Vector3 from; private final Vector3 to; @@ -58,11 +61,13 @@ public class ExtentEntityCopy implements EntityFunction { * @param to the destination position * @param transform the transformation to apply to both position and orientation */ - public ExtentEntityCopy(Vector3 from, Extent destination, Vector3 to, Transform transform) { + public ExtentEntityCopy(Extent source, Vector3 from, Extent destination, Vector3 to, Transform transform) { + checkNotNull(source); checkNotNull(from); checkNotNull(destination); checkNotNull(to); checkNotNull(transform); + this.source = source; this.destination = destination; this.from = from; this.to = to; @@ -119,7 +124,18 @@ public class ExtentEntityCopy implements EntityFunction { // Remove if (isRemoving() && success) { - entity.remove(); + //todo remove from source with Extent i guess? im confused now + UUID uuid = null; + if (tag.containsKey("UUID")) { + int[] arr = tag.getIntArray("UUID"); + uuid = new UUID((long)arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long)arr[2] << 32 | (arr[3] & 0xFFFFFFFFL)); + } else if (tag.containsKey("UUIDMost")) { + uuid = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast")); + } else if (tag.containsKey("PersistentIDMSB")) { + uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB")); + } + if (uuid != null) + source.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid); } return success; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 5c8f188c4..55948f63e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -393,7 +393,7 @@ public class ForwardExtentCopy implements Operation { Operations.completeBlindly(blockCopy); if (!entities.isEmpty()) { - ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform); + ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform); entityCopy.setRemoving(removingEntities); List entities2 = Lists.newArrayList(source.getEntities(region)); entities2.removeIf(entity -> { From ae95ad8fe7522659256c2bed873773ae749a646f Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Wed, 29 Jul 2020 22:45:48 +0200 Subject: [PATCH 17/26] cleanup --- .../src/main/java/com/boydti/fawe/util/ReflectionUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index f55c8651e..8be037b13 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -14,7 +14,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Map; public class ReflectionUtils { @@ -88,8 +87,7 @@ public class ReflectionUtils { return list; } } - private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(); - + public static Object getHandle(Object wrapper) { final Method getHandle = makeMethod(wrapper.getClass(), "getHandle"); return callMethod(getHandle, wrapper); From 3c70cdc9fddbeba39d567850d59669f171365e65 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Wed, 29 Jul 2020 22:47:47 +0200 Subject: [PATCH 18/26] more cleanup --- .../com/sk89q/worldedit/function/entity/ExtentEntityCopy.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index 0b38902da..fda0e0103 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -37,7 +37,6 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.entity.EntityTypes; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.jnbt.LongTag; import java.util.UUID; /** @@ -124,7 +123,6 @@ public class ExtentEntityCopy implements EntityFunction { // Remove if (isRemoving() && success) { - //todo remove from source with Extent i guess? im confused now UUID uuid = null; if (tag.containsKey("UUID")) { int[] arr = tag.getIntArray("UUID"); From bf09d6922cb1894a395ea97c800bc4196e0f5df4 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Thu, 30 Jul 2020 14:19:04 +0200 Subject: [PATCH 19/26] fix //move -e --- .../beta/implementation/IChunkExtent.java | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java index f355cecea..a8a3621ca 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -1,11 +1,9 @@ package com.boydti.fawe.beta.implementation; import com.boydti.fawe.beta.IChunk; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.IntArrayTag; -import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.LongTag; import com.sk89q.jnbt.StringTag; @@ -111,39 +109,24 @@ public interface IChunkExtent extends Extent { @Override default Entity createEntity(Location location, BaseEntity entity) { final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); - CompoundTag tag = entity.getNbtData(); - Map map = new HashMap<>(tag.getValue()); //do not modify original entity data + Map map = new HashMap<>(entity.getNbtData().getValue()); //do not modify original entity data map.put("Id", new StringTag(entity.getType().getName())); //Set pos - ListTag pos = (ListTag) map.get("Pos"); - List posList; - if (pos != null) { - posList = ReflectionUtils.getList(pos.getValue()); - } else { - posList = new ArrayList<>(); - pos = new ListTag(DoubleTag.class, posList); - map.put("Pos", pos); - } - posList.set(0, new DoubleTag(location.getX())); - posList.set(1, new DoubleTag(location.getY())); - posList.set(2, new DoubleTag(location.getZ())); + List posList = new ArrayList<>(); + posList.add(new DoubleTag(location.getX())); + posList.add(new DoubleTag(location.getY())); + posList.add(new DoubleTag(location.getZ())); + map.put("Pos", new ListTag(DoubleTag.class, posList)); //set new uuid UUID newuuid = UUID.randomUUID(); - IntArrayTag uuid = (IntArrayTag) map.get("UUID"); - int[] uuidArray; - if (uuid != null) { - uuidArray = uuid.getValue(); - } else { - uuidArray = new int[4]; - uuid = new IntArrayTag(uuidArray); - map.put("UUID", uuid); - } + int[] uuidArray = new int[4]; uuidArray[0] = (int) (newuuid.getMostSignificantBits() >> 32); uuidArray[1] = (int) newuuid.getMostSignificantBits(); uuidArray[2] = (int) (newuuid.getLeastSignificantBits() >> 32); uuidArray[3] = (int) newuuid.getLeastSignificantBits(); + map.put("UUID", new IntArrayTag(uuidArray)); map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits())); map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits())); @@ -151,7 +134,7 @@ public interface IChunkExtent extends Extent { map.put("PersistentIDMSB", new LongTag(newuuid.getMostSignificantBits())); map.put("PersistentIDLSB", new LongTag(newuuid.getLeastSignificantBits())); - chunk.setEntity(tag); + chunk.setEntity(new CompoundTag(map)); return new IChunkEntity(this, location, newuuid, entity); } From 629a237fb51cf989ecf3709e1eafde96d6321515 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Mon, 3 Aug 2020 17:27:08 +0200 Subject: [PATCH 20/26] set forge uuid values --- .../src/main/java/com/sk89q/worldedit/internal/Constants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java index d074445fc..baa1cfd0b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java @@ -36,9 +36,9 @@ public final class Constants { static { NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList( -// "UUIDLeast", "UUIDMost", // Bukkit and Vanilla //UUID values need to be set manully to a new UUID + //"UUIDLeast", "UUIDMost", // Bukkit and Vanilla //UUID values need to be set manully to a new UUID "WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla - "PersistentIDMSB", "PersistentIDLSB" // Forge + //"PersistentIDMSB", "PersistentIDLSB" // Forge //UUID values need to be set manully to a new UUID )); } From 9b9534360136d69e2fd488fb58791066d0272b1f Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Mon, 3 Aug 2020 17:34:06 +0200 Subject: [PATCH 21/26] keep original constructor to not break plugin that use the api --- .../function/entity/ExtentEntityCopy.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index fda0e0103..04d179bdf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -60,6 +60,28 @@ public class ExtentEntityCopy implements EntityFunction { * @param to the destination position * @param transform the transformation to apply to both position and orientation */ + @Deprecated + public ExtentEntityCopy(Vector3 from, Extent destination, Vector3 to, Transform transform) { + checkNotNull(from); + checkNotNull(destination); + checkNotNull(to); + checkNotNull(transform); + this.source = null; + this.destination = destination; + this.from = from; + this.to = to; + this.transform = transform; + } + + /** + * Create a new instance. + * + * @param source the source {@code Extent} + * @param from the from position + * @param destination the destination {@code Extent} + * @param to the destination position + * @param transform the transformation to apply to both position and orientation + */ public ExtentEntityCopy(Extent source, Vector3 from, Extent destination, Vector3 to, Transform transform) { checkNotNull(source); checkNotNull(from); @@ -132,8 +154,12 @@ public class ExtentEntityCopy implements EntityFunction { } else if (tag.containsKey("PersistentIDMSB")) { uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB")); } - if (uuid != null) - source.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid); + if (uuid != null) { + Extent src = source != null ? source : entity.getExtent(); + if (src != null) { + src.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid); + } + } } return success; From 1097ac78898b39b55d02e036008cad8b1966e021 Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Mon, 3 Aug 2020 17:35:53 +0200 Subject: [PATCH 22/26] remove entity properly --- .../sk89q/worldedit/function/entity/ExtentEntityCopy.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index 04d179bdf..4ed4a6bc9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -155,9 +155,10 @@ public class ExtentEntityCopy implements EntityFunction { uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB")); } if (uuid != null) { - Extent src = source != null ? source : entity.getExtent(); - if (src != null) { - src.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid); + if (source != null) { + source.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid); + } else { + entity.remove(); } } } From b582d3f70d2b87c24f9826e8f1b9601cddde1b9a Mon Sep 17 00:00:00 2001 From: wea_ondara Date: Mon, 3 Aug 2020 17:43:36 +0200 Subject: [PATCH 23/26] fix compile error --- .../src/main/java/com/sk89q/worldedit/internal/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java index baa1cfd0b..6d7e847b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/Constants.java @@ -37,7 +37,7 @@ public final class Constants { static { NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList( //"UUIDLeast", "UUIDMost", // Bukkit and Vanilla //UUID values need to be set manully to a new UUID - "WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla + "WorldUUIDLeast", "WorldUUIDMost" // Bukkit and Vanilla //"PersistentIDMSB", "PersistentIDLSB" // Forge //UUID values need to be set manully to a new UUID )); } From e74cb33847586f516f745f967640129d5382c903 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sun, 16 Aug 2020 17:05:09 +0200 Subject: [PATCH 24/26] comment biome change output back in --- .../sk89q/worldedit/function/operation/ForwardExtentCopy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 55948f63e..1e1255b1e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -424,8 +424,8 @@ public class ForwardExtentCopy implements Operation { return ImmutableList.of( TranslatableComponent.of("worldedit.operation.affected.block", TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), -// TranslatableComponent.of("worldedit.operation.affected.biome", -// TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), + TranslatableComponent.of("worldedit.operation.affected.biome", + TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), TranslatableComponent.of("worldedit.operation.affected.entity", TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) ); From 7f0fd182bb4c10e02a0db8465c519e5be7d4ef2c Mon Sep 17 00:00:00 2001 From: aurorasmiles <21148213+aurorasmiles@users.noreply.github.com> Date: Wed, 19 Aug 2020 11:06:04 +0200 Subject: [PATCH 25/26] Add comment regarding createentitiy --- .../src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index ce615b9fd..3ae9b4dbc 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -123,6 +123,8 @@ public class BukkitWorld extends AbstractWorld { return list; } + //createEntity was moved to IChunkExtent to prevent issues with Async Entitiy Add. + /** * Get the world handle. * From 947871281f87c0001239cfe78a642322f2361a8b Mon Sep 17 00:00:00 2001 From: aurorasmiles <21148213+aurorasmiles@users.noreply.github.com> Date: Wed, 19 Aug 2020 11:08:59 +0200 Subject: [PATCH 26/26] Fix styling issues --- .../src/main/java/com/sk89q/worldedit/EditSession.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 73216f950..c574eab95 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -3100,7 +3100,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } @Override - public Entity createEntity(Location location, BaseEntity entity){ + public Entity createEntity(Location location, BaseEntity entity) { try { return this.getExtent().createEntity(location, entity); } catch (WorldEditException e) { @@ -3109,8 +3109,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } @Override - public void removeEntity(int x, int y, int z, UUID uuid) - { + public void removeEntity(int x, int y, int z, UUID uuid) { try { this.getExtent().removeEntity(x, y, z, uuid); } catch (WorldEditException e) {