From 534c81f7d830accb9ec65ba1e4e647572d4bbcb4 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 18 Feb 2020 14:27:05 -0500 Subject: [PATCH] Removed redundant code and modifications to NullExtent --- .../main/java/com/boydti/fawe/FaweAPI.java | 3 +- .../main/java/com/boydti/fawe/FaweCache.java | 2 - .../object/changeset/AbstractChangeSet.java | 2 +- .../clipboard/DiskOptimizedClipboard.java | 16 +- .../object/clipboard/LinearClipboard.java | 9 +- .../object/clipboard/SimpleClipboard.java | 4 +- .../collection/BlockVector3ChunkMap.java | 7 +- .../collection/CleanableThreadLocal.java | 4 +- .../fawe/object/extent/HeightBoundExtent.java | 10 +- .../boydti/fawe/object/extent/NullExtent.java | 149 +++++++++--------- .../java/com/boydti/fawe/util/WEManager.java | 6 +- 11 files changed, 91 insertions(+), 121 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java index f5508c3cd..2d271d472 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -22,6 +22,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; @@ -222,7 +223,7 @@ public class FaweAPI { * @param reason * @see EditSession#getRegionExtent() To get the FaweExtent for an EditSession */ - public static void cancelEdit(Extent extent, Component reason) { + public static void cancelEdit(AbstractDelegateExtent extent, Component reason) { try { WEManager.IMP.cancelEdit(extent, new FaweException(reason)); } catch (WorldEditException ignore) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java index ade7c3887..a8e7ee656 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -13,7 +13,6 @@ import com.boydti.fawe.object.collection.VariableThreadLocal; import com.boydti.fawe.object.exception.FaweBlockBagException; import com.boydti.fawe.object.exception.FaweChunkLoadException; import com.boydti.fawe.object.exception.FaweException; -import com.boydti.fawe.util.IOUtil; import com.boydti.fawe.util.MathMan; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -36,7 +35,6 @@ import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.block.BlockTypesCache; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java index d2ce6f254..e4d32198e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java @@ -41,7 +41,7 @@ import java.util.UUID; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; -public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor, Closeable { +public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { private World world; private final String worldName; 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 a3523e1df..16d2b5e50 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 @@ -21,7 +21,6 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; -import java.io.Closeable; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; @@ -36,7 +35,6 @@ import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; @@ -47,7 +45,7 @@ import javax.annotation.Nullable; * - Uses an auto closable RandomAccessFile for getting / setting id / data * - I don't know how to reduce nbt / entities to O(2) complexity, so it is stored in memory. */ -public class DiskOptimizedClipboard extends LinearClipboard implements Closeable { +public class DiskOptimizedClipboard extends LinearClipboard { private static int HEADER_SIZE = 14; @@ -427,16 +425,4 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable this.entities.remove(entity); } - @Override - public void removeEntity(int x, int y, int z, UUID uuid) { - Iterator iter = this.entities.iterator(); - while (iter.hasNext()) { - BlockArrayClipboard.ClipboardEntity entity = iter.next(); - UUID entUUID = entity.getState().getNbtData().getUUID(); - if (uuid.equals(entUUID)) { - iter.remove(); - return; - } - } - } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java index 5d87eccd3..676187c34 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java @@ -5,9 +5,7 @@ import com.boydti.fawe.jnbt.streamer.IntValueReader; import com.google.common.collect.ForwardingIterator; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard.ClipboardEntity; -import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.visitor.Order; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -16,8 +14,6 @@ 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.io.Closeable; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -28,7 +24,7 @@ import org.jetbrains.annotations.NotNull; * Best used when clipboard selections are small, or using legacy formats * (Small being < Integer.MAX_VALUE/BLOCK_SIZE_BYTES blocks) */ -public abstract class LinearClipboard extends SimpleClipboard implements Clipboard, Closeable { +public abstract class LinearClipboard extends SimpleClipboard { protected final HashSet entities; @@ -56,9 +52,6 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa public abstract Collection getTileEntities(); - @Override - public void close() {} - public void flush() {} @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java index b614e5bef..df4f7de5b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/SimpleClipboard.java @@ -5,9 +5,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; -import java.io.Closeable; - -public abstract class SimpleClipboard implements Clipboard, Closeable { +public abstract class SimpleClipboard implements Clipboard { private final BlockVector3 size; private final int area; private final int volume; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVector3ChunkMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVector3ChunkMap.java index 60317307e..b3bca51d4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVector3ChunkMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVector3ChunkMap.java @@ -4,14 +4,9 @@ import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; import java.util.Map; -import java.util.Set; -public class BlockVector3ChunkMap implements Map, IAdaptedMap { +public class BlockVector3ChunkMap implements IAdaptedMap { private final Short2ObjectArrayMap map = new Short2ObjectArrayMap<>(); @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java index 87aef5b8d..8e0c15b68 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java @@ -87,7 +87,7 @@ public class CleanableThreadLocal extends ThreadLocal implements Closeable return list; } - public static void iterate(ThreadLocal instance, Consumer withMap) { + public static void iterate(ThreadLocal instance, Consumer withMap) { try { Thread[] threads = MainUtil.getThreads(); Field tl = Thread.class.getDeclaredField("threadLocals"); @@ -105,7 +105,7 @@ public class CleanableThreadLocal extends ThreadLocal implements Closeable } } - public static void clean(ThreadLocal instance) { + public static void clean(ThreadLocal instance) { iterate(instance, new Consumer() { Method methodRemove; @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java index 580b70109..87b467e16 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java @@ -1,24 +1,16 @@ package com.boydti.fawe.object.extent; -import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.IBatchProcessor; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.RegionWrapper; -import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -public class HeightBoundExtent extends FaweRegionExtent implements IBatchProcessor { +public class HeightBoundExtent extends FaweRegionExtent { private final int min, max; private int lastY = -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index e796c2b20..6146faac8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -5,6 +5,7 @@ import com.boydti.fawe.beta.IBatchProcessor; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; +import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.util.formatting.text.Component; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.exception.FaweException; @@ -26,11 +27,14 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Set; import javax.annotation.Nullable; @@ -57,70 +61,93 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor { this(new com.sk89q.worldedit.extent.NullExtent(), FaweCache.MANUAL); } + @Override + public BlockVector3 getMinimumPoint() { + return BlockVector3.ZERO; + } + + @Override + public BlockVector3 getMaximumPoint() { + return BlockVector3.ZERO; + } + + @Override + public List getEntities(Region region) { + throw reason; + } + + @Override + public List getEntities() { + return Collections.emptyList(); + } + + @Nullable + @Override + public Entity createEntity(Location arg0, BaseEntity arg1) { + return null; + } + + @Override + public BlockState getBlock(BlockVector3 position) { + return BlockTypes.AIR.getDefaultState(); + } + + @Override + public BlockState getBlock(int x, int y, int z) { + return BlockTypes.AIR.getDefaultState(); + } + + @Override + public BaseBlock getFullBlock(BlockVector3 position) { + return getBlock(position).toBaseBlock(); + } + + @Override + public BaseBlock getFullBlock(int x, int y, int z) { + return getBlock(x, y, z).toBaseBlock(); + } + + @Override + public BiomeType getBiome(BlockVector2 position) { + return BiomeTypes.THE_VOID; + } + + @Override + public BiomeType getBiomeType(int x, int y, int z) { + return BiomeTypes.THE_VOID; + } + + @Override + public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { + return false; + } + + @Override + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { + return false; + } + @Override public ResettableExtent setExtent(Extent extent) { return this; } @Override - public BiomeType getBiome(BlockVector2 arg0) { - throw reason; - } - - @Override - public BiomeType getBiomeType(int x, int y, int z) { - throw reason; + public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { + return false; } @Override - public BlockState getBlock(BlockVector3 arg0) { - throw reason; - } - - @Override - public BlockState getBlock(int x, int y, int z) { - throw reason; - } - - @Override - public BaseBlock getFullBlock(BlockVector3 position) { - throw reason; - } - - @Override - public BaseBlock getFullBlock(int x, int y, int z) { - if(reason != null) { - throw reason; - } - return null; - } - - @Override - public boolean setBiome(BlockVector2 arg0, BiomeType arg1) { - throw reason; + public boolean setBiome(BlockVector2 position, BiomeType biome) { + return false; } @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { - throw reason; - } - - @Override - public > boolean setBlock(BlockVector3 arg0, B arg1) throws WorldEditException { - throw reason; - } - - @Override - public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { - throw reason; - } - - @Nullable - @Override - public Entity createEntity(Location arg0, BaseEntity arg1) { - throw reason; + return false; } - + @Override public boolean isQueueEnabled() { throw reason; @@ -156,26 +183,6 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor { throw reason; } - @Override - public List getEntities() { - throw reason; - } - - @Override - public List getEntities(Region arg0) { - throw reason; - } - - @Override - public BlockVector3 getMaximumPoint() { - return BlockVector3.ZERO; - } - - @Override - public BlockVector3 getMinimumPoint() { - return BlockVector3.ZERO; - } - @Override public boolean contains(int x, int z) { throw reason; @@ -194,7 +201,7 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor { @Nullable @Override public Operation commit() { - throw reason; + return null; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java b/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java index 82f01dcfc..a7b40ba44 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -26,11 +26,11 @@ public class WEManager { public final ArrayDeque managers = new ArrayDeque<>(); - public void cancelEditSafe(Extent parent, FaweException reason) throws FaweException { + public void cancelEditSafe(AbstractDelegateExtent parent, FaweException reason) throws FaweException { try { final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); - Object currentExtent = field.get(parent); + Extent currentExtent = parent.getExtent(); if (!(currentExtent instanceof NullExtent)) { field.set(parent, new NullExtent((Extent) field.get(parent), reason)); } @@ -40,7 +40,7 @@ public class WEManager { throw reason; } - public void cancelEdit(Extent parent, FaweException reason) throws WorldEditException { + public void cancelEdit(AbstractDelegateExtent parent, FaweException reason) throws WorldEditException { cancelEditSafe(parent, reason); }