2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
2022-01-02 22:22:19 +01:00
|
|
|
* Copyright (C) 2014 - 2022 IntellectualSites
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
|
|
|
* 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
|
2020-08-15 14:59:29 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.queue;
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-12 12:25:44 +02:00
|
|
|
import com.google.inject.Inject;
|
2020-05-19 23:05:36 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
2020-08-17 17:21:11 +02:00
|
|
|
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.util.PatternUtil;
|
2018-12-20 00:18:57 +01:00
|
|
|
import com.sk89q.jnbt.CompoundTag;
|
2020-07-23 18:30:23 +02:00
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2019-11-10 18:47:37 +01:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2020-07-18 13:07:56 +02:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
2020-07-24 16:17:42 +02:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2020-07-17 15:38:50 +02:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-11-10 18:47:37 +01:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2018-12-20 00:18:57 +01:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
2019-11-04 20:58:24 +01:00
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
2021-12-14 23:04:36 +01:00
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2020-07-17 14:22:33 +02:00
|
|
|
|
2020-07-23 18:30:23 +02:00
|
|
|
import java.util.List;
|
2020-07-24 15:36:50 +02:00
|
|
|
import java.util.Set;
|
2020-07-18 13:07:56 +02:00
|
|
|
import java.util.function.Consumer;
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2020-07-17 14:22:33 +02:00
|
|
|
public abstract class QueueCoordinator {
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-18 13:07:56 +02:00
|
|
|
private boolean forceSync = false;
|
2021-01-09 22:28:41 +01:00
|
|
|
@Nullable
|
|
|
|
private Object chunkObject;
|
2021-12-14 23:04:36 +01:00
|
|
|
private final AtomicBoolean enqueued = new AtomicBoolean();
|
|
|
|
|
2022-01-20 21:01:38 +01:00
|
|
|
@SuppressWarnings({"unused", "FieldCanBeLocal"})
|
2021-01-09 22:28:41 +01:00
|
|
|
@Inject
|
|
|
|
private GlobalBlockQueue blockQueue;
|
2020-07-10 22:12:37 +02:00
|
|
|
|
2020-07-28 09:34:14 +02:00
|
|
|
/**
|
|
|
|
* Default constructor requires world to indicate any extents given to {@link QueueCoordinator} also need this constructor.
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param world world as all queues should have this constructor
|
2020-07-28 09:34:14 +02:00
|
|
|
*/
|
|
|
|
public QueueCoordinator(@Nullable World world) {
|
2020-12-05 18:41:25 +01:00
|
|
|
PlotSquared.platform().injector().injectMembers(this);
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get a {@link ScopedQueueCoordinator} limited to the chunk at the specific chunk Coordinates
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param x chunk x coordinate
|
|
|
|
* @param z chunk z coordinate
|
|
|
|
* @return a new {@link ScopedQueueCoordinator}
|
2022-03-05 19:03:39 +01:00
|
|
|
* @deprecated Use {@link ScopedQueueCoordinator#getForChunk(int, int, int, int)}
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2022-03-05 19:03:39 +01:00
|
|
|
@Deprecated(forRemoval = true, since = "TODO")
|
2020-07-17 16:41:06 +02:00
|
|
|
public ScopedQueueCoordinator getForChunk(int x, int z) {
|
2022-03-05 19:03:39 +01:00
|
|
|
if (getWorld() == null) {
|
|
|
|
return getForChunk(x, z, PlotSquared.platform().versionMinHeight(), PlotSquared.platform().versionMaxHeight());
|
|
|
|
}
|
|
|
|
return getForChunk(x, z, getWorld().getMinY(), getWorld().getMaxY());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a {@link ScopedQueueCoordinator} limited to the chunk at the specific chunk Coordinates
|
|
|
|
*
|
|
|
|
* @param x chunk x coordinate
|
|
|
|
* @param z chunk z coordinate
|
|
|
|
* @return a new {@link ScopedQueueCoordinator}
|
|
|
|
* @since TODO
|
|
|
|
*/
|
|
|
|
public ScopedQueueCoordinator getForChunk(int x, int z, int minY, int maxY) {
|
2020-07-17 16:41:06 +02:00
|
|
|
int bx = x << 4;
|
|
|
|
int bz = z << 4;
|
2022-03-05 19:03:39 +01:00
|
|
|
return new ScopedQueueCoordinator(this, Location.at(getWorld().getName(), bx, minY, bz),
|
|
|
|
Location.at(getWorld().getName(), bx + 15, maxY, bz + 15)
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2020-07-17 16:41:06 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get the size of the queue in chunks
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return size
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2016-06-13 06:47:50 +02:00
|
|
|
public abstract int size();
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set when the queue was last modified
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param modified long of system millis
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2018-08-10 17:01:10 +02:00
|
|
|
public abstract void setModified(long modified);
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the queue should be forced to be synchronous when enqueued.
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return is force sync
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-18 13:07:56 +02:00
|
|
|
public boolean isForceSync() {
|
|
|
|
return forceSync;
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set whether the queue should be forced to be synchronous
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param forceSync force sync or not
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-18 13:07:56 +02:00
|
|
|
public void setForceSync(boolean forceSync) {
|
|
|
|
this.forceSync = forceSync;
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get the Chunk Object set to the queue
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return chunk object. Usually the implementation-specific chunk (e.g. bukkit Chunk)
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @Nullable Object getChunkObject() {
|
2020-07-18 13:07:56 +02:00
|
|
|
return chunkObject;
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set a chunk object (e.g. the Bukkit Chunk object) to the queue
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param chunkObject chunk object. Usually the implementation-specific chunk (e.g. bukkit Chunk)
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void setChunkObject(@NonNull Object chunkObject) {
|
2020-07-18 13:07:56 +02:00
|
|
|
this.chunkObject = chunkObject;
|
|
|
|
}
|
|
|
|
|
2019-04-29 21:19:49 +02:00
|
|
|
/**
|
|
|
|
* Sets the block at the coordinates provided to the given id.
|
|
|
|
*
|
2020-02-24 18:42:02 +01:00
|
|
|
* @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
|
2020-07-24 18:00:08 +02:00
|
|
|
* @param id the BlockState to set the block to
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2019-04-29 21:19:49 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setBlock(final int x, final int y, final int z, final @NonNull BlockState id);
|
2018-12-17 20:57:21 +01:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setBlock(final int x, final int y, final int z, final @NonNull BaseBlock id);
|
2018-12-20 00:18:57 +01:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public boolean setBlock(final int x, final int y, final int z, final @NonNull Pattern pattern) {
|
2019-11-10 18:47:37 +01:00
|
|
|
return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z));
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setTile(int x, int y, int z, @NonNull CompoundTag tag);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Whether the queue has any tiles being set
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return if setting tiles
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-17 15:38:50 +02:00
|
|
|
public abstract boolean isSettingTiles();
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get a block at the given coordinates.
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param x block x
|
|
|
|
* @param y block y
|
|
|
|
* @param z block z
|
|
|
|
* @return WorldEdit BlockState
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-08-18 11:58:18 +02:00
|
|
|
public @Nullable
|
|
|
|
abstract BlockState getBlock(int x, int y, int z);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set a biome in XZ. This will likely set to the whole column
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param x x coordinate
|
|
|
|
* @param z z coordinate
|
|
|
|
* @param biome biome
|
|
|
|
* @return success or not
|
2021-08-11 17:58:24 +02:00
|
|
|
* @deprecated Biomes now take XYZ, see {@link #setBiome(int, int, int, BiomeType)}
|
2021-12-14 23:04:36 +01:00
|
|
|
* <br>
|
|
|
|
* Scheduled for removal once we drop the support for versions not supporting 3D biomes.
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2022-01-24 21:46:01 +01:00
|
|
|
@Deprecated(forRemoval = true, since = "6.0.0")
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setBiome(int x, int z, @NonNull BiomeType biome);
|
2020-07-17 16:41:06 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set a biome in XYZ
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param x x coordinate
|
|
|
|
* @param y y coordinate
|
|
|
|
* @param z z coordinate
|
|
|
|
* @param biome biome
|
|
|
|
* @return success or not
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setBiome(int x, int y, int z, @NonNull BiomeType biome);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Whether the queue has any biomes to be set
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return if setting biomes
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-17 15:38:50 +02:00
|
|
|
public abstract boolean isSettingBiomes();
|
2020-03-24 09:08:56 +01:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Add entities to be created
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param entities list of entities to add to queue
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void addEntities(@NonNull List<? extends Entity> entities) {
|
2020-07-23 18:30:23 +02:00
|
|
|
for (Entity e : entities) {
|
|
|
|
this.setEntity(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Add an entity to be created
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param entity entity to add to queue
|
|
|
|
* @return success or not
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setEntity(@NonNull Entity entity);
|
2020-07-23 18:30:23 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get the list of chunks that are added manually. This usually indicated the queue is "read only".
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return list of BlockVector2 of chunks that are to be "read"
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-08-18 11:58:18 +02:00
|
|
|
public @NonNull
|
|
|
|
abstract List<BlockVector2> getReadChunks();
|
2020-07-23 18:30:23 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Add a set of {@link BlockVector2} Chunk coordinates to the Read Chunks list
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param readChunks set of BlockVector2 to add to "read" chunks
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract void addReadChunks(@NonNull Set<BlockVector2> readChunks);
|
2020-07-23 18:30:23 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Add a {@link BlockVector2} Chunk coordinate to the Read Chunks list
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param chunk BlockVector2 to add to "read" chunks
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract void addReadChunk(@NonNull BlockVector2 chunk);
|
2020-07-23 18:30:23 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Whether chunks should be unloaded after being accessed
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return if is unloading chunks after accessing them
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-23 18:30:23 +02:00
|
|
|
public abstract boolean isUnloadAfter();
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set whether chunks should be unloaded after being accessed
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param unloadAfter if to unload chunks after being accessed
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-24 15:36:50 +02:00
|
|
|
public abstract void setUnloadAfter(boolean unloadAfter);
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get the {@link CuboidRegion} designated for direct regeneration
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return CuboidRegion to regenerate
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-08-18 11:58:18 +02:00
|
|
|
public @Nullable
|
|
|
|
abstract CuboidRegion getRegenRegion();
|
2020-07-24 16:17:42 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set the {@link CuboidRegion} designated for direct regeneration
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param regenRegion CuboidRegion to regenerate
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract void setRegenRegion(@NonNull CuboidRegion regenRegion);
|
2020-07-24 16:17:42 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set a specific chunk at the chunk coordinates XZ to be regenerated.
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param x chunk x
|
|
|
|
* @param z chunk z
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-19 14:12:27 +02:00
|
|
|
public abstract void regenChunk(int x, int z);
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get the world the queue is writing to
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return world of the queue
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-08-18 11:58:18 +02:00
|
|
|
public @Nullable
|
|
|
|
abstract World getWorld();
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Set the queue as having been modified now
|
|
|
|
*/
|
2016-06-13 06:47:50 +02:00
|
|
|
public final void setModified() {
|
|
|
|
setModified(System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
2021-08-19 13:31:47 +02:00
|
|
|
* Enqueue the queue to start it
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return success or not
|
2022-01-24 21:46:01 +01:00
|
|
|
* @since 6.0.10
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2019-09-08 20:02:45 +02:00
|
|
|
public boolean enqueue() {
|
2021-08-19 13:31:47 +02:00
|
|
|
boolean success = false;
|
|
|
|
if (enqueued.compareAndSet(false, true)) {
|
|
|
|
success = true;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
return success;
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Start the queue
|
|
|
|
*/
|
2020-07-19 14:12:27 +02:00
|
|
|
public abstract void start();
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
2021-08-19 13:31:47 +02:00
|
|
|
* Cancel the queue
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-19 14:12:27 +02:00
|
|
|
public abstract void cancel();
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Get the task to be run when all chunks have been accessed
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return task to be run when queue is complete
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
|
|
|
public abstract Runnable getCompleteTask();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the task to be run when all chunks have been accessed
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param whenDone task to be run when queue is complete
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2020-07-24 17:24:53 +02:00
|
|
|
public abstract void setCompleteTask(@Nullable Runnable whenDone);
|
2020-07-17 16:41:06 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Return the chunk consumer set to the queue or null if one is not set
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @return Consumer to be executed on each chunk in queue
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-08-18 11:58:18 +02:00
|
|
|
public @Nullable
|
|
|
|
abstract Consumer<BlockVector2> getChunkConsumer();
|
2020-07-24 18:00:08 +02:00
|
|
|
|
|
|
|
/**
|
2020-08-16 14:22:49 +02:00
|
|
|
* Set the Consumer that will be executed on each chunk in queue
|
|
|
|
*
|
|
|
|
* @param consumer Consumer to be executed on each chunk in queue
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract void setChunkConsumer(@NonNull Consumer<BlockVector2> consumer);
|
2020-07-18 13:07:56 +02:00
|
|
|
|
2020-08-17 17:21:11 +02:00
|
|
|
/**
|
|
|
|
* Add a {@link ProgressSubscriber} to the Queue to subscribe to the relevant Chunk Processor
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract void addProgressSubscriber(@NonNull ProgressSubscriber progressSubscriber);
|
2020-08-17 17:21:11 +02:00
|
|
|
|
2020-09-11 15:18:50 +02:00
|
|
|
/**
|
|
|
|
* Get the {@link LightingMode} to be used when setting blocks
|
|
|
|
*/
|
2021-08-18 11:58:18 +02:00
|
|
|
public @NonNull
|
|
|
|
abstract LightingMode getLightingMode();
|
2020-09-11 15:18:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the {@link LightingMode} to be used when setting blocks
|
|
|
|
*
|
|
|
|
* @param mode lighting mode. Null to use default.
|
|
|
|
*/
|
|
|
|
public abstract void setLightingMode(@Nullable LightingMode mode);
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Fill a cuboid between two positions with a BlockState
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param pos1 1st cuboid position
|
|
|
|
* @param pos2 2nd cuboid position
|
|
|
|
* @param block block to fill
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void setCuboid(@NonNull Location pos1, @NonNull Location pos2, @NonNull BlockState block) {
|
2019-06-01 14:43:29 +02:00
|
|
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
2022-03-05 19:03:39 +01:00
|
|
|
int yMax = Math.max(pos1.getY(), pos2.getY());
|
2019-06-01 14:43:29 +02:00
|
|
|
int xMin = Math.min(pos1.getX(), pos2.getX());
|
|
|
|
int xMax = Math.max(pos1.getX(), pos2.getX());
|
|
|
|
int zMin = Math.min(pos1.getZ(), pos2.getZ());
|
|
|
|
int zMax = Math.max(pos1.getZ(), pos2.getZ());
|
|
|
|
for (int y = yMin; y <= yMax; y++) {
|
|
|
|
for (int x = xMin; x <= xMax; x++) {
|
|
|
|
for (int z = zMin; z <= zMax; z++) {
|
2016-06-13 06:47:50 +02:00
|
|
|
setBlock(x, y, z, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Fill a cuboid between two positions with a Pattern
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param pos1 1st cuboid position
|
|
|
|
* @param pos2 2nd cuboid position
|
|
|
|
* @param blocks pattern to fill
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void setCuboid(@NonNull Location pos1, @NonNull Location pos2, @NonNull Pattern blocks) {
|
2019-06-01 14:43:29 +02:00
|
|
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
2022-03-05 19:03:39 +01:00
|
|
|
int yMax = Math.max(pos1.getY(), pos2.getY());
|
2019-06-01 14:43:29 +02:00
|
|
|
int xMin = Math.min(pos1.getX(), pos2.getX());
|
|
|
|
int xMax = Math.max(pos1.getX(), pos2.getX());
|
|
|
|
int zMin = Math.min(pos1.getZ(), pos2.getZ());
|
|
|
|
int zMax = Math.max(pos1.getZ(), pos2.getZ());
|
|
|
|
for (int y = yMin; y <= yMax; y++) {
|
|
|
|
for (int x = xMin; x <= xMax; x++) {
|
|
|
|
for (int z = zMin; z <= zMax; z++) {
|
2019-11-10 18:47:37 +01:00
|
|
|
setBlock(x, y, z, blocks);
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-24 16:17:42 +02:00
|
|
|
|
2020-07-24 18:00:08 +02:00
|
|
|
/**
|
|
|
|
* Fill a cuboid between two positions with a BiomeType
|
2020-08-16 14:22:49 +02:00
|
|
|
*
|
|
|
|
* @param pos1 1st cuboid position
|
|
|
|
* @param pos2 2nd cuboid position
|
|
|
|
* @param biome biome to fill
|
2020-07-24 18:00:08 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void setBiomeCuboid(@NonNull Location pos1, @NonNull Location pos2, @NonNull BiomeType biome) {
|
2020-07-24 16:17:42 +02:00
|
|
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
2022-03-05 19:03:39 +01:00
|
|
|
int yMax = Math.max(pos1.getY(), pos2.getY());
|
2020-07-24 16:17:42 +02:00
|
|
|
int xMin = Math.min(pos1.getX(), pos2.getX());
|
|
|
|
int xMax = Math.max(pos1.getX(), pos2.getX());
|
|
|
|
int zMin = Math.min(pos1.getZ(), pos2.getZ());
|
|
|
|
int zMax = Math.max(pos1.getZ(), pos2.getZ());
|
|
|
|
for (int y = yMin; y <= yMax; y++) {
|
|
|
|
for (int x = xMin; x <= xMax; x++) {
|
|
|
|
for (int z = zMin; z <= zMax; z++) {
|
|
|
|
setBiome(x, y, z, biome);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2022-03-05 19:03:39 +01:00
|
|
|
/**
|
|
|
|
* Get the min Y limit associated with the queue
|
|
|
|
*/
|
|
|
|
protected int getMinY() {
|
|
|
|
return getWorld() != null ? getWorld().getMinY() : PlotSquared.platform().versionMinHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the max Y limit associated with the queue
|
|
|
|
*/
|
|
|
|
protected int getMaxY() {
|
|
|
|
return getWorld() != null ? getWorld().getMinY() : PlotSquared.platform().versionMaxHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the min chunk layer associated with the queue. Usually 0 or -4;
|
|
|
|
*/
|
|
|
|
protected int getMinLayer() {
|
|
|
|
return (getWorld() != null ? getWorld().getMinY() : PlotSquared.platform().versionMinHeight()) >> 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the max chunk layer associated with the queue. Usually 15 or 19
|
|
|
|
*/
|
|
|
|
protected int getMaxLayer() {
|
|
|
|
return (getWorld() != null ? getWorld().getMaxY() : PlotSquared.platform().versionMaxHeight()) >> 4;
|
|
|
|
}
|
|
|
|
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|