From 2d5a8ce573cb43ffaf2aae132c300a9150402966 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 14 Jan 2020 19:44:09 -0500 Subject: [PATCH] Cleaned up a lot of code and introduced Kotlin to the project --- worldedit-core/build.gradle.kts | 12 +++ .../src/main/java/com/boydti/fawe/Fawe.java | 12 +-- .../main/java/com/boydti/fawe/FaweCache.java | 49 ++--------- .../com/boydti/fawe/beta/IBatchProcessor.java | 2 + .../java/com/boydti/fawe/beta/IBlocks.java | 10 +-- .../java/com/boydti/fawe/beta/IChunk.java | 13 ++- .../java/com/boydti/fawe/beta/IChunkSet.java | 2 +- .../com/boydti/fawe/beta/IDelegateChunk.java | 4 +- .../com/boydti/fawe/beta/IDelegateFilter.java | 4 +- .../fawe/beta/IDelegateQueueExtent.java | 5 +- .../com/boydti/fawe/beta/IQueueChunk.java | 1 - .../beta/implementation/IChunkExtent.java | 2 +- .../implementation/blocks/BitSetBlocks.java | 2 +- .../implementation/blocks/CharBlocks.java | 1 + .../implementation/blocks/CharGetBlocks.java | 5 -- .../implementation/blocks/CharSetBlocks.java | 18 ++-- .../blocks/DelegateChunkSet.java | 2 +- .../implementation/blocks/NullChunkGet.java | 83 ------------------- .../implementation/blocks/NullChunkGet.kt | 68 +++++++++++++++ .../beta/implementation/cache/ChunkCache.java | 34 ++++---- .../cache/preloader/AsyncPreloader.java | 6 +- .../implementation/chunk/ChunkHolder.java | 25 +++--- .../implementation/chunk/FinalizedChunk.java | 4 +- .../beta/implementation/chunk/NullChunk.java | 2 +- .../filter/block/DelegateFilterBlock.java | 1 - .../processors/EmptyBatchProcessor.java | 26 ------ .../processors/EmptyBatchProcessor.kt | 22 +++++ .../processors/LimitExtent.java | 1 - .../processors/NullProcessor.java | 21 ----- .../processors/NullProcessor.kt | 19 +++++ .../fawe/beta/implementation/queue/Pool.java | 10 +++ .../beta/implementation/queue/QueuePool.java | 27 ++++++ .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 5 +- .../clipboard/CPUOptimizedClipboard.java | 3 - .../object/clipboard/DelegateClipboard.java | 1 - .../clipboard/DiskOptimizedClipboard.java | 17 +--- .../fawe/object/clipboard/EmptyClipboard.java | 2 +- .../object/clipboard/LinearClipboard.java | 21 +++++ .../clipboard/MemoryOptimizedClipboard.java | 15 ---- .../collection/CleanableThreadLocal.java | 2 +- .../boydti/fawe/object/mask/AngleMask.java | 3 - .../boydti/fawe/util/task/TaskBuilder.java | 6 +- .../com/sk89q/worldedit/extent/Extent.java | 2 +- .../sk89q/worldedit/extent/OutputExtent.java | 2 +- .../extent/clipboard/BlockArrayClipboard.java | 1 - .../worldedit/regions/EllipsoidRegion.java | 1 + .../com/sk89q/worldedit/regions/Region.java | 1 + 47 files changed, 268 insertions(+), 307 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.kt delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.kt create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueuePool.java diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index df64fd3c4..a58e758eb 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -2,6 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.plugins.ide.idea.model.IdeaModel import com.mendhak.gradlecrowdin.DownloadTranslationsTask import com.mendhak.gradlecrowdin.UploadSourceFileTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("java-library") @@ -9,10 +10,12 @@ plugins { id("net.ltgt.apt-idea") id("antlr") id("com.mendhak.gradlecrowdin") + kotlin("jvm") version "1.3.41" } repositories { maven { url = uri("http://ci.athion.net/job/PlotSquared-breaking/ws/mvn/") } + mavenCentral() } @@ -55,6 +58,7 @@ dependencies { "compile"("com.github.intellectualsites.plotsquared:PlotSquared-API:latest") { isTransitive = false } + implementation(kotlin("stdlib-jdk8")) } tasks.withType().configureEach { @@ -132,3 +136,11 @@ if (project.hasProperty(crowdinApiKey)) { dependsOn("crowdinDownload") } } +val compileKotlin: KotlinCompile by tasks +compileKotlin.kotlinOptions { + jvmTarget = "1.8" +} +val compileTestKotlin: KotlinCompile by tasks +compileTestKotlin.kotlinOptions { + jvmTarget = "1.8" +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index 492c2362a..782d798a6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -284,16 +284,6 @@ public class Fawe { public void setupConfigs() { MainUtil.copyFile(MainUtil.getJarFile(), "lang/strings.json", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "de/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "ru/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "ru/commands.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "tr/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "es/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "es/commands.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "nl/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "fr/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "cn/message.yml", null); -// MainUtil.copyFile(MainUtil.getJarFile(), "it/message.yml", null); // Setting up config.yml File file = new File(this.IMP.getDirectory(), "config.yml"); Settings.IMP.PLATFORM = IMP.getPlatform().replace("\"", ""); @@ -305,7 +295,7 @@ public class Fawe { br.close(); this.version = FaweVersion.tryParse(versionString, commitString, dateString); Settings.IMP.DATE = new Date(100 + version.year, version.month, version.day).toGMTString(); - Settings.IMP.BUILD = "https://ci.athion.net/job/FastAsyncWorldEdit-commanding-pipeline/" + version.build; + Settings.IMP.BUILD = "https://ci.athion.net/job/FastAsyncWorldEdit-1.15/" + version.build; Settings.IMP.COMMIT = "https://github.com/IntellectualSites/FastAsyncWorldEdit-1.13/commit/" + Integer.toHexString(version.hash); } catch (Throwable ignore) {} try { 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 694ad2959..aee4d4285 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -4,6 +4,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.slf4j.LoggerFactory.getLogger; import com.boydti.fawe.beta.Trimable; +import com.boydti.fawe.beta.implementation.queue.Pool; +import com.boydti.fawe.beta.implementation.queue.QueuePool; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.collection.BitArray4096; import com.boydti.fawe.object.collection.CleanableThreadLocal; @@ -65,43 +67,8 @@ public enum FaweCache implements Trimable { public final char[] EMPTY_CHAR_4096 = new char[4096]; - private final IdentityHashMap REGISTERED_SINGLETONS = new IdentityHashMap<>(); - private final IdentityHashMap REGISTERED_POOLS = new IdentityHashMap<>(); - - public interface Pool { - T poll(); - default boolean offer(T recycle) { - return false; - } - default void clear() {} - } - - public class QueuePool extends ConcurrentLinkedQueue implements Pool { - private final Supplier supplier; - - public QueuePool(Supplier supplier) { - this.supplier = supplier; - } - - @Override - public boolean offer(T t) { - return super.offer(t); - } - - @Override - public T poll() { - T result = super.poll(); - if (result == null) { - return supplier.get(); - } - return result; - } - - @Override - public void clear() { - if (!isEmpty()) super.clear(); - } - } + private final IdentityHashMap, CleanableThreadLocal> REGISTERED_SINGLETONS = new IdentityHashMap<>(); + private final IdentityHashMap, Pool> REGISTERED_POOLS = new IdentityHashMap<>(); /* Palette buffers / cache @@ -125,11 +92,11 @@ public enum FaweCache implements Trimable { MUTABLE_VECTOR3.clean(); MUTABLE_BLOCKVECTOR3.clean(); SECTION_BITS_TO_CHAR.clean(); - for (Map.Entry entry : REGISTERED_SINGLETONS.entrySet()) { + for (Map.Entry, CleanableThreadLocal> entry : REGISTERED_SINGLETONS.entrySet()) { entry.getValue().clean(); } } - for (Map.Entry entry : REGISTERED_POOLS.entrySet()) { + for (Map.Entry, Pool> entry : REGISTERED_POOLS.entrySet()) { Pool pool = entry.getValue(); pool.clear(); } @@ -269,7 +236,7 @@ public enum FaweCache implements Trimable { /** * Holds data for a palette used in a chunk section */ - public final class Palette { + public static final class Palette { public int bitsPerEntry; public int paletteToBlockLength; @@ -493,7 +460,7 @@ public enum FaweCache implements Trimable { System.out.println("Invalid nbt: " + value); return null; } else { - Class clazz = value.getClass(); + Class clazz = value.getClass(); if (clazz.getName().startsWith("com.intellectualcrafters.jnbt")) { try { if (clazz.getName().equals("com.intellectualcrafters.jnbt.EndTag")) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java index 84f19d8f9..7f913b5d1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java @@ -10,6 +10,7 @@ import com.sk89q.worldedit.math.BlockVector3; import java.util.Map; import java.util.Set; import java.util.function.Function; +import org.jetbrains.annotations.Nullable; public interface IBatchProcessor { /** @@ -30,6 +31,7 @@ public interface IBatchProcessor { * @param child * @return */ + @Nullable Extent construct(Extent child); /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java index 79fb0bc08..b175b62d3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java @@ -14,6 +14,7 @@ import com.sk89q.worldedit.world.registry.BlockRegistry; import java.io.IOException; import java.util.Map; import java.util.Set; +import java.util.stream.IntStream; /** * Shared interface for IGetBlocks and ISetBlocks @@ -35,13 +36,8 @@ public interface IBlocks extends Trimable { BiomeType getBiomeType(int x, int y, int z); default int getBitMask() { - int mask = 0; - for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) { - if (hasSection(layer)) { - mask += (1 << layer); - } - } - return mask; + return IntStream.range(0, FaweCache.IMP.CHUNK_LAYERS).filter(this::hasSection) + .map(layer -> (1 << layer)).sum(); } IBlocks reset(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java index 00a616ac8..58921adc3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java @@ -8,12 +8,14 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import javax.annotation.Nullable; +import org.jetbrains.annotations.Range; /** * Represents a chunk in the queue {@link IQueueExtent} Used for getting and setting blocks / biomes * / entities */ public interface IChunk extends Trimable, IChunkGet, IChunkSet { + /** * Initialize at the location * (allows for reuse) @@ -22,17 +24,20 @@ public interface IChunk extends Trimable, IChunkGet, IChunkSet { * @param x * @param z */ - default void init(IQueueExtent extent, int x, int z) {} + default void init(IQueueExtent extent, int x, int z) {} + /** * Get chunkX - * @return + * @return the x coordinate of the chunk */ + @Range(from = 0, to = 15) int getX(); /** * Get chunkZ - * @return + * @return the z coordinate of the chunk */ + @Range(from = 0, to = 15) int getZ(); /** @@ -78,7 +83,7 @@ public interface IChunk extends Trimable, IChunkGet, IChunkSet { boolean setTile(int x, int y, int z, CompoundTag tag); @Override - boolean setBlock(int x, int y, int z, BlockStateHolder block); + > boolean setBlock(int x, int y, int z, T block); @Override BiomeType getBiomeType(int x, int y, int z); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java index f5993b2ce..81f8f3abc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java @@ -21,7 +21,7 @@ public interface IChunkSet extends IBlocks, OutputExtent { boolean setBiome(int x, int y, int z, BiomeType biome); @Override - boolean setBlock(int x, int y, int z, BlockStateHolder holder); + > boolean setBlock(int x, int y, int z, T holder); void setBlocks(int layer, char[] data); 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 index 9838c5fa4..a6a621b45 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java @@ -65,7 +65,7 @@ public interface IDelegateChunk extends IQueueChunk { } @Override - default boolean setBlock(int x, int y, int z, BlockStateHolder holder) { + default > boolean setBlock(int x, int y, int z, T holder) { return getParent().setBlock(x, y, z, holder); } @@ -85,7 +85,7 @@ public interface IDelegateChunk extends IQueueChunk { } @Override - default void init(IQueueExtent extent, int chunkX, int chunkZ) { + default void init(IQueueExtent extent, int chunkX, int chunkZ) { getParent().init(extent, chunkX, chunkZ); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java index 6149266df..862da2a56 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java @@ -14,7 +14,7 @@ public interface IDelegateFilter extends Filter { } @Override - default IChunk applyChunk(IChunk chunk, @Nullable Region region) { + default V applyChunk(V chunk, @Nullable Region region) { return getParent().applyChunk(chunk, region); } @@ -48,4 +48,4 @@ public interface IDelegateFilter extends Filter { } Filter newInstance(Filter other); -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java index c3ba8bbb9..8a120ef6e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java @@ -80,7 +80,7 @@ public interface IDelegateQueueExtent extends IQueueExten } @Override - default boolean setBlock(int x, int y, int z, BlockStateHolder state) { + default > boolean setBlock(int x, int y, int z, B state) { return getParent().setBlock(x, y, z, state); } @@ -171,7 +171,6 @@ public interface IDelegateQueueExtent extends IQueueExten } @Override - @Nullable default void removeEntity(int x, int y, int z, UUID uuid) { getParent().removeEntity(x, y, z, uuid); } @@ -359,7 +358,7 @@ public interface IDelegateQueueExtent extends IQueueExten @Override @Deprecated - default > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { + default > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { return getParent().setBlock(position, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java index c512edd9e..574f25b0a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java @@ -36,6 +36,5 @@ public interface IQueueChunk> extends IChunk, Callable { while (future != null) { future = future.get(); } - return; } } 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 865fd6bdb..11269ce91 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,7 +20,7 @@ public interface IChunkExtent extends Extent { T getOrCreateChunk(int chunkX, int chunkZ); @Override - default boolean setBlock(int x, int y, int z, BlockStateHolder state) { + default > boolean setBlock(int x, int y, int z, B state) { final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); return chunk.setBlock(x & 15, y, z & 15, state); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java index 4989bbb64..a3712a053 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java @@ -36,7 +36,7 @@ public class BitSetBlocks implements IChunkSet { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder holder) { + public > boolean setBlock(int x, int y, int z, T holder) { row.set(null, x, y, z); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java index 1b2aa0039..88b595c15 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java @@ -109,6 +109,7 @@ public abstract class CharBlocks implements IBlocks { try { set(layer, index, value); } catch (ArrayIndexOutOfBoundsException exception) { + assert Fawe.imp() != null; Fawe.imp().debug("Tried Setting Block at x:" + x + ", y:" + y + " , z:" + z); Fawe.imp().debug("Layer variable was = " + layer); exception.printStackTrace(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java index e9a76c986..931c676be 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java @@ -16,11 +16,6 @@ public abstract class CharGetBlocks extends CharBlocks implements IChunkGet { return state.toBaseBlock(this, x, y, z); } - @Override - public BlockState getBlock(int x, int y, int z) { - return BlockTypesCache.states[get(x, y, z)]; - } - @Override public boolean trim(boolean aggressive) { for (int i = 0; i < 16; i++) { 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 7640adeae..584928704 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 @@ -2,6 +2,7 @@ package com.boydti.fawe.beta.implementation.blocks; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.implementation.queue.Pool; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.collection.BlockVector3ChunkMap; import com.boydti.fawe.util.MathMan; @@ -20,9 +21,10 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.stream.IntStream; public class CharSetBlocks extends CharBlocks implements IChunkSet { - private static FaweCache.Pool POOL = FaweCache.IMP.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL); + private static Pool POOL = FaweCache.IMP.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL); public static CharSetBlocks newInstance() { return POOL.poll(); } @@ -80,12 +82,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet { } @Override - public BlockState getBlock(int x, int y, int z) { - return BlockTypesCache.states[get(x, y, z)]; - } - - @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder holder) { + public > boolean setBlock(int x, int y, int z, T holder) { set(x, y, z, holder.getOrdinalChar()); holder.applyTileEntity(this, x, y, z); return true; @@ -138,12 +135,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet { if (biomes != null) { return false; } - for (int i = 0; i < 16; i++) { - if (hasSection(i)) { - return false; - } - } - return true; + return IntStream.range(0, 16).noneMatch(this::hasSection); } @Override 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 index 53c237753..18c21ad58 100644 --- 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 @@ -24,7 +24,7 @@ public interface DelegateChunkSet extends IChunkSet { } @Override - default boolean setBlock(int x, int y, int z, BlockStateHolder holder) { + default > boolean setBlock(int x, int y, int z, T holder) { return getParent().setBlock(x, y, z, holder); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java deleted file mode 100644 index c9004abe1..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.boydti.fawe.beta.implementation.blocks; - -import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.IBlocks; -import com.boydti.fawe.beta.IChunkGet; -import com.boydti.fawe.beta.IChunkSet; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.math.BlockVector3; -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.BlockTypes; - -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Future; - -public enum NullChunkGet implements IChunkGet { - INSTANCE - ; - @Override - public BaseBlock getFullBlock(int x, int y, int z) { - return BlockTypes.AIR.getDefaultState().toBaseBlock(); - } - - @Override - public BiomeType getBiomeType(int x, int y, int z) { - return BiomeTypes.FOREST; - } - - @Override - public BlockState getBlock(int x, int y, int z) { - return BlockTypes.AIR.getDefaultState(); - } - - @Override - public Map getTiles() { - return Collections.emptyMap(); - } - - @Override - public CompoundTag getTile(int x, int y, int z) { - return null; - } - - @Override - public Set getEntities() { - return null; - } - - @Override - public CompoundTag getEntity(UUID uuid) { - return null; - } - - @Override - public boolean trim(boolean aggressive) { - return true; - } - - @Override - public > T call(IChunkSet set, Runnable finalize) { - return null; - } - - @Override - public char[] load(int layer) { - return FaweCache.IMP.EMPTY_CHAR_4096; - } - - @Override - public boolean hasSection(int layer) { - return false; - } - - @Override - public IBlocks reset() { - return null; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt new file mode 100644 index 000000000..77e85f715 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.kt @@ -0,0 +1,68 @@ +package com.boydti.fawe.beta.implementation.blocks + +import com.boydti.fawe.FaweCache +import com.boydti.fawe.beta.IBlocks +import com.boydti.fawe.beta.IChunkGet +import com.boydti.fawe.beta.IChunkSet +import com.sk89q.jnbt.CompoundTag +import com.sk89q.worldedit.math.BlockVector3 +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.BlockTypes + +import java.util.Collections +import java.util.UUID +import java.util.concurrent.Future + +object NullChunkGet : IChunkGet { + + override fun getFullBlock(x: Int, y: Int, z: Int): BaseBlock { + return BlockTypes.AIR!!.defaultState.toBaseBlock() + } + + override fun getBiomeType(x: Int, y: Int, z: Int): BiomeType? { + return BiomeTypes.FOREST + } + + override fun getBlock(x: Int, y: Int, z: Int): BlockState { + return BlockTypes.AIR!!.defaultState + } + + override fun getTiles(): Map { + return emptyMap() + } + + override fun getTile(x: Int, y: Int, z: Int): CompoundTag? { + return null + } + + override fun getEntities(): Set? { + return null + } + + override fun getEntity(uuid: UUID): CompoundTag? { + return null + } + + override fun trim(aggressive: Boolean): Boolean { + return true + } + + override fun > call(set: IChunkSet, finalize: Runnable): T? { + return null + } + + override fun load(layer: Int): CharArray { + return FaweCache.IMP.EMPTY_CHAR_4096 + } + + override fun hasSection(layer: Int): Boolean { + return false + } + + override fun reset(): IBlocks? { + return null + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/ChunkCache.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/ChunkCache.java index 8c8dc463a..e4636899f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/ChunkCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/ChunkCache.java @@ -45,27 +45,25 @@ public class ChunkCache implements IChunkCache { @Override public synchronized boolean trim(boolean aggressive) { - if (getCache.size() == 0) { + if (getCache.isEmpty()) { return true; } boolean result = true; - if (!getCache.isEmpty()) { - final ObjectIterator>> iter = getCache - .long2ObjectEntrySet().fastIterator(); - while (iter.hasNext()) { - final Long2ObjectMap.Entry> entry = iter.next(); - final WeakReference value = entry.getValue(); - final T igb = value.get(); - if (igb == null) { - iter.remove(); - } else { - result = false; - if (!aggressive) { - return false; - } - synchronized (igb) { - igb.trim(true); - } + final ObjectIterator>> iter = getCache + .long2ObjectEntrySet().fastIterator(); + while (iter.hasNext()) { + final Long2ObjectMap.Entry> entry = iter.next(); + final WeakReference value = entry.getValue(); + final T igb = value.get(); + if (igb == null) { + iter.remove(); + } else { + result = false; + if (!aggressive) { + return false; + } + synchronized (igb) { + igb.trim(true); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/preloader/AsyncPreloader.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/preloader/AsyncPreloader.java index 14933971a..9154248f3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/preloader/AsyncPreloader.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/cache/preloader/AsyncPreloader.java @@ -7,6 +7,7 @@ import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -33,7 +34,7 @@ public class AsyncPreloader implements Preloader, Runnable { cancelAndGet(player); } - private MutablePair> cancelAndGet(Player player) { + private MutablePair> cancelAndGet(Actor player) { MutablePair> existing = update.get(player.getUniqueId()); if (existing != null) { existing.setValue(null); @@ -100,11 +101,10 @@ public class AsyncPreloader implements Preloader, Runnable { } } catch (InterruptedException e) { e.printStackTrace(); - return; } } public void queueLoad(World world, BlockVector2 chunk) { world.checkLoadedChunk(BlockVector3.at(chunk.getX() << 4, 0, chunk.getZ() << 4)); } -} \ No newline at end of file +} 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 c70a9490c..d7b4e866b 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 @@ -8,6 +8,7 @@ import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.beta.IQueueExtent; +import com.boydti.fawe.beta.implementation.queue.Pool; import com.boydti.fawe.config.Settings; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.math.BlockVector3; @@ -26,9 +27,9 @@ import javax.annotation.Nullable; /** * An abstract {@link IChunk} class that implements basic get/set blocks */ -public class ChunkHolder> implements IQueueChunk { +public class ChunkHolder> implements IQueueChunk { - private static FaweCache.Pool POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); + private static Pool POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); public static ChunkHolder newInstance() { return POOL.poll(); @@ -121,8 +122,8 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public boolean setBlock(ChunkHolder chunk, int x, int y, int z, - BlockStateHolder block) { + public > boolean setBlock(ChunkHolder chunk, int x, int y, int z, + B block) { return chunk.chunkSet.setBlock(x, y, z, block); } @@ -164,8 +165,8 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public boolean setBlock(ChunkHolder chunk, int x, int y, int z, - BlockStateHolder block) { + public > boolean setBlock(ChunkHolder chunk, int x, int y, int z, + T block) { chunk.getOrCreateSet(); chunk.delegate = BOTH; return chunk.setBlock(x, y, z, block); @@ -207,7 +208,7 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder block) { + public > boolean setBlock(ChunkHolder chunk, int x, int y, int z, T block) { return chunk.chunkSet.setBlock(x, y, z, block); } @@ -256,7 +257,7 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder block) { + public > boolean setBlock(ChunkHolder chunk, int x, int y, int z, T block) { chunk.getOrCreateSet(); chunk.delegate = SET; return chunk.setBlock(x, y, z, block); @@ -388,7 +389,7 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public void init(IQueueExtent extent, int chunkX, int chunkZ) { + public void init(IQueueExtent extent, int chunkX, int chunkZ) { this.extent = extent; this.chunkX = chunkX; this.chunkZ = chunkZ; @@ -445,7 +446,7 @@ public class ChunkHolder> implements IQueueChunk { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) { + public > boolean setBlock(int x, int y, int z, B block) { return delegate.setBlock(this, x, y, z, block); } @@ -465,12 +466,12 @@ public class ChunkHolder> implements IQueueChunk { } public interface IBlockDelegate { - IChunkGet get(ChunkHolder chunk); + > IChunkGet get(ChunkHolder chunk); IChunkSet set(ChunkHolder chunk); boolean setBiome(ChunkHolder chunk, int x, int y, int z, BiomeType biome); - boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder holder); + > boolean setBlock(ChunkHolder chunk, int x, int y, int z, T holder); BiomeType getBiome(ChunkHolder chunk, int x, int y, int z); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java index 7f5de9101..8c0211d80 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java @@ -7,11 +7,11 @@ import com.boydti.fawe.beta.IQueueExtent; * Used by {@link ReferenceChunk} to allow the chunk to be garbage collected. - When the object is * finalized, add it to the queue */ -public class FinalizedChunk extends DelegateChunk { +public class FinalizedChunk extends DelegateChunk { private final IQueueExtent queueExtent; - public FinalizedChunk(IQueueChunk parent, IQueueExtent queueExtent) { + public FinalizedChunk(T parent, IQueueExtent queueExtent) { super(parent); this.queueExtent = queueExtent; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java index 6b2516dd6..cd5846a70 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java @@ -83,7 +83,7 @@ public enum NullChunk implements IQueueChunk { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) { + public > boolean setBlock(int x, int y, int z, B block) { return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/DelegateFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/DelegateFilterBlock.java index 20a6e4aa7..b3216fae6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/DelegateFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/DelegateFilterBlock.java @@ -575,7 +575,6 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - @Nullable public void removeEntity(int x, int y, int z, UUID uuid) { parent.removeEntity(x, y, z, uuid); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.java deleted file mode 100644 index c68eadb5e..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.boydti.fawe.beta.implementation.processors; - -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.worldedit.extent.Extent; - -public enum EmptyBatchProcessor implements IBatchProcessor { - INSTANCE - ; - @Override - public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { - return set; - } - - @Override - public Extent construct(Extent child) { - return child; - } - - @Override - public IBatchProcessor join(IBatchProcessor other) { - return other; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.kt b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.kt new file mode 100644 index 000000000..024ff6a4d --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/EmptyBatchProcessor.kt @@ -0,0 +1,22 @@ +package com.boydti.fawe.beta.implementation.processors + +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.worldedit.extent.Extent + +object EmptyBatchProcessor : IBatchProcessor { + + override fun construct(child: Extent?): Extent { + return child!! + } + + override fun processSet(chunk: IChunk?, get: IChunkGet?, set: IChunkSet?): IChunkSet { + return set!! + } + + override fun join(other: IBatchProcessor?): IBatchProcessor { + return other!! + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java index 44ff0c59a..1c59fc96d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/LimitExtent.java @@ -92,7 +92,6 @@ public class LimitExtent extends PassthroughExtent { } @Override - @Nullable public void removeEntity(int x, int y, int z, UUID uuid) { limit.THROW_MAX_CHANGES(); limit.THROW_MAX_ENTITIES(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.java deleted file mode 100644 index 7b3f54b25..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.boydti.fawe.beta.implementation.processors; - -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.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.NullExtent; - -public enum NullProcessor implements IBatchProcessor { - INSTANCE; - @Override - public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { - return null; - } - - @Override - public Extent construct(Extent child) { - return new NullExtent(); - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.kt b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.kt new file mode 100644 index 000000000..2e85cd938 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/NullProcessor.kt @@ -0,0 +1,19 @@ +package com.boydti.fawe.beta.implementation.processors + +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.worldedit.extent.Extent +import com.sk89q.worldedit.extent.NullExtent + +object NullProcessor : IBatchProcessor { + + override fun processSet(chunk: IChunk, get: IChunkGet, set: IChunkSet): IChunkSet? { + return null + } + + override fun construct(child: Extent): Extent { + return NullExtent() + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java new file mode 100644 index 000000000..a56b17942 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java @@ -0,0 +1,10 @@ +package com.boydti.fawe.beta.implementation.queue; + +public interface Pool { + T poll(); + default boolean offer(T recycle) { + return false; + } + default void clear() {} +} + diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueuePool.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueuePool.java new file mode 100644 index 000000000..25b51f528 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueuePool.java @@ -0,0 +1,27 @@ +package com.boydti.fawe.beta.implementation.queue; + +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.function.Supplier; + +public class QueuePool extends ConcurrentLinkedQueue implements Pool { + private final Supplier supplier; + + public QueuePool(Supplier supplier) { + this.supplier = supplier; + } + + @Override + public T poll() { + T result = super.poll(); + if (result == null) { + return supplier.get(); + } + return result; + } + + @Override + public void clear() { + if (!isEmpty()) super.clear(); + } +} + diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java index efe224081..16cc9f06d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java @@ -101,7 +101,7 @@ public class MCAChunk implements IChunk { } @Override - public void init(IQueueExtent extent, int x, int z) { + public void init(IQueueExtent extent, int x, int z) { if (x != chunkX || z != chunkZ) { throw new UnsupportedOperationException("Not reuse capable"); } @@ -414,6 +414,7 @@ public class MCAChunk implements IChunk { this.modified++; } + @Override public int getBitMask() { int bitMask = 0; for (int section = 0; section < hasSections.length; section++) { @@ -509,7 +510,7 @@ public class MCAChunk implements IChunk { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder holder) { + public > boolean setBlock(int x, int y, int z, B holder) { setBlock(x, y, z, holder.getOrdinalChar()); holder.applyTileEntity(this, x, y, z); return true; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index 6a09ef441..b47880573 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -35,14 +35,12 @@ public class CPUOptimizedClipboard extends LinearClipboard { private final HashMap nbtMapLoc; private final HashMap nbtMapIndex; - private final HashSet entities; public CPUOptimizedClipboard(BlockVector3 dimensions) { super(dimensions); this.states = new char[getVolume()]; nbtMapLoc = new HashMap<>(); nbtMapIndex = new HashMap<>(); - entities = new HashSet<>(); } @Override @@ -216,7 +214,6 @@ public class CPUOptimizedClipboard extends LinearClipboard { this.entities.remove(entity); } - @Nullable @Override public void removeEntity(int x, int y, int z, UUID uuid) { Iterator iter = this.entities.iterator(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DelegateClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DelegateClipboard.java index 7d668154c..61b83b29d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DelegateClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DelegateClipboard.java @@ -92,7 +92,6 @@ public class DelegateClipboard implements Clipboard { } @Override - @Nullable public void removeEntity(int x, int y, int z, UUID uuid) { parent.removeEntity(x, y, z, uuid); } 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 db1eb9f36..a3523e1df 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 @@ -11,26 +11,20 @@ import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; -import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Region; 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 javax.annotation.Nullable; import java.io.Closeable; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.lang.reflect.Field; @@ -42,12 +36,11 @@ import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; +import javax.annotation.Nullable; /** * A clipboard with disk backed storage. (lower memory + loads on crash) @@ -59,7 +52,6 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private static int HEADER_SIZE = 14; private final HashMap nbtMap; - private final HashSet entities; private final File file; private RandomAccessFile braf; @@ -81,9 +73,8 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable if (getWidth() > Character.MAX_VALUE || getHeight() > Character.MAX_VALUE || getLength() > Character.MAX_VALUE) { throw new IllegalArgumentException("Too large"); } + nbtMap = new HashMap<>(); try { - nbtMap = new HashMap<>(); - entities = new HashSet<>(); this.file = file; try { if (!file.exists()) { @@ -127,9 +118,8 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable public DiskOptimizedClipboard(File file) { super(readSize(file)); + nbtMap = new HashMap<>(); try { - nbtMap = new HashMap<>(); - entities = new HashSet<>(); this.file = file; this.braf = new RandomAccessFile(file, "rw"); braf.setLength(file.length()); @@ -437,7 +427,6 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable this.entities.remove(entity); } - @Nullable @Override public void removeEntity(int x, int y, int z, UUID uuid) { Iterator iter = this.entities.iterator(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java index e67d1bc38..ef24d9003 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java @@ -71,7 +71,7 @@ public class EmptyClipboard implements Clipboard { } @Override - public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { return false; } 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 e02d557c8..5d87eccd3 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,6 +5,8 @@ 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; @@ -17,7 +19,9 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.Closeable; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; +import java.util.UUID; import org.jetbrains.annotations.NotNull; /** @@ -25,8 +29,12 @@ import org.jetbrains.annotations.NotNull; * (Small being < Integer.MAX_VALUE/BLOCK_SIZE_BYTES blocks) */ public abstract class LinearClipboard extends SimpleClipboard implements Clipboard, Closeable { + + protected final HashSet entities; + public LinearClipboard(BlockVector3 dimensions) { super(dimensions); + entities = new HashSet<>(); } public abstract > boolean setBlock(int i, B block); @@ -91,6 +99,19 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa } + @Override + public void removeEntity(int x, int y, int z, UUID uuid) { + Iterator iter = this.entities.iterator(); + while (iter.hasNext()) { + ClipboardEntity entity = iter.next(); + UUID entUUID = entity.getState().getNbtData().getUUID(); + if (uuid.equals(entUUID)) { + iter.remove(); + return; + } + } + } + private class LinearFilter extends AbstractFilterBlock { private int index = -1; private BlockVector3 position; 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 3a802311e..4e97c9561 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 @@ -46,7 +46,6 @@ public class MemoryOptimizedClipboard extends LinearClipboard { private final HashMap nbtMapLoc; private final HashMap nbtMapIndex; - private final HashSet entities; private int lastCombinedIdsI = -1; @@ -65,7 +64,6 @@ public class MemoryOptimizedClipboard extends LinearClipboard { states = new byte[1 + (getVolume() >> BLOCK_SHIFT)][]; nbtMapLoc = new HashMap<>(); nbtMapIndex = new HashMap<>(); - entities = new HashSet<>(); this.compressionLevel = compressionLevel; } @@ -315,17 +313,4 @@ public class MemoryOptimizedClipboard extends LinearClipboard { this.entities.remove(entity); } - @Nullable - @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/collection/CleanableThreadLocal.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/CleanableThreadLocal.java index 2f61a48ea..87aef5b8d 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 @@ -138,7 +138,7 @@ public class CleanableThreadLocal extends ThreadLocal implements Closeable // Get a reference to the array holding the thread local variables inside the // ThreadLocalMap of the current thread - Class threadLocalMapClass = Class.forName("java.lang.ThreadLocal$ThreadLocalMap"); + Class threadLocalMapClass = Class.forName("java.lang.ThreadLocal$ThreadLocalMap"); Field tableField = threadLocalMapClass.getDeclaredField("table"); tableField.setAccessible(true); Object table = tableField.get(threadLocalTable); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java index 4aac2a2de..5607c2eda 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.mask; -import com.boydti.fawe.Fawe; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.math.BlockVector3; @@ -138,8 +137,6 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { @Override public boolean test(Extent extent, BlockVector3 vector) { - Fawe.imp().debug("getExtent(): " + getExtent().getClass() + " extent: " + extent.getClass()); - int x = vector.getBlockX(); int y = vector.getBlockY(); int z = vector.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java index c9b0865cf..c152e9cf2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java @@ -427,7 +427,7 @@ public class TaskBuilder extends Metadatable { } } - public static abstract class SplitTask extends RunnableTask { + public static abstract class SplitTask extends RunnableTask { private final long allocation; private final QueueHandler queue; @@ -450,7 +450,7 @@ public class TaskBuilder extends Metadatable { this.queue = Fawe.get().getQueueHandler(); } - public Object execSplit(final Object previous) { + public Object execSplit(final T previous) { this.value = previous; final Thread thread = new Thread(() -> { try { @@ -478,7 +478,7 @@ public class TaskBuilder extends Metadatable { e.printStackTrace(); } while (thread.isAlive()) { - TaskManager.IMP.syncWhenFree(new RunnableVal() { + TaskManager.IMP.syncWhenFree(new RunnableVal() { @Override public void run(Object ignore) { queue.startSet(true); 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 f46d220af..423df21b0 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 @@ -151,7 +151,7 @@ public interface Extent extends InputExtent, OutputExtent { * @param z the z coordinate * @param uuid the unique identifier of the entity */ - default @Nullable void removeEntity(int x, int y, int z, UUID uuid) {} + default void removeEntity(int x, int y, int z, UUID uuid) {} /* Queue based methods diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java index 317e070a7..794ddefb2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java @@ -60,7 +60,7 @@ public interface OutputExtent { } // The defaults need to remain for compatibility (the actual implementation still needs to override one of these) - default > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + default > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { return setBlock(MutableBlockVector3.get(x, y, z), block); } 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 6bda89355..f05619fd5 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 @@ -210,7 +210,6 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard, } @Override - @Nullable public void removeEntity(int x, int y, int z, UUID uuid) { x -= offset.getX(); y -= offset.getY(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java index 544fc560a..5bfe830e6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.world.storage.ChunkStore; import java.util.HashSet; import java.util.Set; +import org.jetbrains.annotations.Range; /** * Represents an ellipsoid region. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index 0eb1fc636..f35860b01 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -319,6 +319,7 @@ public interface Region extends Iterable, Cloneable, IBatchProcess } } + @Override default Extent construct(Extent child) { if (isGlobal()) { return child;