mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-28 17:38:01 +01:00
Javadoc, some cleanup
This commit is contained in:
parent
1d0760c630
commit
7aaa075ba8
@ -67,7 +67,6 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
private org.bukkit.World bukkitWorld;
|
private org.bukkit.World bukkitWorld;
|
||||||
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||||
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||||
private Runnable whenDone;
|
|
||||||
private ChunkCoordinator chunkCoordinator;
|
private ChunkCoordinator chunkCoordinator;
|
||||||
|
|
||||||
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
||||||
@ -198,7 +197,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
}
|
}
|
||||||
chunkCoordinator =
|
chunkCoordinator =
|
||||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld()).withChunks(getBlockChunks().keySet()).withChunks(read)
|
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld()).withChunks(getBlockChunks().keySet()).withChunks(read)
|
||||||
.withInitialBatchSize(3).withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace).withFinalAction(whenDone)
|
.withInitialBatchSize(3).withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace).withFinalAction(getCompleteTask())
|
||||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).build();
|
.withConsumer(consumer).unloadAfter(isUnloadAfter()).build();
|
||||||
return super.enqueue();
|
return super.enqueue();
|
||||||
}
|
}
|
||||||
@ -239,8 +238,4 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setCompleteTask(Runnable whenDone) {
|
|
||||||
this.whenDone = whenDone;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,9 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return this.chunkData;
|
return this.chunkData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the internal Bukkit chunk data
|
||||||
|
*/
|
||||||
public void setChunkData(@Nonnull ChunkData chunkData) {
|
public void setChunkData(@Nonnull ChunkData chunkData) {
|
||||||
this.chunkData = chunkData;
|
this.chunkData = chunkData;
|
||||||
}
|
}
|
||||||
@ -85,10 +88,17 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the chunk being represented
|
||||||
|
*/
|
||||||
public void setChunk(@Nonnull Chunk chunk) {
|
public void setChunk(@Nonnull Chunk chunk) {
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the world and XZ of the chunk being represented via {@link ChunkWrapper}
|
||||||
|
*/
|
||||||
public void setChunk(@Nonnull ChunkWrapper wrap) {
|
public void setChunk(@Nonnull ChunkWrapper wrap) {
|
||||||
chunk = null;
|
chunk = null;
|
||||||
world = wrap.world;
|
world = wrap.world;
|
||||||
@ -101,9 +111,11 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Biome biome = BukkitAdapter.adapt(biomeType);
|
Biome biome = BukkitAdapter.adapt(biomeType);
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int y = 0; y < 256; y++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
this.biomeGrid.setBiome(x, z, biome);
|
for (int z = 0; z < 16; z++) {
|
||||||
|
this.biomeGrid.setBiome(x, y, z, biome);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,9 +146,22 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the in the whole column of XZ
|
||||||
|
*/
|
||||||
public boolean setBiome(int x, int z, @Nonnull Biome biome) {
|
public boolean setBiome(int x, int z, @Nonnull Biome biome) {
|
||||||
if (this.biomeGrid != null) {
|
if (this.biomeGrid != null) {
|
||||||
this.biomeGrid.setBiome(x, z, biome);
|
for (int y = 0; y < 256; y++) {
|
||||||
|
this.setBiome(x, y, z, biome);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setBiome(int x, int y, int z, @Nonnull Biome biome) {
|
||||||
|
if (this.biomeGrid != null) {
|
||||||
|
this.biomeGrid.setBiome(x, y, z, biome);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -162,6 +162,8 @@ public class AugmentedUtils {
|
|||||||
new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, 0, blockZ), Location.at(world, blockX + 15, 255, blockZ + 15));
|
new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, 0, blockZ), Location.at(world, blockX + 15, 255, blockZ + 15));
|
||||||
generator.generateChunk(scoped, area);
|
generator.generateChunk(scoped, area);
|
||||||
generator.populateChunk(scoped, area);
|
generator.populateChunk(scoped, area);
|
||||||
|
scoped.setForceSync(true);
|
||||||
|
scoped.enqueue();
|
||||||
}
|
}
|
||||||
if (enqueue) {
|
if (enqueue) {
|
||||||
queue.enqueue();
|
queue.enqueue();
|
||||||
|
@ -36,6 +36,9 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue Coordinator that only sets blocks with the specified PlotArea
|
||||||
|
*/
|
||||||
public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator {
|
public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator {
|
||||||
|
|
||||||
private final PlotArea area;
|
private final PlotArea area;
|
||||||
@ -45,6 +48,9 @@ public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator
|
|||||||
this.area = Objects.requireNonNull(area);
|
this.area = Objects.requireNonNull(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the plot area block settings is limited to
|
||||||
|
*/
|
||||||
public PlotArea getArea() {
|
public PlotArea getArea() {
|
||||||
return this.area;
|
return this.area;
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,16 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standard block setting queue that allows block setting across numerous chunks, without limits.
|
||||||
|
*/
|
||||||
public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||||
|
|
||||||
private final World world;
|
private final World world;
|
||||||
@ -62,6 +66,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
|||||||
private CuboidRegion regenRegion = null;
|
private CuboidRegion regenRegion = null;
|
||||||
private Consumer<BlockVector2> consumer = null;
|
private Consumer<BlockVector2> consumer = null;
|
||||||
private boolean unloadAfter = true;
|
private boolean unloadAfter = true;
|
||||||
|
private Runnable whenDone;
|
||||||
|
|
||||||
public BasicQueueCoordinator(@Nonnull World world) {
|
public BasicQueueCoordinator(@Nonnull World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@ -193,35 +198,61 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
|||||||
this.unloadAfter = unloadAfter;
|
this.unloadAfter = unloadAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the int[x,z] chunk coordinates where regeneration should start from
|
||||||
|
*/
|
||||||
public int[] getRegenStart() {
|
public int[] getRegenStart() {
|
||||||
return regenStart;
|
return regenStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the int[x,z] chunk coordinates where regeneration should finish
|
||||||
|
*/
|
||||||
public int[] getRegenEnd() {
|
public int[] getRegenEnd() {
|
||||||
return regenEnd;
|
return regenEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the queue has a start/end to chunk regeneration
|
||||||
|
*/
|
||||||
public boolean isRegen() {
|
public boolean isRegen() {
|
||||||
return regen;
|
return regen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrentHashMap<BlockVector2, LocalChunk> getBlockChunks() {
|
/**
|
||||||
|
* Gets the map of ChunkCoordinates in {@link BlockVector2} form against the {@link LocalChunk} of cached chunks to be written
|
||||||
|
*/
|
||||||
|
@Nonnull public ConcurrentHashMap<BlockVector2, LocalChunk> getBlockChunks() {
|
||||||
return this.blockChunks;
|
return this.blockChunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setChunk(LocalChunk chunk) {
|
/**
|
||||||
|
* Forces an {@link LocalChunk} into the list of chunks to be written. Overwrites existing chunks in the map
|
||||||
|
*/
|
||||||
|
public final void setChunk(@Nonnull LocalChunk chunk) {
|
||||||
this.blockChunks.put(BlockVector2.at(chunk.getX(), chunk.getZ()), chunk);
|
this.blockChunks.put(BlockVector2.at(chunk.getX(), chunk.getZ()), chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Consumer<BlockVector2> getChunkConsumer() {
|
@Override @Nullable public final Consumer<BlockVector2> getChunkConsumer() {
|
||||||
return this.consumer;
|
return this.consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setChunkConsumer(@Nonnull Consumer<BlockVector2> consumer) {
|
@Override public final void setChunkConsumer(@Nonnull Consumer<BlockVector2> consumer) {
|
||||||
this.consumer = consumer;
|
this.consumer = consumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalChunk getChunk(final int chunkX, final int chunkZ) {
|
@Override public Runnable getCompleteTask() {
|
||||||
|
return this.whenDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void setCompleteTask(Runnable whenDone) {
|
||||||
|
this.whenDone = whenDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link LocalChunk} from the queue at the given chunk coordinates. Returns a new instance if one doesn't exist
|
||||||
|
*/
|
||||||
|
@Nonnull private LocalChunk getChunk(final int chunkX, final int chunkZ) {
|
||||||
if (chunkX != lastX || chunkZ != lastZ) {
|
if (chunkX != lastX || chunkZ != lastZ) {
|
||||||
lastX = chunkX;
|
lastX = chunkX;
|
||||||
lastZ = chunkZ;
|
lastZ = chunkZ;
|
||||||
|
@ -40,6 +40,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a {@link ChunkCoordinator} instance
|
||||||
|
*/
|
||||||
public class ChunkCoordinatorBuilder {
|
public class ChunkCoordinatorBuilder {
|
||||||
|
|
||||||
private final List<BlockVector2> requestedChunks = new LinkedList<>();
|
private final List<BlockVector2> requestedChunks = new LinkedList<>();
|
||||||
@ -57,21 +60,33 @@ public class ChunkCoordinatorBuilder {
|
|||||||
this.chunkCoordinatorFactory = chunkCoordinatorFactory;
|
this.chunkCoordinatorFactory = chunkCoordinatorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the world
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder inWorld(@Nonnull final World world) {
|
@Nonnull public ChunkCoordinatorBuilder inWorld(@Nonnull final World world) {
|
||||||
this.world = Preconditions.checkNotNull(world, "World may not be null");
|
this.world = Preconditions.checkNotNull(world, "World may not be null");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a chunk to be accessed
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withChunk(@Nonnull final BlockVector2 chunkLocation) {
|
@Nonnull public ChunkCoordinatorBuilder withChunk(@Nonnull final BlockVector2 chunkLocation) {
|
||||||
this.requestedChunks.add(Preconditions.checkNotNull(chunkLocation, "Chunk location may not be null"));
|
this.requestedChunks.add(Preconditions.checkNotNull(chunkLocation, "Chunk location may not be null"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Collection of chunks to be accessed
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withChunks(@Nonnull final Collection<BlockVector2> chunkLocations) {
|
@Nonnull public ChunkCoordinatorBuilder withChunks(@Nonnull final Collection<BlockVector2> chunkLocations) {
|
||||||
chunkLocations.forEach(this::withChunk);
|
chunkLocations.forEach(this::withChunk);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add chunks within a region to be accessed
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withRegion(@Nonnull Location pos1, @Nonnull Location pos2) {
|
@Nonnull public ChunkCoordinatorBuilder withRegion(@Nonnull Location pos1, @Nonnull Location pos2) {
|
||||||
final int p1x = pos1.getX();
|
final int p1x = pos1.getX();
|
||||||
final int p1z = pos1.getZ();
|
final int p1z = pos1.getZ();
|
||||||
@ -93,11 +108,17 @@ public class ChunkCoordinatorBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the consumer to be used when a chunk is loaded
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withConsumer(@Nonnull final Consumer<BlockVector2> chunkConsumer) {
|
@Nonnull public ChunkCoordinatorBuilder withConsumer(@Nonnull final Consumer<BlockVector2> chunkConsumer) {
|
||||||
this.chunkConsumer = Preconditions.checkNotNull(chunkConsumer, "Chunk consumer may not be null");
|
this.chunkConsumer = Preconditions.checkNotNull(chunkConsumer, "Chunk consumer may not be null");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Runnable to run when all chunks have been accessed
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withFinalAction(@Nullable final Runnable whenDone) {
|
@Nonnull public ChunkCoordinatorBuilder withFinalAction(@Nullable final Runnable whenDone) {
|
||||||
if (whenDone == null) {
|
if (whenDone == null) {
|
||||||
return this;
|
return this;
|
||||||
@ -106,28 +127,44 @@ public class ChunkCoordinatorBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the max time taken while iterating over and accessing loaded chunks
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withMaxIterationTime(final long maxIterationTime) {
|
@Nonnull public ChunkCoordinatorBuilder withMaxIterationTime(final long maxIterationTime) {
|
||||||
Preconditions.checkArgument(maxIterationTime > 0, "Max iteration time must be positive");
|
Preconditions.checkArgument(maxIterationTime > 0, "Max iteration time must be positive");
|
||||||
this.maxIterationTime = maxIterationTime;
|
this.maxIterationTime = maxIterationTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the initial batch size to be used for loading chunks
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withInitialBatchSize(final int initialBatchSize) {
|
@Nonnull public ChunkCoordinatorBuilder withInitialBatchSize(final int initialBatchSize) {
|
||||||
Preconditions.checkArgument(initialBatchSize > 0, "Initial batch size must be positive");
|
Preconditions.checkArgument(initialBatchSize > 0, "Initial batch size must be positive");
|
||||||
this.initialBatchSize = initialBatchSize;
|
this.initialBatchSize = initialBatchSize;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the consumer to be used to handle {@link Throwable}s
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder withThrowableConsumer(@Nonnull final Consumer<Throwable> throwableConsumer) {
|
@Nonnull public ChunkCoordinatorBuilder withThrowableConsumer(@Nonnull final Consumer<Throwable> throwableConsumer) {
|
||||||
this.throwableConsumer = Preconditions.checkNotNull(throwableConsumer, "Throwable consumer may not be null");
|
this.throwableConsumer = Preconditions.checkNotNull(throwableConsumer, "Throwable consumer may not be null");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the chunks should be allow to unload after being accessed. This should only be used where the chunks are read from
|
||||||
|
* and then written to from a separate queue where they're consequently unloaded.
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinatorBuilder unloadAfter(final boolean unloadAfter) {
|
@Nonnull public ChunkCoordinatorBuilder unloadAfter(final boolean unloadAfter) {
|
||||||
this.unloadAfter = unloadAfter;
|
this.unloadAfter = unloadAfter;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ChunkCoordinator} instance based on the values in the Builder instance.
|
||||||
|
*/
|
||||||
@Nonnull public ChunkCoordinator build() {
|
@Nonnull public ChunkCoordinator build() {
|
||||||
Preconditions.checkNotNull(this.world, "No world was supplied");
|
Preconditions.checkNotNull(this.world, "No world was supplied");
|
||||||
Preconditions.checkNotNull(this.chunkConsumer, "No chunk consumer was supplied");
|
Preconditions.checkNotNull(this.chunkConsumer, "No chunk consumer was supplied");
|
||||||
|
@ -36,6 +36,9 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue that is limited to a single chunk
|
||||||
|
*/
|
||||||
public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
|
public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
|
||||||
|
|
||||||
public final BiomeType[][][] biomeResult;
|
public final BiomeType[][][] biomeResult;
|
||||||
@ -127,7 +130,7 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public World getWorld() {
|
@Override @Nullable public World getWorld() {
|
||||||
return super.getWorld();
|
return super.getWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ import com.sk89q.worldedit.world.World;
|
|||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -43,6 +42,9 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue that delegates to a parent queue.
|
||||||
|
*/
|
||||||
public class DelegateQueueCoordinator extends QueueCoordinator {
|
public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||||
|
|
||||||
private final QueueCoordinator parent;
|
private final QueueCoordinator parent;
|
||||||
@ -180,6 +182,13 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable @Override public Consumer<BlockVector2> getChunkConsumer() {
|
||||||
|
if (parent != null) {
|
||||||
|
return parent.getChunkConsumer();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void setChunkConsumer(@Nonnull Consumer<BlockVector2> consumer) {
|
@Override public void setChunkConsumer(@Nonnull Consumer<BlockVector2> consumer) {
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.setChunkConsumer(consumer);
|
parent.setChunkConsumer(consumer);
|
||||||
|
@ -43,6 +43,9 @@ public class GlobalBlockQueue {
|
|||||||
this.activeQueues = new ConcurrentLinkedDeque<>();
|
this.activeQueues = new ConcurrentLinkedDeque<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new {@link QueueCoordinator} for the given world.
|
||||||
|
*/
|
||||||
@Nonnull public QueueCoordinator getNewQueue(@Nonnull World world) {
|
@Nonnull public QueueCoordinator getNewQueue(@Nonnull World world) {
|
||||||
QueueCoordinator queue = provider.getNewQueue(world);
|
QueueCoordinator queue = provider.getNewQueue(world);
|
||||||
// Auto-inject into the queue
|
// Auto-inject into the queue
|
||||||
|
@ -35,6 +35,9 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offsets input coordinates and delegates to a parent queue
|
||||||
|
*/
|
||||||
public class LocationOffsetDelegateQueueCoordinator extends DelegateQueueCoordinator {
|
public class LocationOffsetDelegateQueueCoordinator extends DelegateQueueCoordinator {
|
||||||
|
|
||||||
private final boolean[][] canPlace;
|
private final boolean[][] canPlace;
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* _____ _ _ _____ _
|
|
||||||
* | __ \| | | | / ____| | |
|
|
||||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
||||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
||||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
||||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
||||||
* | |
|
|
||||||
* |_|
|
|
||||||
* PlotSquared plot management system for Minecraft
|
|
||||||
* Copyright (C) 2020 IntellectualSites
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.plotsquared.core.queue;
|
|
||||||
|
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
|
||||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class OffsetQueueCoordinator extends DelegateQueueCoordinator {
|
|
||||||
private final int ox;
|
|
||||||
private final int oy;
|
|
||||||
private final int oz;
|
|
||||||
|
|
||||||
public OffsetQueueCoordinator(@Nonnull QueueCoordinator parent, int ox, int oy, int oz) {
|
|
||||||
super(parent);
|
|
||||||
this.ox = ox;
|
|
||||||
this.oy = oy;
|
|
||||||
this.oz = oz;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean setBiome(int x, int z, @Nonnull BiomeType biome) {
|
|
||||||
return super.setBiome(ox + x, oz + z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean setBiome(int x, int y, int z, @Nonnull BiomeType biome) {
|
|
||||||
return super.setBiome(ox + x, oy + y, oz + z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull BaseBlock id) {
|
|
||||||
return super.setBlock(ox + x, oy + y, oz + z, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull Pattern pattern) {
|
|
||||||
return super.setBlock(ox + x, oy + y, oz + z, pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean setTile(int x, int y, int z, @Nonnull CompoundTag tag) {
|
|
||||||
return super.setTile(ox + x, oy + y, oz + z, tag);
|
|
||||||
}
|
|
||||||
}
|
|
@ -56,6 +56,9 @@ public abstract class QueueCoordinator {
|
|||||||
PlotSquared.platform().getInjector().injectMembers(this);
|
PlotSquared.platform().getInjector().injectMembers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link ScopedQueueCoordinator} limited to the chunk at the specific chunk Coordinates
|
||||||
|
*/
|
||||||
public ScopedQueueCoordinator getForChunk(int x, int z) {
|
public ScopedQueueCoordinator getForChunk(int x, int z) {
|
||||||
int bx = x << 4;
|
int bx = x << 4;
|
||||||
int bz = z << 4;
|
int bz = z << 4;
|
||||||
@ -63,22 +66,40 @@ public abstract class QueueCoordinator {
|
|||||||
Location.at(getWorld().getName(), bx + 15, 255, bz + 255));
|
Location.at(getWorld().getName(), bx + 15, 255, bz + 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the size of the queue in chunks
|
||||||
|
*/
|
||||||
public abstract int size();
|
public abstract int size();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set when the queue was last modified
|
||||||
|
*/
|
||||||
public abstract void setModified(long modified);
|
public abstract void setModified(long modified);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the queue should be forced to be synchronous when enqueued.
|
||||||
|
*/
|
||||||
public boolean isForceSync() {
|
public boolean isForceSync() {
|
||||||
return forceSync;
|
return forceSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the queue should be forced to be synchronous
|
||||||
|
*/
|
||||||
public void setForceSync(boolean forceSync) {
|
public void setForceSync(boolean forceSync) {
|
||||||
this.forceSync = forceSync;
|
this.forceSync = forceSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Chunk Object set to the queue
|
||||||
|
*/
|
||||||
@Nullable public Object getChunkObject() {
|
@Nullable public Object getChunkObject() {
|
||||||
return chunkObject;
|
return chunkObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a chunk object (e.g. the Bukkit Chunk object) to the queue
|
||||||
|
*/
|
||||||
public void setChunkObject(@Nonnull Object chunkObject) {
|
public void setChunkObject(@Nonnull Object chunkObject) {
|
||||||
this.chunkObject = chunkObject;
|
this.chunkObject = chunkObject;
|
||||||
}
|
}
|
||||||
@ -89,70 +110,173 @@ public abstract class QueueCoordinator {
|
|||||||
* @param x the x coordinate from from 0 to 15 inclusive
|
* @param x the x coordinate from from 0 to 15 inclusive
|
||||||
* @param y the y coordinate from from 0 (inclusive) - maxHeight(exclusive)
|
* @param y the y coordinate from from 0 (inclusive) - maxHeight(exclusive)
|
||||||
* @param z the z coordinate from 0 to 15 inclusive
|
* @param z the z coordinate from 0 to 15 inclusive
|
||||||
* @param id the id to set the block to
|
* @param id the BlockState to set the block to
|
||||||
*/
|
*/
|
||||||
public abstract boolean setBlock(final int x, final int y, final int z, @Nonnull final BlockState id);
|
public abstract boolean setBlock(final int x, final int y, final int z, @Nonnull final BlockState id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the block at the coordinates provided to the given id.
|
||||||
|
*
|
||||||
|
* @param x the x coordinate from from 0 to 15 inclusive
|
||||||
|
* @param y the y coordinate from from 0 (inclusive) - maxHeight(exclusive)
|
||||||
|
* @param z the z coordinate from 0 to 15 inclusive
|
||||||
|
* @param id the BaseBlock to set the block to
|
||||||
|
*/
|
||||||
public abstract boolean setBlock(final int x, final int y, final int z, @Nonnull final BaseBlock id);
|
public abstract boolean setBlock(final int x, final int y, final int z, @Nonnull final BaseBlock id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the block at the coordinates provided to the given id.
|
||||||
|
*
|
||||||
|
* @param x the x coordinate from from 0 to 15 inclusive
|
||||||
|
* @param y the y coordinate from from 0 (inclusive) - maxHeight(exclusive)
|
||||||
|
* @param z the z coordinate from 0 to 15 inclusive
|
||||||
|
* @param pattern the pattern to set the block to
|
||||||
|
*/
|
||||||
public boolean setBlock(final int x, final int y, final int z, @Nonnull final Pattern pattern) {
|
public boolean setBlock(final int x, final int y, final int z, @Nonnull final Pattern pattern) {
|
||||||
return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z));
|
return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a tile entity at the coordinates provided to the given CompoundTag
|
||||||
|
*
|
||||||
|
* @param x the x coordinate from from 0 to 15 inclusive
|
||||||
|
* @param y the y coordinate from from 0 (inclusive) - maxHeight(exclusive)
|
||||||
|
* @param z the z coordinate from 0 to 15 inclusive
|
||||||
|
* @param tag the CompoundTag to set the tile to
|
||||||
|
*/
|
||||||
public abstract boolean setTile(int x, int y, int z, @Nonnull CompoundTag tag);
|
public abstract boolean setTile(int x, int y, int z, @Nonnull CompoundTag tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the queue has any tiles being set
|
||||||
|
*/
|
||||||
public abstract boolean isSettingTiles();
|
public abstract boolean isSettingTiles();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a block at the given coordinates.
|
||||||
|
*/
|
||||||
@Nullable public abstract BlockState getBlock(int x, int y, int z);
|
@Nullable public abstract BlockState getBlock(int x, int y, int z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a biome in XZ. This will likely set to the whole column
|
||||||
|
*/
|
||||||
@Deprecated public abstract boolean setBiome(int x, int z, @Nonnull BiomeType biome);
|
@Deprecated public abstract boolean setBiome(int x, int z, @Nonnull BiomeType biome);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a biome in XYZ
|
||||||
|
*/
|
||||||
public abstract boolean setBiome(int x, int y, int z, @Nonnull BiomeType biome);
|
public abstract boolean setBiome(int x, int y, int z, @Nonnull BiomeType biome);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the queue has any biomes to be set
|
||||||
|
*/
|
||||||
public abstract boolean isSettingBiomes();
|
public abstract boolean isSettingBiomes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add entities to be created
|
||||||
|
*/
|
||||||
public void addEntities(@Nonnull List<? extends Entity> entities) {
|
public void addEntities(@Nonnull List<? extends Entity> entities) {
|
||||||
for (Entity e : entities) {
|
for (Entity e : entities) {
|
||||||
this.setEntity(e);
|
this.setEntity(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an entity to be created
|
||||||
|
*/
|
||||||
public abstract boolean setEntity(@Nonnull Entity entity);
|
public abstract boolean setEntity(@Nonnull Entity entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of chunks that are added manually. This usually indicated the queue is "read only".
|
||||||
|
*/
|
||||||
@Nonnull public abstract List<BlockVector2> getReadChunks();
|
@Nonnull public abstract List<BlockVector2> getReadChunks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a set of {@link BlockVector2} Chunk coordinates to the Read Chunks list
|
||||||
|
*/
|
||||||
public abstract void addReadChunks(@Nonnull Set<BlockVector2> readChunks);
|
public abstract void addReadChunks(@Nonnull Set<BlockVector2> readChunks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a {@link BlockVector2} Chunk coordinate to the Read Chunks list
|
||||||
|
*/
|
||||||
public abstract void addReadChunk(@Nonnull BlockVector2 chunk);
|
public abstract void addReadChunk(@Nonnull BlockVector2 chunk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether chunks should be unloaded after being accessed
|
||||||
|
*/
|
||||||
public abstract boolean isUnloadAfter();
|
public abstract boolean isUnloadAfter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether chunks should be unloaded after being accessed
|
||||||
|
*/
|
||||||
public abstract void setUnloadAfter(boolean unloadAfter);
|
public abstract void setUnloadAfter(boolean unloadAfter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link CuboidRegion} designated for direct regeneration
|
||||||
|
*/
|
||||||
@Nullable public abstract CuboidRegion getRegenRegion();
|
@Nullable public abstract CuboidRegion getRegenRegion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link CuboidRegion} designated for direct regeneration
|
||||||
|
*/
|
||||||
public abstract void setRegenRegion(@Nonnull CuboidRegion regenRegion);
|
public abstract void setRegenRegion(@Nonnull CuboidRegion regenRegion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a specific chunk at the chunk coordinates XZ to be regenerated.
|
||||||
|
*/
|
||||||
public abstract void regenChunk(int x, int z);
|
public abstract void regenChunk(int x, int z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the world the queue is writing to
|
||||||
|
*/
|
||||||
@Nullable public abstract World getWorld();
|
@Nullable public abstract World getWorld();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the queue as having been modified now
|
||||||
|
*/
|
||||||
public final void setModified() {
|
public final void setModified() {
|
||||||
setModified(System.currentTimeMillis());
|
setModified(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue the queue with the {@link GlobalBlockQueue}
|
||||||
|
*/
|
||||||
public boolean enqueue() {
|
public boolean enqueue() {
|
||||||
return blockQueue.enqueue(this);
|
return blockQueue.enqueue(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the queue
|
||||||
|
*/
|
||||||
public abstract void start();
|
public abstract void start();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the queue. Not yet implemented.
|
||||||
|
*/
|
||||||
public abstract void cancel();
|
public abstract void cancel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the task to be run when all chunks have been accessed
|
||||||
|
*/
|
||||||
|
public abstract Runnable getCompleteTask();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the task to be run when all chunks have been accessed
|
||||||
|
*/
|
||||||
public abstract void setCompleteTask(@Nullable Runnable whenDone);
|
public abstract void setCompleteTask(@Nullable Runnable whenDone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the chunk consumer set to the queue or null if one is not set
|
||||||
|
*/
|
||||||
|
@Nullable public abstract Consumer<BlockVector2> getChunkConsumer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Consumer that will
|
||||||
|
*/
|
||||||
public abstract void setChunkConsumer(@Nonnull Consumer<BlockVector2> consumer);
|
public abstract void setChunkConsumer(@Nonnull Consumer<BlockVector2> consumer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill a cuboid between two positions with a BlockState
|
||||||
|
*/
|
||||||
public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BlockState block) {
|
public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BlockState block) {
|
||||||
int yMin = Math.min(pos1.getY(), pos2.getY());
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
||||||
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
||||||
@ -169,6 +293,9 @@ public abstract class QueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill a cuboid between two positions with a Pattern
|
||||||
|
*/
|
||||||
public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull Pattern blocks) {
|
public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull Pattern blocks) {
|
||||||
int yMin = Math.min(pos1.getY(), pos2.getY());
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
||||||
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
||||||
@ -185,6 +312,9 @@ public abstract class QueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill a cuboid between two positions with a BiomeType
|
||||||
|
*/
|
||||||
public void setBiomeCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BiomeType biome) {
|
public void setBiomeCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BiomeType biome) {
|
||||||
int yMin = Math.min(pos1.getY(), pos2.getY());
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
||||||
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
||||||
|
@ -44,5 +44,8 @@ public abstract class QueueProvider {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a queue for the given world
|
||||||
|
*/
|
||||||
public abstract QueueCoordinator getNewQueue(@Nonnull World world);
|
public abstract QueueCoordinator getNewQueue(@Nonnull World world);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,9 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue that only sets blocks with a designated area
|
||||||
|
*/
|
||||||
public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
|
public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
|
||||||
private final int minX;
|
private final int minX;
|
||||||
private final int minY;
|
private final int minY;
|
||||||
|
Loading…
Reference in New Issue
Block a user