2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.queue;
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
|
|
|
import com.plotsquared.core.util.SchematicHandler;
|
|
|
|
import com.plotsquared.core.util.StringMan;
|
|
|
|
import com.plotsquared.core.util.uuid.UUIDHandler;
|
|
|
|
import com.plotsquared.core.util.WorldUtil;
|
|
|
|
import com.plotsquared.core.util.PatternUtil;
|
2018-12-20 00:18:57 +01:00
|
|
|
import com.sk89q.jnbt.CompoundTag;
|
2019-11-10 18:47:37 +01:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2019-11-04 18:44:23 +01:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
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-04-08 01:23:22 +02:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2020-04-07 20:19:39 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-04-08 01:23:22 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2016-06-13 06:47:50 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public abstract class LocalBlockQueue {
|
|
|
|
|
2020-04-08 01:23:22 +02:00
|
|
|
@Getter @Setter private boolean forceSync = false;
|
|
|
|
@Getter @Setter @Nullable private Object chunkObject;
|
|
|
|
|
2019-09-08 20:02:45 +02:00
|
|
|
/**
|
|
|
|
* Needed for compatibility with FAWE.
|
|
|
|
*
|
|
|
|
* @param world unused
|
|
|
|
*/
|
|
|
|
@Deprecated public LocalBlockQueue(String world) {
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ScopedLocalBlockQueue getForChunk(int x, int z) {
|
2016-06-18 04:44:56 +02:00
|
|
|
int bx = x << 4;
|
|
|
|
int bz = z << 4;
|
2018-08-10 17:01:10 +02:00
|
|
|
return new ScopedLocalBlockQueue(this, new Location(getWorld(), bx, 0, bz),
|
|
|
|
new Location(getWorld(), bx + 15, 255, bz + 15));
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract boolean next();
|
|
|
|
|
|
|
|
public abstract void startSet(boolean parallel);
|
|
|
|
|
|
|
|
public abstract void endSet(boolean parallel);
|
|
|
|
|
|
|
|
public abstract int size();
|
|
|
|
|
|
|
|
public abstract void optimize();
|
|
|
|
|
|
|
|
public abstract long getModified();
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
public abstract void setModified(long modified);
|
|
|
|
|
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-02-11 23:06:58 +01:00
|
|
|
public boolean setBlock(final int x, final int y, final int z, @NotNull final Pattern pattern) {
|
2019-11-10 18:47:37 +01:00
|
|
|
return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z));
|
|
|
|
}
|
|
|
|
|
2016-06-16 02:31:25 +02:00
|
|
|
public boolean setTile(int x, int y, int z, CompoundTag tag) {
|
|
|
|
SchematicHandler.manager.restoreTile(this, tag, x, y, z);
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-13 06:47:50 +02:00
|
|
|
|
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
|
|
|
|
2019-11-10 18:47:37 +01:00
|
|
|
public abstract boolean setBiome(int x, int z, BiomeType biome);
|
2016-06-13 06:47:50 +02:00
|
|
|
|
2020-03-24 09:08:56 +01:00
|
|
|
public abstract boolean setBiome();
|
|
|
|
|
2016-06-13 06:47:50 +02:00
|
|
|
public abstract String getWorld();
|
|
|
|
|
|
|
|
public abstract void flush();
|
|
|
|
|
|
|
|
public final void setModified() {
|
|
|
|
setModified(System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void refreshChunk(int x, int z);
|
|
|
|
|
|
|
|
public abstract void fixChunkLighting(int x, int z);
|
|
|
|
|
|
|
|
public abstract void regenChunk(int x, int z);
|
|
|
|
|
|
|
|
public final void regenChunkSafe(int x, int z) {
|
|
|
|
regenChunk(x, z);
|
|
|
|
fixChunkLighting(x, z);
|
2019-11-04 18:44:23 +01:00
|
|
|
BlockVector2 loc = BlockVector2.at(x, z);
|
2016-06-13 06:47:50 +02:00
|
|
|
for (Map.Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
|
|
|
PlotPlayer pp = entry.getValue();
|
|
|
|
Location pLoc = pp.getLocation();
|
2019-11-04 18:44:23 +01:00
|
|
|
if (!StringMan.isEqual(getWorld(), pLoc.getWorld()) || !pLoc.getBlockVector2()
|
2018-08-10 17:01:10 +02:00
|
|
|
.equals(loc)) {
|
2016-06-13 06:47:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-07 20:19:39 +02:00
|
|
|
pLoc.setY(WorldUtil.IMP.getHighestBlockSynchronous(getWorld(), pLoc.getX(), pLoc.getZ()));
|
2016-06-13 06:47:50 +02:00
|
|
|
pp.teleport(pLoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 20:02:45 +02:00
|
|
|
public boolean enqueue() {
|
|
|
|
return GlobalBlockQueue.IMP.enqueue(this);
|
2016-06-13 06:47:50 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|