From aac02ceea167a47ec8fd449c60a972af2bf67080 Mon Sep 17 00:00:00 2001 From: Aurora Date: Thu, 25 Jun 2020 22:13:34 +0200 Subject: [PATCH] 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(); }