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 68f15a369..da9874e40 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -3,6 +3,7 @@ package com.boydti.fawe; import static com.google.common.base.Preconditions.checkNotNull; import static org.slf4j.LoggerFactory.getLogger; +import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.beta.Trimable; import com.boydti.fawe.beta.implementation.queue.Pool; import com.boydti.fawe.beta.implementation.queue.QueuePool; @@ -42,6 +43,7 @@ import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -52,6 +54,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.function.Supplier; +import org.jetbrains.annotations.NotNull; public enum FaweCache implements Trimable { IMP @@ -64,7 +67,7 @@ public enum FaweCache implements Trimable { public final char[] EMPTY_CHAR_4096 = new char[4096]; - private final IdentityHashMap, Pool> REGISTERED_POOLS = new IdentityHashMap<>(); + private final IdentityHashMap, Pool> REGISTERED_POOLS = new IdentityHashMap<>(); /* Palette buffers / cache @@ -89,15 +92,15 @@ public enum FaweCache implements Trimable { MUTABLE_BLOCKVECTOR3.clean(); SECTION_BITS_TO_CHAR.clean(); } - for (Map.Entry, Pool> entry : REGISTERED_POOLS.entrySet()) { - Pool pool = entry.getValue(); + for (Entry, Pool> entry : REGISTERED_POOLS.entrySet()) { + Pool pool = entry.getValue(); pool.clear(); } return false; } - public synchronized Pool registerPool(Class clazz, Supplier cache, boolean buffer) { + public synchronized Pool registerPool(Class clazz, Supplier cache, boolean buffer) { checkNotNull(cache); Pool pool; if (buffer) { @@ -105,7 +108,7 @@ public enum FaweCache implements Trimable { } else { pool = cache::get; } - Pool previous = REGISTERED_POOLS.putIfAbsent(clazz, pool); + Pool previous = REGISTERED_POOLS.putIfAbsent(clazz, pool); if (previous != null) { throw new IllegalStateException("Previous key"); } @@ -115,7 +118,7 @@ public enum FaweCache implements Trimable { public LoadingCache createCache(Supplier withInitial) { return CacheBuilder.newBuilder().build(new CacheLoader() { @Override - public V load(T key) { + public V load(@NotNull T key) { return withInitial.get(); } }); @@ -124,7 +127,7 @@ public enum FaweCache implements Trimable { public LoadingCache createCache(Function withInitial) { return CacheBuilder.newBuilder().build(new CacheLoader() { @Override - public V load(T key) { + public V load(@NotNull T key) { return withInitial.apply(key); } }); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java deleted file mode 100644 index a6a621b45..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.boydti.fawe.beta; - -import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; -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.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import javax.annotation.Nullable; - -/** - * Delegate for IChunk - * - * @param parent class - */ -public interface IDelegateChunk extends IQueueChunk { - - U getParent(); - - @Override - default IQueueChunk getRoot() { - IQueueChunk root = getParent(); - while (root instanceof IDelegateChunk) { - root = ((IDelegateChunk) root).getParent(); - } - return root; - } - - @Override - default > T call(IChunkSet set, Runnable finalize) { - return getParent().call(set, finalize); - } - - @Override - default CompoundTag getTile(int x, int y, int z) { - return getParent().getTile(x, y, z); - } - - @Override - default boolean hasSection(int layer) { - return getParent().hasSection(layer); - } - -// @Override -// default void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { -// getParent().flood(flood, mask, block); -// } - - @Override - default boolean setTile(int x, int y, int z, CompoundTag tag) { - return getParent().setTile(x, y, z, tag); - } - - @Override - default boolean setBiome(int x, int y, int z, BiomeType biome) { - return getParent().setBiome(x, y, z, biome); - } - - @Override - default > boolean setBlock(int x, int y, int z, T holder) { - return getParent().setBlock(x, y, z, holder); - } - - @Override - default BiomeType getBiomeType(int x, int y, int z) { - return getParent().getBiomeType(x, y, z); - } - - @Override - default BlockState getBlock(int x, int y, int z) { - return getParent().getBlock(x, y, z); - } - - @Override - default BaseBlock getFullBlock(int x, int y, int z) { - return getParent().getFullBlock(x, y, z); - } - - @Override - default void init(IQueueExtent extent, int chunkX, int chunkZ) { - getParent().init(extent, chunkX, chunkZ); - } - - @Override - default int getX() { - return getParent().getX(); - } - - @Override - default int getZ() { - return getParent().getZ(); - } - - - @Override - default boolean trim(boolean aggressive) { - return getParent().trim(aggressive); - } - - @Override - default Future call() { - return getParent().call(); - } - - @Override - default void join() throws ExecutionException, InterruptedException { - getParent().join(); - } - - @Override - default void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region, boolean full) { - getParent().filterBlocks(filter, block, region, full); - } - - @Override - default boolean isEmpty() { - return getParent().isEmpty(); - } - - @Override - default Map getTiles() { - return getParent().getTiles(); - } - - @Override - default Set getEntities() { - return getParent().getEntities(); - } - - @Override - default CompoundTag getEntity(UUID uuid) { - return getParent().getEntity(uuid); - } - - @Override - default char[] load(int layer) { - return getParent().load(layer); - } - - @Override - default void setBlocks(int layer, char[] data) { - getParent().setBlocks(layer, data); - } - - @Override - default void setEntity(CompoundTag tag) { - getParent().setEntity(tag); - } - - @Override - default void removeEntity(UUID uuid) { - getParent().removeEntity(uuid); - } - - @Override - default Set getEntityRemoves() { - return getParent().getEntityRemoves(); - } - - @Override - default BiomeType[] getBiomes() { - return getParent().getBiomes(); - } - - @Override - default boolean hasBiomes() { - return getParent().hasBiomes(); - } - - default T findParent(Class clazz) { - IChunk root = getParent(); - if (clazz.isAssignableFrom(root.getClass())) { - return (T) root; - } - while (root instanceof IDelegateChunk) { - root = ((IDelegateChunk) root).getParent(); - if (clazz.isAssignableFrom(root.getClass())) { - return (T) root; - } - } - return null; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java index 20c2554aa..39947092c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java @@ -25,7 +25,7 @@ import java.util.stream.IntStream; import org.jetbrains.annotations.Range; public class CharSetBlocks extends CharBlocks implements IChunkSet { - private static Pool POOL = FaweCache.IMP.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL); + private static final Pool POOL = FaweCache.IMP.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL); public static CharSetBlocks newInstance() { return POOL.poll(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java deleted file mode 100644 index 18c21ad58..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.boydti.fawe.beta.implementation.blocks; - -import com.boydti.fawe.beta.IChunkSet; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import javax.annotation.Nullable; - -public interface DelegateChunkSet extends IChunkSet { - - IChunkSet getParent(); - - @Override - default boolean setBiome(int x, int y, int z, BiomeType biome) { - return getParent().setBiome(x, y, z, biome); - } - - @Override - default > boolean setBlock(int x, int y, int z, T holder) { - return getParent().setBlock(x, y, z, holder); - } - - @Override - default boolean isEmpty() { - return getParent().isEmpty(); - } - - @Override - default boolean setTile(int x, int y, int z, CompoundTag tile) { - return getParent().setTile(x, y, z, tile); - } - - @Override - default void setEntity(CompoundTag tag) { - getParent().setEntity(tag); - } - - @Override - default void removeEntity(UUID uuid) { - getParent().removeEntity(uuid); - } - - @Override - default BlockState getBlock(int x, int y, int z) { - return getParent().getBlock(x, y, z); - } - - @Override - default char[] load(int layer) { - return getParent().load(layer); - } - - @Override - default BiomeType[] getBiomes() { - return getParent().getBiomes(); - } - - @Override - default Map getTiles() { - return getParent().getTiles(); - } - - @Override - default Set getEntities() { - return getParent().getEntities(); - } - - @Override - default Set getEntityRemoves() { - return getParent().getEntityRemoves(); - } - - @Override - default IChunkSet reset() { - IChunkSet parent = getParent(); - parent.reset(); - return parent; - } - - @Override - @Nullable - default Operation commit() { - return getParent().commit(); - } - - @Override - default boolean hasSection(int layer) { - return getParent().hasSection(layer); - } - - @Override - default boolean trim(boolean aggressive) { - return getParent().trim(aggressive); - } - - @Override - default > boolean setBlock(BlockVector3 position, T block) - throws WorldEditException { - return getParent().setBlock(position, block); - } - - @Override - default boolean setBiome(BlockVector2 position, BiomeType biome) { - return getParent().setBiome(position, biome); - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java index aa5d3e2b5..443c310ff 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java @@ -30,7 +30,7 @@ import org.jetbrains.annotations.Range; */ public class ChunkHolder> implements IQueueChunk { - private static Pool POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); + private static final Pool POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); public static ChunkHolder newInstance() { return POOL.poll(); @@ -39,11 +39,11 @@ public class ChunkHolder> implements IQueueChunk { private IChunkGet chunkExisting; // The existing chunk (e.g. a clipboard, or the world, before changes) private IChunkSet chunkSet; // The blocks to be set to the chunkExisting private IBlockDelegate delegate; // delegate handles the abstraction of the chunk layers - private IQueueExtent extent; // the parent queue extent which has this chunk + private IQueueExtent extent; // the parent queue extent which has this chunk private int chunkX; private int chunkZ; - public ChunkHolder() { + private ChunkHolder() { this.delegate = NULL; } @@ -346,8 +346,7 @@ public class ChunkHolder> implements IQueueChunk { } /** - * Get or create the existing part of this chunk - * @return + * Get or create the existing part of this chunk. */ public final IChunkGet getOrCreateGet() { if (chunkExisting == null) { @@ -357,8 +356,7 @@ public class ChunkHolder> implements IQueueChunk { } /** - * Get or create the settable part of this chunk - * @return + * Get or create the settable part of this chunk. */ public final IChunkSet getOrCreateSet() { if (chunkSet == null) { @@ -371,7 +369,6 @@ public class ChunkHolder> implements IQueueChunk { * Create a wrapped set object * - The purpose of wrapping is to allow different extents to intercept / alter behavior * - e.g., caching, optimizations, filtering - * @return */ private IChunkSet newWrappedSet() { return extent.getCachedSet(chunkX, chunkZ); @@ -381,7 +378,6 @@ public class ChunkHolder> implements IQueueChunk { * Create a wrapped get object * - The purpose of wrapping is to allow different extents to intercept / alter behavior * - e.g., caching, optimizations, filtering - * @return */ private IChunkGet newWrappedGet() { return extent.getCachedGet(chunkX, chunkZ); @@ -423,9 +419,8 @@ public class ChunkHolder> implements IQueueChunk { /** * Get the extent this chunk is in - * @return */ - public IQueueExtent getExtent() { + public IQueueExtent getExtent() { return extent; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java deleted file mode 100644 index 61f26467a..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.boydti.fawe.beta.implementation.chunk; - -import com.boydti.fawe.beta.IChunk; -import com.boydti.fawe.beta.IDelegateChunk; -import com.boydti.fawe.beta.IQueueChunk; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.world.biome.BiomeType; - -import java.util.Set; -import java.util.UUID; - -/** - * Implementation of IDelegateChunk - */ -public class DelegateChunk implements IDelegateChunk { - - private T parent; - - public DelegateChunk(final T parent) { - this.parent = parent; - } - - @Override - public final T getParent() { - return parent; - } - - public final void setParent(final T parent) { - this.parent = parent; - } -}