3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-20 01:40:06 +01:00

Cleaned up a lot of code and introduced Kotlin to the project

Dieser Commit ist enthalten in:
MattBDev 2020-01-14 19:44:09 -05:00
Ursprung 2fb1c3bdbc
Commit 2d5a8ce573
47 geänderte Dateien mit 268 neuen und 307 gelöschten Zeilen

Datei anzeigen

@ -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<JavaCompile>().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"
}

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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<Class, CleanableThreadLocal> REGISTERED_SINGLETONS = new IdentityHashMap<>();
private final IdentityHashMap<Class, Pool> REGISTERED_POOLS = new IdentityHashMap<>();
public interface Pool<T> {
T poll();
default boolean offer(T recycle) {
return false;
}
default void clear() {}
}
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 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<Class<?>, CleanableThreadLocal> REGISTERED_SINGLETONS = new IdentityHashMap<>();
private final IdentityHashMap<Class<?>, 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<Class, CleanableThreadLocal> entry : REGISTERED_SINGLETONS.entrySet()) {
for (Map.Entry<Class<?>, CleanableThreadLocal> entry : REGISTERED_SINGLETONS.entrySet()) {
entry.getValue().clean();
}
}
for (Map.Entry<Class, Pool> entry : REGISTERED_POOLS.entrySet()) {
for (Map.Entry<Class<?>, 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<? extends Object> clazz = value.getClass();
Class<?> clazz = value.getClass();
if (clazz.getName().startsWith("com.intellectualcrafters.jnbt")) {
try {
if (clazz.getName().equals("com.intellectualcrafters.jnbt.EndTag")) {

Datei anzeigen

@ -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);
/**

Datei anzeigen

@ -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();

Datei anzeigen

@ -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 <V extends IChunk> void init(IQueueExtent<V> 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);
<T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block);
@Override
BiomeType getBiomeType(int x, int y, int z);

Datei anzeigen

@ -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);
<T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T holder);
void setBlocks(int layer, char[] data);

Datei anzeigen

@ -65,7 +65,7 @@ public interface IDelegateChunk<U extends IQueueChunk> extends IQueueChunk {
}
@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);
}
@ -85,7 +85,7 @@ public interface IDelegateChunk<U extends IQueueChunk> extends IQueueChunk {
}
@Override
default void init(IQueueExtent extent, int chunkX, int chunkZ) {
default <E extends IChunk> void init(IQueueExtent<E> extent, int chunkX, int chunkZ) {
getParent().init(extent, chunkX, chunkZ);
}

Datei anzeigen

@ -14,7 +14,7 @@ public interface IDelegateFilter extends Filter {
}
@Override
default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
default <V extends IChunk> V applyChunk(V chunk, @Nullable Region region) {
return getParent().applyChunk(chunk, region);
}

Datei anzeigen

@ -80,7 +80,7 @@ public interface IDelegateQueueExtent<T extends IQueueChunk> extends IQueueExten
}
@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) {
return getParent().setBlock(x, y, z, state);
}
@ -171,7 +171,6 @@ public interface IDelegateQueueExtent<T extends IQueueChunk> 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<T extends IQueueChunk> extends IQueueExten
@Override
@Deprecated
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
return getParent().setBlock(position, block);
}

Datei anzeigen

@ -36,6 +36,5 @@ public interface IQueueChunk<T extends Future<T>> extends IChunk, Callable<T> {
while (future != null) {
future = future.get();
}
return;
}
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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++) {

Datei anzeigen

@ -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

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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
}
}

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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,7 +101,6 @@ public class AsyncPreloader implements Preloader, Runnable {
}
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
}

Datei anzeigen

@ -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);

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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!!
}
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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()
}
}

Datei anzeigen

@ -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() {}
}

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -101,7 +101,7 @@ public class MCAChunk implements IChunk {
}
@Override
public void init(IQueueExtent extent, int x, int z) {
public <V extends IChunk> void init(IQueueExtent<V> 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 <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B holder) {
setBlock(x, y, z, holder.getOrdinalChar());
holder.applyTileEntity(this, x, y, z);
return true;

Datei anzeigen

@ -35,14 +35,12 @@ public class CPUOptimizedClipboard extends LinearClipboard {
private final HashMap<IntegerTrio, CompoundTag> nbtMapLoc;
private final HashMap<Integer, CompoundTag> nbtMapIndex;
private final HashSet<BlockArrayClipboard.ClipboardEntity> 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<BlockArrayClipboard.ClipboardEntity> iter = this.entities.iterator();

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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<IntegerTrio, CompoundTag> nbtMap;
private final HashSet<BlockArrayClipboard.ClipboardEntity> 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<BlockArrayClipboard.ClipboardEntity> iter = this.entities.iterator();

Datei anzeigen

@ -71,7 +71,7 @@ public class EmptyClipboard implements Clipboard {
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
return false;
}

Datei anzeigen

@ -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<ClipboardEntity> entities;
public LinearClipboard(BlockVector3 dimensions) {
super(dimensions);
entities = new HashSet<>();
}
public abstract <B extends BlockStateHolder<B>> 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<ClipboardEntity> 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;

Datei anzeigen

@ -46,7 +46,6 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
private final HashMap<IntegerTrio, CompoundTag> nbtMapLoc;
private final HashMap<Integer, CompoundTag> nbtMapIndex;
private final HashSet<BlockArrayClipboard.ClipboardEntity> 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<BlockArrayClipboard.ClipboardEntity> 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;
}
}
}
}

Datei anzeigen

@ -138,7 +138,7 @@ public class CleanableThreadLocal<T> extends ThreadLocal<T> 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);

Datei anzeigen

@ -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();

Datei anzeigen

@ -427,7 +427,7 @@ public class TaskBuilder extends Metadatable {
}
}
public static abstract class SplitTask extends RunnableTask {
public static abstract class SplitTask<T> extends RunnableTask<T> {
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<T>() {
@Override
public void run(Object ignore) {
queue.startSet(true);

Datei anzeigen

@ -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

Datei anzeigen

@ -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 <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
default <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return setBlock(MutableBlockVector3.get(x, y, z), block);
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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.

Datei anzeigen

@ -319,6 +319,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
}
}
@Override
default Extent construct(Extent child) {
if (isGlobal()) {
return child;