2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* 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/>.
|
|
|
|
*/
|
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-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;
|
2020-07-18 13:07:56 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-07-17 14:22:33 +02:00
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
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;
|
|
|
|
@Nullable private Object chunkObject;
|
2020-04-08 01:23:22 +02:00
|
|
|
|
2020-07-12 12:25:44 +02:00
|
|
|
@Inject private GlobalBlockQueue blockQueue;
|
2020-07-10 22:12:37 +02:00
|
|
|
|
2020-07-17 14:22:33 +02:00
|
|
|
public QueueCoordinator() {
|
2020-07-10 22:12:37 +02:00
|
|
|
PlotSquared.platform().getInjector().injectMembers(this);
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
public ScopedQueueCoordinator getForChunk(int x, int z) {
|
|
|
|
int bx = x << 4;
|
|
|
|
int bz = z << 4;
|
|
|
|
return new ScopedQueueCoordinator(this, Location.at(getWorld().getName(), bx, 0, bz),
|
|
|
|
Location.at(getWorld().getName(), bx + 15, 255, bz + 255));
|
|
|
|
}
|
|
|
|
|
2016-06-13 06:47:50 +02:00
|
|
|
public abstract int size();
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
public abstract void setModified(long modified);
|
|
|
|
|
2020-07-18 13:07:56 +02:00
|
|
|
public boolean isForceSync() {
|
|
|
|
return forceSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setForceSync(boolean forceSync) {
|
|
|
|
this.forceSync = forceSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable public Object getChunkObject() {
|
|
|
|
return chunkObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChunkObject(@NotNull Object chunkObject) {
|
|
|
|
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
|
2019-04-29 21:19:49 +02:00
|
|
|
* @param id the id to set the block to
|
|
|
|
*/
|
2019-11-04 20:55:55 +01:00
|
|
|
public abstract boolean setBlock(final int x, final int y, final int z, final BlockState id);
|
2018-12-17 20:57:21 +01:00
|
|
|
|
2018-12-20 00:18:57 +01:00
|
|
|
public abstract boolean setBlock(final int x, final int y, final int z, final BaseBlock id);
|
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
public boolean setBlock(final int x, final int y, final int z, @Nonnull final Pattern pattern) {
|
2019-11-10 18:47:37 +01:00
|
|
|
return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z));
|
|
|
|
}
|
|
|
|
|
2020-07-17 14:22:33 +02:00
|
|
|
public abstract boolean setTile(int x, int y, int z, CompoundTag tag);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-17 15:38:50 +02:00
|
|
|
public abstract boolean isSettingTiles();
|
|
|
|
|
2019-11-04 20:55:55 +01:00
|
|
|
public abstract BlockState getBlock(int x, int y, int z);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
@Deprecated public abstract boolean setBiome(int x, int z, BiomeType biome);
|
|
|
|
|
|
|
|
public abstract boolean setBiome(int x, int y, int z, BiomeType biome);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-07-17 15:38:50 +02:00
|
|
|
public abstract boolean isSettingBiomes();
|
2020-03-24 09:08:56 +01:00
|
|
|
|
2020-07-23 18:30:23 +02:00
|
|
|
public void addEntities(List<? extends Entity> entities) {
|
|
|
|
for (Entity e : entities) {
|
|
|
|
this.setEntity(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract boolean setEntity(Entity entity);
|
|
|
|
|
2020-07-24 15:36:50 +02:00
|
|
|
public abstract List<BlockVector2> getReadChunks();
|
2020-07-23 18:30:23 +02:00
|
|
|
|
2020-07-24 15:36:50 +02:00
|
|
|
public abstract void addReadChunks(Set<BlockVector2> readChunks);
|
2020-07-23 18:30:23 +02:00
|
|
|
|
2020-07-24 15:36:50 +02:00
|
|
|
public abstract void addReadChunk(BlockVector2 chunk);
|
2020-07-23 18:30:23 +02:00
|
|
|
|
|
|
|
public abstract boolean isUnloadAfter();
|
|
|
|
|
2020-07-24 15:36:50 +02:00
|
|
|
public abstract void setUnloadAfter(boolean unloadAfter);
|
|
|
|
|
2020-07-24 16:17:42 +02:00
|
|
|
public abstract CuboidRegion getRegenRegion();
|
|
|
|
|
|
|
|
public abstract void setRegenRegion(CuboidRegion regenRegion);
|
|
|
|
|
2020-07-19 14:12:27 +02:00
|
|
|
public abstract void regenChunk(int x, int z);
|
|
|
|
|
2020-07-17 15:38:50 +02:00
|
|
|
public abstract World getWorld();
|
2016-06-13 06:47:50 +02:00
|
|
|
|
|
|
|
public final void setModified() {
|
|
|
|
setModified(System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2019-09-08 20:02:45 +02:00
|
|
|
public boolean enqueue() {
|
2020-07-17 15:38:50 +02:00
|
|
|
return blockQueue.enqueue(this);
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 14:12:27 +02:00
|
|
|
public abstract void start();
|
|
|
|
|
|
|
|
public abstract void cancel();
|
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
public abstract void setCompleteTask(Runnable whenDone);
|
|
|
|
|
2020-07-18 13:07:56 +02:00
|
|
|
public abstract void setChunkConsumer(Consumer<BlockVector2> consumer);
|
|
|
|
|
2019-11-04 20:55:55 +01:00
|
|
|
public void setCuboid(Location pos1, Location pos2, BlockState block) {
|
2019-06-01 14:43:29 +02:00
|
|
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
|
|
|
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 18:47:37 +01:00
|
|
|
public void setCuboid(Location pos1, Location pos2, Pattern blocks) {
|
2019-06-01 14:43:29 +02:00
|
|
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
|
|
|
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
|
|
|
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
|
|
|
|
|
|
|
public void setBiomeCuboid(Location pos1, Location pos2, BiomeType biome) {
|
|
|
|
int yMin = Math.min(pos1.getY(), pos2.getY());
|
|
|
|
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|