mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Cleaned up a lot of code and introduced Kotlin to the project
This commit is contained in:
@ -20,7 +20,7 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
T getOrCreateChunk(int chunkX, int chunkZ);
|
||||
|
||||
@Override
|
||||
default boolean setBlock(int x, int y, int z, BlockStateHolder state) {
|
||||
default <B extends BlockStateHolder<B>> 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);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class BitSetBlocks implements IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T holder) {
|
||||
row.set(null, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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++) {
|
||||
|
@ -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<CharSetBlocks> POOL = FaweCache.IMP.registerPool(CharSetBlocks.class, CharSetBlocks::new, Settings.IMP.QUEUE.POOL);
|
||||
private static Pool<CharSetBlocks> 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 <T extends BlockStateHolder<T>> 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
|
||||
|
@ -24,7 +24,7 @@ public interface DelegateChunkSet extends IChunkSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
|
||||
default <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T holder) {
|
||||
return getParent().setBlock(x, y, z, holder);
|
||||
}
|
||||
|
||||
|
@ -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<BlockVector3, CompoundTag> getTiles() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getTile(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CompoundTag> getEntities() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getEntity(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(boolean aggressive) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Future<T>> 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;
|
||||
}
|
||||
}
|
@ -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<BlockVector3, CompoundTag> {
|
||||
return emptyMap()
|
||||
}
|
||||
|
||||
override fun getTile(x: Int, y: Int, z: Int): CompoundTag? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getEntities(): Set<CompoundTag>? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getEntity(uuid: UUID): CompoundTag? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun trim(aggressive: Boolean): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun <T : Future<T>> 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
|
||||
}
|
||||
}
|
@ -45,27 +45,25 @@ public class ChunkCache<T extends Trimable> implements IChunkCache<T> {
|
||||
|
||||
@Override
|
||||
public synchronized boolean trim(boolean aggressive) {
|
||||
if (getCache.size() == 0) {
|
||||
if (getCache.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
boolean result = true;
|
||||
if (!getCache.isEmpty()) {
|
||||
final ObjectIterator<Long2ObjectMap.Entry<WeakReference<T>>> iter = getCache
|
||||
.long2ObjectEntrySet().fastIterator();
|
||||
while (iter.hasNext()) {
|
||||
final Long2ObjectMap.Entry<WeakReference<T>> entry = iter.next();
|
||||
final WeakReference<T> 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<Long2ObjectMap.Entry<WeakReference<T>>> iter = getCache
|
||||
.long2ObjectEntrySet().fastIterator();
|
||||
while (iter.hasNext()) {
|
||||
final Long2ObjectMap.Entry<WeakReference<T>> entry = iter.next();
|
||||
final WeakReference<T> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<World, Set<BlockVector2>> cancelAndGet(Player player) {
|
||||
private MutablePair<World, Set<BlockVector2>> cancelAndGet(Actor player) {
|
||||
MutablePair<World, Set<BlockVector2>> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<T extends Future<T>> implements IQueueChunk {
|
||||
public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
|
||||
|
||||
private static FaweCache.Pool<ChunkHolder> POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL);
|
||||
private static Pool<ChunkHolder> 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<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder block) {
|
||||
public <B extends BlockStateHolder<B>> 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<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||
BlockStateHolder block) {
|
||||
public <T extends BlockStateHolder<T>> 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<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder block) {
|
||||
public <T extends BlockStateHolder<T>> 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<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder block) {
|
||||
public <T extends BlockStateHolder<T>> 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<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IQueueExtent extent, int chunkX, int chunkZ) {
|
||||
public <V extends IChunk> void init(IQueueExtent<V> extent, int chunkX, int chunkZ) {
|
||||
this.extent = extent;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
@ -445,7 +446,7 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
|
||||
public <B extends BlockStateHolder<B>> 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<T extends Future<T>> implements IQueueChunk {
|
||||
}
|
||||
|
||||
public interface IBlockDelegate {
|
||||
IChunkGet get(ChunkHolder chunk);
|
||||
<C extends Future<C>> IChunkGet get(ChunkHolder<C> 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);
|
||||
<T extends BlockStateHolder<T>> boolean setBlock(ChunkHolder chunk, int x, int y, int z, T holder);
|
||||
|
||||
BiomeType getBiome(ChunkHolder chunk, int x, int y, int z);
|
||||
|
||||
|
@ -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<T extends IQueueChunk> extends DelegateChunk<T> {
|
||||
|
||||
private final IQueueExtent queueExtent;
|
||||
|
||||
public FinalizedChunk(IQueueChunk parent, IQueueExtent queueExtent) {
|
||||
public FinalizedChunk(T parent, IQueueExtent queueExtent) {
|
||||
super(parent);
|
||||
this.queueExtent = queueExtent;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public enum NullChunk implements IQueueChunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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!!
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.boydti.fawe.beta.implementation.queue;
|
||||
|
||||
public interface Pool<T> {
|
||||
T poll();
|
||||
default boolean offer(T recycle) {
|
||||
return false;
|
||||
}
|
||||
default void clear() {}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.boydti.fawe.beta.implementation.queue;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class QueuePool<T> extends ConcurrentLinkedQueue<T> implements Pool<T> {
|
||||
private final Supplier<T> supplier;
|
||||
|
||||
public QueuePool(Supplier<T> 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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user