Switch to using QueueCoordinators everywhere

This commit is contained in:
dordsor21
2020-07-17 15:41:06 +01:00
parent ed77522c08
commit 9fefe57c90
33 changed files with 485 additions and 355 deletions

View File

@ -28,7 +28,7 @@ package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal2;
@ -50,12 +50,13 @@ public class Relight extends Command {
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
final Plot plot = player.getCurrentPlot();
player.sendMessage("Not implemented.");
/* final Plot plot = player.getCurrentPlot();
if (plot == null) {
Captions.NOT_IN_PLOT.send(player);
return CompletableFuture.completedFuture(false);
}
final LocalBlockQueue queue = plot.getArea().getQueue(false);
final QueueCoordinator queue = plot.getArea().getQueue(false);
ChunkManager.chunkTask(plot, new RunnableVal<int[]>() {
@Override public void run(int[] value) {
queue.fixChunkLighting(value[0], value[1]);
@ -63,7 +64,7 @@ public class Relight extends Command {
}, () -> {
plot.refreshChunks();
Captions.SET_BLOCK_ACTION_FINISHED.send(player);
}, 5);
}, 5);*/
return CompletableFuture.completedFuture(true);
}

View File

@ -34,7 +34,7 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.RegionUtil;
@ -188,7 +188,7 @@ public class Trim extends SubCommand {
}
}
}
final LocalBlockQueue queue = blockQueue.getNewQueue(world, false);
final QueueCoordinator queue = blockQueue.getNewQueue(world, false);
TaskManager.objectTask(chunks, new RunnableVal<BlockVector2>() {
@Override public void run(BlockVector2 value) {
queue.regenChunk(value.getX(), value.getZ());

View File

@ -31,17 +31,17 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.queue.AreaBoundDelegateLocalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.LocationOffsetDelegateLocalBlockQueue;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.queue.AreaBoundDelegateQueueCoordinator;
import com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.RegionUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Set;
public class AugmentedUtils {
@ -55,7 +55,7 @@ public class AugmentedUtils {
}
public static boolean generate(@Nullable Object chunkObject, @Nonnull final String world,
final int chunkX, final int chunkZ, LocalBlockQueue queue) {
final int chunkX, final int chunkZ, QueueCoordinator queue) {
if (!enabled) {
return false;
}
@ -67,7 +67,8 @@ public class AugmentedUtils {
// entire chunk
CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15);
// Query for plot areas in the chunk
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region);
final Set<PlotArea> areas =
PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region);
if (areas.isEmpty()) {
return false;
}
@ -89,7 +90,7 @@ public class AugmentedUtils {
queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false);
queue.setChunkObject(chunkObject);
}
LocalBlockQueue primaryMask;
QueueCoordinator primaryMask;
// coordinates
int relativeBottomX;
int relativeBottomZ;
@ -102,14 +103,14 @@ public class AugmentedUtils {
relativeTopX = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX);
relativeTopZ = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ);
primaryMask = new AreaBoundDelegateLocalBlockQueue(area, queue);
primaryMask = new AreaBoundDelegateQueueCoordinator(area, queue);
} else {
relativeBottomX = relativeBottomZ = 0;
relativeTopX = relativeTopZ = 15;
primaryMask = queue;
}
LocalBlockQueue secondaryMask;
QueueCoordinator secondaryMask;
BlockState air = BlockTypes.AIR.getDefaultState();
if (area.getTerrain() == PlotAreaTerrainType.ROAD) {
PlotManager manager = area.getPlotManager();
@ -133,7 +134,7 @@ public class AugmentedUtils {
continue;
}
generationResult = true;
secondaryMask = new LocationOffsetDelegateLocalBlockQueue(canPlace, blockX, blockZ,
secondaryMask = new LocationOffsetDelegateQueueCoordinator(canPlace, blockX, blockZ,
primaryMask);
} else {
secondaryMask = primaryMask;
@ -151,15 +152,15 @@ public class AugmentedUtils {
secondaryMask.setChunkObject(chunkObject);
secondaryMask.setForceSync(true);
ScopedLocalBlockQueue scoped =
new ScopedLocalBlockQueue(secondaryMask, Location.at(world, blockX, 0, blockZ),
ScopedQueueCoordinator scoped =
new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, 0, blockZ),
Location.at(world, blockX + 15, 255, blockZ + 15));
generator.generateChunk(scoped, area);
generator.populateChunk(scoped, area);
}
if (queue != null) {
queue.setForceSync(true);
queue.flush();
queue.enqueue();
}
return generationResult;
}

View File

@ -33,7 +33,7 @@ import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.RegionManager;
@ -136,7 +136,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return false;
}
Location[] corners = plot.getCorners();
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
int x = MathMan.average(corners[0].getX(), corners[1].getX());
int z = MathMan.average(corners[0].getZ(), corners[1].getZ());
@ -157,7 +157,7 @@ public class ClassicPlotManager extends SquarePlotManager {
Plot plot = classicPlotWorld.getPlotAbs(plotId);
Location bottom = plot.getBottomAbs();
Location top = plot.getExtendedTopAbs();
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
int maxY = classicPlotWorld.getPlotManager().getWorldHeight();
if (!plot.getMerged(Direction.NORTH)) {
int z = bottom.getZ();
@ -221,7 +221,7 @@ public class ClassicPlotManager extends SquarePlotManager {
.subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0,
plot.getMerged(Direction.NORTH) ? 0 : 1);
Location top = plot.getExtendedTopAbs().add(1, 0, 1);
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
if (!plot.getMerged(Direction.NORTH)) {
int z = bot.getZ();
for (int x = bot.getX(); x < top.getX(); x++) {
@ -274,7 +274,7 @@ public class ClassicPlotManager extends SquarePlotManager {
.subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0,
plot.getMerged(Direction.NORTH) ? 0 : 1);
Location top = plot.getExtendedTopAbs().add(1, 0, 1);
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
int y = classicPlotWorld.WALL_HEIGHT + 1;
if (!plot.getMerged(Direction.NORTH)) {
int z = bot.getZ();
@ -315,7 +315,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int ex = sx + classicPlotWorld.ROAD_WIDTH - 1;
int sz = pos1.getZ() - 2;
int ez = pos2.getZ() + 2;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
int maxY = getWorldHeight();
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz + 1),
@ -353,7 +353,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
int sx = pos1.getX() - 2;
int ex = pos2.getX() + 2;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1,
Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
Location.at(classicPlotWorld.getWorldName(), ex - 1,
@ -390,7 +390,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int ex = sx + classicPlotWorld.ROAD_WIDTH - 1;
int sz = pos2.getZ() + 1;
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
queue.setCuboid(
Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.ROAD_HEIGHT + 1,
sz + 1), Location.at(classicPlotWorld.getWorldName(), ex - 1,
@ -412,7 +412,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int ex = sx + classicPlotWorld.ROAD_WIDTH - 1;
int sz = pos1.getZ() - 1;
int ez = pos2.getZ() + 1;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
Location.at(classicPlotWorld.getWorldName(), ex,
@ -435,7 +435,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
int sx = pos1.getX() - 1;
int ex = pos2.getX() + 1;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
Location.at(classicPlotWorld.getWorldName(), ex,
@ -457,7 +457,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int ex = sx + classicPlotWorld.ROAD_WIDTH - 1;
int sz = location.getZ() + 1;
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
QueueCoordinator queue = classicPlotWorld.getQueue(false);
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
Location.at(classicPlotWorld.getWorldName(), ex,

View File

@ -33,7 +33,7 @@ import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -52,7 +52,7 @@ public class HybridGen extends IndependentPlotGenerator {
return PlotSquared.platform().getPluginName();
}
private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX,
private void placeSchem(HybridPlotWorld world, ScopedQueueCoordinator result, short relativeX,
short relativeZ, int x, int z, boolean isRoad) {
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad
@ -76,7 +76,7 @@ public class HybridGen extends IndependentPlotGenerator {
}
@Override
public void generateChunk(@Nonnull ScopedLocalBlockQueue result, @Nonnull PlotArea settings) {
public void generateChunk(@Nonnull ScopedQueueCoordinator result, @Nonnull PlotArea settings) {
Preconditions.checkNotNull(result, "result cannot be null");
Preconditions.checkNotNull(settings, "settings cannot be null");

View File

@ -34,7 +34,7 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.FileBytes;
import com.plotsquared.core.util.MainUtil;
@ -47,8 +47,8 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import lombok.Getter;
import javax.annotation.Nonnull;
import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@ -62,7 +62,7 @@ public class HybridPlotManager extends ClassicPlotManager {
private final RegionManager regionManager;
public HybridPlotManager(@Nonnull final HybridPlotWorld hybridPlotWorld,
@Nonnull final RegionManager regionManager) {
@Nonnull final RegionManager regionManager) {
super(hybridPlotWorld, regionManager);
this.hybridPlotWorld = hybridPlotWorld;
this.regionManager = regionManager;
@ -106,20 +106,22 @@ public class HybridPlotManager extends ClassicPlotManager {
PlotId id2 = new PlotId(id.x + 1, id.y);
Location bot = getPlotBottomLocAbs(id2);
Location top = getPlotTopLocAbs(id);
Location pos1 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1);
Location pos2 = Location.at(hybridPlotWorld.getWorldName(), bot.getX(),
Math.min(getWorldHeight(), 255), top.getZ() + 1);
Location pos1 =
Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1);
Location pos2 = Location
.at(hybridPlotWorld.getWorldName(), bot.getX(), Math.min(getWorldHeight(), 255),
top.getZ() + 1);
MainUtil.resetBiome(hybridPlotWorld, pos1, pos2);
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
return true;
}
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
QueueCoordinator queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2, true);
queue.enqueue();
return true;
}
private void createSchemAbs(LocalBlockQueue queue, Location pos1, Location pos2,
private void createSchemAbs(QueueCoordinator queue, Location pos1, Location pos2,
boolean isRoad) {
int size = hybridPlotWorld.SIZE;
int minY;
@ -167,14 +169,16 @@ public class HybridPlotManager extends ClassicPlotManager {
PlotId id2 = new PlotId(id.x, id.y + 1);
Location bot = getPlotBottomLocAbs(id2);
Location top = getPlotTopLocAbs(id);
Location pos1 = Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1);
Location pos2 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1,
Math.min(getWorldHeight(), 255), bot.getZ());
Location pos1 =
Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1);
Location pos2 = Location
.at(hybridPlotWorld.getWorldName(), top.getX() + 1, Math.min(getWorldHeight(), 255),
bot.getZ());
MainUtil.resetBiome(hybridPlotWorld, pos1, pos2);
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
return true;
}
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
QueueCoordinator queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2, true);
queue.enqueue();
return true;
@ -186,7 +190,7 @@ public class HybridPlotManager extends ClassicPlotManager {
PlotId id2 = new PlotId(id.x + 1, id.y + 1);
Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1).withY(0);
Location pos2 = getPlotBottomLocAbs(id2).withY(Math.min(getWorldHeight(), 255));
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
QueueCoordinator queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2, true);
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
createSchemAbs(queue, pos1, pos2, true);
@ -228,7 +232,7 @@ public class HybridPlotManager extends ClassicPlotManager {
}
final BiomeType biome = hybridPlotWorld.getPlotBiome();
final LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
final QueueCoordinator queue = hybridPlotWorld.getQueue(false);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override public void run(int[] value) {
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
@ -257,14 +261,14 @@ public class HybridPlotManager extends ClassicPlotManager {
pastePlotSchematic(queue, bot, top);
}
}, () -> {
queue.enqueue();
// And notify whatever called this when plot clearing is done
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone);
queue.setCompleteTask(whenDone);
queue.enqueue();
}, 10);
return true;
}
public void pastePlotSchematic(LocalBlockQueue queue, Location bottom, Location top) {
public void pastePlotSchematic(QueueCoordinator queue, Location bottom, Location top) {
if (!hybridPlotWorld.PLOT_SCHEMATIC) {
return;
}

View File

@ -42,9 +42,9 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.ChunkBlockQueue;
import com.plotsquared.core.queue.ChunkQueueCoordinator;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
@ -128,7 +128,7 @@ public class HybridUtils {
*
*/
TaskManager.runTaskAsync(() -> {
final LocalBlockQueue queue = blockQueue.getNewQueue(world, false);
final QueueCoordinator queue = blockQueue.getNewQueue(world, false);
final BlockVector3 bot = region.getMinimumPoint();
final BlockVector3 top = region.getMaximumPoint();
@ -152,7 +152,7 @@ public class HybridUtils {
}
HybridPlotWorld hpw = (HybridPlotWorld) area;
ChunkBlockQueue chunk = new ChunkBlockQueue(bot, top, false);
ChunkQueueCoordinator chunk = new ChunkQueueCoordinator(bot, top, false);
hpw.getGenerator().generateChunk(chunk, hpw);
final BlockState[][][] oldBlocks = chunk.getBlocks();
@ -374,7 +374,7 @@ public class HybridUtils {
run.run();
}
public int checkModified(LocalBlockQueue queue, int x1, int x2, int y1, int y2, int z1, int z2,
public int checkModified(QueueCoordinator queue, int x1, int x2, int y1, int y2, int z1, int z2,
BlockState[] blocks) {
int count = 0;
for (int y = y1; y <= y2; y++) {
@ -521,7 +521,7 @@ public class HybridUtils {
public boolean setupRoadSchematic(Plot plot) {
final String world = plot.getWorldName();
final LocalBlockQueue queue = blockQueue.getNewQueue(world, false);
final QueueCoordinator queue = blockQueue.getNewQueue(world, false);
Location bot = plot.getBottomAbs().subtract(1, 0, 1);
Location top = plot.getTopAbs();
final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea();
@ -564,7 +564,7 @@ public class HybridUtils {
return true;
}
public int get_ey(final PlotManager pm, LocalBlockQueue queue, int sx, int ex, int sz, int ez,
public int get_ey(final PlotManager pm, QueueCoordinator queue, int sx, int ex, int sz, int ez,
int sy) {
int ey = sy;
for (int x = sx; x <= ex; x++) {
@ -608,7 +608,7 @@ public class HybridUtils {
z -= plotWorld.ROAD_OFFSET_Z;
final int finalX = x;
final int finalZ = z;
LocalBlockQueue queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false);
QueueCoordinator queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false);
if (id1 == null || id2 == null || id1 != id2) {
this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
if (id1 != null) {

View File

@ -29,7 +29,7 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.setup.PlotAreaBuilder;
/**
@ -52,9 +52,9 @@ public abstract class IndependentPlotGenerator {
* @param result
* @param settings
*/
public abstract void generateChunk(ScopedLocalBlockQueue result, PlotArea settings);
public abstract void generateChunk(ScopedQueueCoordinator result, PlotArea settings);
public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea setting) {
public boolean populateChunk(ScopedQueueCoordinator result, PlotArea setting) {
return false;
}
@ -75,8 +75,7 @@ public abstract class IndependentPlotGenerator {
*
* @param setup
*/
@Deprecated
public void processSetup(SetupObject setup) {
@Deprecated public void processSetup(SetupObject setup) {
}
/**
@ -85,7 +84,8 @@ public abstract class IndependentPlotGenerator {
*
* @param builder the area builder to modify
*/
public void processAreaSetup(PlotAreaBuilder builder) { }
public void processAreaSetup(PlotAreaBuilder builder) {
}
/**
* It is preferred for the PlotArea object to do most of the initialization necessary.

View File

@ -32,7 +32,7 @@ import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nonnull;
@ -56,7 +56,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
return "PlotSquared:single";
}
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
@Override public void generateChunk(ScopedQueueCoordinator result, PlotArea settings) {
SinglePlotArea area = (SinglePlotArea) settings;
if (area.VOID) {
Location min = result.getMin();

View File

@ -56,7 +56,7 @@ import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.KeepFlag;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
@ -75,11 +75,11 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import lombok.Getter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
@ -123,24 +123,13 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
*/
public class Plot {
private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName());
public static final int MAX_HEIGHT = 256;
private static final Logger logger =
LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName());
private static Set<Plot> connected_cache;
private static Set<CuboidRegion> regions_cache;
@Nonnull private final PlotId id;
// These will be injected
@Inject private EventDispatcher eventDispatcher;
@Inject private PlotListener plotListener;
@Inject private RegionManager regionManager;
@Inject private GlobalBlockQueue blockQueue;
@Inject private WorldUtil worldUtil;
@Inject private SchematicHandler schematicHandler;
@Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
/**
* Plot flag container
*/
@ -149,7 +138,6 @@ public class Plot {
* Has the plot changed since the last save cycle?
*/
public boolean countsTowardsMax = true;
/**
* Represents whatever the database manager needs it to: <br>
* - A value of -1 usually indicates the plot will not be stored in the DB<br>
@ -158,6 +146,14 @@ public class Plot {
* @deprecated magical
*/
@Deprecated public int temp;
// These will be injected
@Inject private EventDispatcher eventDispatcher;
@Inject private PlotListener plotListener;
@Inject private RegionManager regionManager;
@Inject private GlobalBlockQueue blockQueue;
@Inject private WorldUtil worldUtil;
@Inject private SchematicHandler schematicHandler;
@Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
/**
* plot owner
* (Merged plots can have multiple owners)
@ -945,9 +941,8 @@ public class Plot {
if (isDelete) {
this.removeSign();
}
PlotUnlinkEvent event = this.eventDispatcher
.callUnlink(getArea(), this, true, !isDelete,
isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR);
PlotUnlinkEvent event = this.eventDispatcher.callUnlink(getArea(), this, true, !isDelete,
isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR);
if (event.getEventResult() != Result.DENY) {
this.unlinkPlot(event.isCreateRoad(), event.isCreateSign());
}
@ -975,7 +970,8 @@ public class Plot {
Plot current = queue.poll();
if (Plot.this.area.getTerrain() != PlotAreaTerrainType.NONE) {
try {
regionManager.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false,
regionManager
.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false,
this);
} catch (UnsupportedOperationException exception) {
MainUtil.sendMessage(null,
@ -1099,7 +1095,8 @@ public class Plot {
"%plr%", name),
Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll(
"%plr%", name)};
this.worldUtil.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(),
this.worldUtil
.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(),
lines);
}
}
@ -1348,8 +1345,8 @@ public class Plot {
if (Settings.Backup.DELETE_ON_UNCLAIM) {
// Destroy all backups when the plot is unclaimed
Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(current)
.destroy();
Objects.requireNonNull(PlotSquared.platform()).getBackupManager()
.getProfile(current).destroy();
}
getArea().removePlot(getId());
@ -1377,7 +1374,8 @@ public class Plot {
Location[] corners = getCorners();
Location top = corners[0];
Location bot = corners[1];
Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
Location location = Location
.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
if (!isLoaded()) {
result.accept(location);
@ -1399,12 +1397,14 @@ public class Plot {
Location[] corners = getCorners();
Location top = corners[0];
Location bot = corners[1];
Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
Location location = Location
.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
if (!isLoaded()) {
return location;
}
int y = this.worldUtil.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ());
int y = this.worldUtil
.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ());
if (area.allowSigns()) {
y = Math.max(y, getManager().getSignLoc(this).getY());
}
@ -1459,14 +1459,16 @@ public class Plot {
return this.getDefaultHomeSynchronous(true);
} else {
Location bottom = this.getBottomAbs();
Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(),
bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(),
home.getPitch());
Location location = Location
.at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(),
bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch());
if (!isLoaded()) {
return location;
}
if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
location = location.withY(Math.max(1 + this.worldUtil.getHighestBlockSynchronous(this.getWorldName(), location.getX(),
if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial()
.isAir()) {
location = location.withY(Math.max(1 + this.worldUtil
.getHighestBlockSynchronous(this.getWorldName(), location.getX(),
location.getZ()), bottom.getY()));
}
return location;
@ -1482,16 +1484,17 @@ public class Plot {
this.getDefaultHome(result);
} else {
Location bottom = this.getBottomAbs();
Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(),
bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(),
home.getPitch());
Location location = Location
.at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(),
bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch());
if (!isLoaded()) {
result.accept(location);
return;
}
this.worldUtil.getBlock(location, block -> {
if (!block.getBlockType().getMaterial().isAir()) {
this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
this.worldUtil
.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
y -> result.accept(location.withY(Math.max(1 + y, bottom.getY()))));
} else {
result.accept(location);
@ -1683,7 +1686,7 @@ public class Plot {
* This should not need to be called
*/
public void refreshChunks() {
LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false);
QueueCoordinator queue = this.blockQueue.getNewQueue(getWorldName(), false);
HashSet<BlockVector2> chunks = new HashSet<>();
for (CuboidRegion region : Plot.this.getRegions()) {
for (int x = region.getMinimumPoint().getX() >> 4;
@ -1707,10 +1710,10 @@ public class Plot {
return;
}
Location location = manager.getSignLoc(this);
LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false);
QueueCoordinator queue = this.blockQueue.getNewQueue(getWorldName(), false);
queue.setBlock(location.getX(), location.getY(), location.getZ(),
BlockTypes.AIR.getDefaultState());
queue.flush();
queue.enqueue();
}
/**
@ -1721,8 +1724,8 @@ public class Plot {
this.setSign("unknown");
return;
}
this.impromptuPipeline.getSingle(this.getOwnerAbs(), (username, sign) ->
this.setSign(username));
this.impromptuPipeline
.getSingle(this.getOwnerAbs(), (username, sign) -> this.setSign(username));
}
/**
@ -1749,7 +1752,8 @@ public class Plot {
if (updateDB) {
if (!create(player.getUUID(), true)) {
logger.error("[P2] Player {} attempted to claim plot {}, but the database failed to update",
logger.error(
"[P2] Player {} attempted to claim plot {}, but the database failed to update",
player.getName(), this.getId().toCommaSeparatedString());
return false;
}
@ -2919,13 +2923,16 @@ public class Plot {
return;
}
final String string =
Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString()).replace("%message%", message);
Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString())
.replace("%message%", message);
for (final PlotPlayer<?> player : players) {
if (isOwner(player.getUUID()) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) {
if (isOwner(player.getUUID()) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) {
player.sendMessage(string);
}
}
} catch (final Exception ignored) {}
} catch (final Exception ignored) {
}
}
/**
@ -2977,8 +2984,7 @@ public class Plot {
Consumer<Boolean> resultConsumer) {
Plot plot = this.getBasePlot(false);
Result result =
this.eventDispatcher.callTeleport(player, player.getLocation(), plot)
.getEventResult();
this.eventDispatcher.callTeleport(player, player.getLocation(), plot).getEventResult();
if (result == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Teleport");
resultConsumer.accept(false);
@ -3214,8 +3220,10 @@ public class Plot {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
Location pos1 = corners[0];
Location pos2 = corners[1];
Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
Location pos4 = pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
Location pos3 =
pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
Location pos4 =
pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
regionManager.swap(pos1, pos2, pos3, pos4, this);
}
}
@ -3246,7 +3254,8 @@ public class Plot {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
final Location pos1 = corners[0];
final Location pos2 = corners[1];
Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
Location newPos =
pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
regionManager.copyRegion(pos1, pos2, newPos, task);
}
}.run();
@ -3340,7 +3349,8 @@ public class Plot {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
Location pos1 = corners[0];
Location pos2 = corners[1];
Location newPos = pos1 .add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
Location newPos =
pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
regionManager.copyRegion(pos1, pos2, newPos, this);
}
};

View File

@ -27,7 +27,6 @@ package com.plotsquared.core.plot;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.collection.QuadMap;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
@ -49,7 +48,7 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.MainUtil;
@ -172,7 +171,7 @@ public abstract class PlotArea {
@Nonnull protected abstract PlotManager createManager();
public LocalBlockQueue getQueue(final boolean autoQueue) {
public QueueCoordinator getQueue(final boolean autoQueue) {
return this.globalBlockQueue.getNewQueue(worldName, autoQueue);
}

View File

@ -75,6 +75,13 @@ public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator
return false;
}
@Override public boolean setBiome(int x, int y, int z, BiomeType biome) {
if (area.contains(x, z)) {
return super.setBiome(x, y, z, biome);
}
return false;
}
@Override public boolean setTile(int x, int y, int z, CompoundTag tag) {
if (area.contains(x, z)) {
return super.setTile(x, y, z, tag);

View File

@ -99,7 +99,16 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
@Override public final boolean setBiome(int x, int z, BiomeType biomeType) {
LocalChunk chunk = getChunk(x >> 4, z >> 4);
chunk.setBiome(x & 15, z & 15, biomeType);
for (int y = 0; y < 256; y++) {
chunk.setBiome(x & 15, y, z & 15, biomeType);
}
settingBiomes = true;
return true;
}
@Override public final boolean setBiome(int x, int y, int z, BiomeType biomeType) {
LocalChunk chunk = getChunk(x >> 4, z >> 4);
chunk.setBiome(x & 15, y, z & 15, biomeType);
settingBiomes = true;
return true;
}

View File

@ -35,11 +35,10 @@ import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
public final BiomeType[] biomeGrid;
public final BiomeType[][][] biomeResult;
public final BlockState[][][] result;
private final int width;
private final int length;
@ -51,7 +50,7 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
this.width = top.getX() - bot.getX() + 1;
this.length = top.getZ() - bot.getZ() + 1;
this.result = new BlockState[256][][];
this.biomeGrid = biomes ? new BiomeType[width * length] : null;
this.biomeResult = biomes ? new BiomeType[256][][] : null;
this.bot = bot;
this.top = top;
}
@ -60,16 +59,19 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
return result;
}
@Override public void fillBiome(BiomeType biomeType) {
if (biomeGrid == null) {
return;
@Override public boolean setBiome(int x, int z, BiomeType biomeType) {
if (this.biomeResult != null) {
for (int y = 0; y < 256; y++) {
this.storeCacheBiome(x, y, z, biomeType);
}
return true;
}
Arrays.fill(biomeGrid, biomeType);
return false;
}
@Override public boolean setBiome(int x, int z, BiomeType biomeType) {
if (this.biomeGrid != null) {
biomeGrid[(z * width) + x] = biomeType;
@Override public boolean setBiome(int x, int y, int z, BiomeType biomeType) {
if (this.biomeResult != null) {
this.storeCacheBiome(x, y, z, biomeType);
return true;
}
return false;
@ -97,6 +99,18 @@ public class ChunkQueueCoordinator extends ScopedQueueCoordinator {
resultYZ[x] = id;
}
private void storeCacheBiome(final int x, final int y, final int z, final BiomeType id) {
BiomeType[][] resultY = biomeResult[y];
if (resultY == null) {
biomeResult[y] = resultY = new BiomeType[length][];
}
BiomeType[] resultYZ = resultY[z];
if (resultYZ == null) {
resultY[z] = resultYZ = new BiomeType[width];
}
resultYZ[x] = id;
}
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {
this.storeCache(x, y, z, id.toImmutableState());
return true;

View File

@ -81,6 +81,10 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
return parent.setBiome(x, z, biome);
}
@Override public boolean setBiome(int x, int y, int z, BiomeType biome) {
return parent.setBiome(x, y, z, biome);
}
@Override public boolean isSettingBiomes() {
return parent.isSettingBiomes();
}
@ -103,4 +107,8 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
}
return false;
}
@Override public void setCompleteTask(Runnable whenDone) {
parent.setCompleteTask(whenDone);
}
}

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.queue;
import com.plotsquared.core.PlotSquared;
import lombok.Getter;
import lombok.Setter;
@ -42,6 +43,16 @@ public class GlobalBlockQueue {
this.activeQueues = new ConcurrentLinkedDeque<>();
}
public QueueCoordinator getNewQueue(String world, boolean autoQueue) {
QueueCoordinator queue = provider.getNewQueue(world);
// Auto-inject into the queue
PlotSquared.platform().getInjector().injectMembers(queue);
if (autoQueue) {
queue.enqueue();
}
return queue;
}
/**
* TODO Documentation needed.
*

View File

@ -31,16 +31,11 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
public class LocationOffsetDelegateQueueCoordinator extends DelegateQueueCoordinator {
private static final Logger logger = LoggerFactory
.getLogger("P2/" + LocationOffsetDelegateQueueCoordinator.class.getSimpleName());
private final boolean[][] canPlace;
private final int blockX;
private final int blockZ;
@ -76,8 +71,12 @@ public class LocationOffsetDelegateQueueCoordinator extends DelegateQueueCoordin
return this.setBlock(x, y, z, pattern.apply(blockVector3));
}
@Override public boolean setBiome(int x, int y, BiomeType biome) {
return super.setBiome(x, y, biome);
@Override public boolean setBiome(int x, int z, BiomeType biome) {
return super.setBiome(x, z, biome);
}
@Override public boolean setBiome(int x, int y, int z, BiomeType biome) {
return super.setBiome(x, y, z, biome);
}
@Override public boolean setTile(int x, int y, int z, CompoundTag tag) {

View File

@ -42,8 +42,12 @@ public class OffsetQueueCoordinator extends DelegateQueueCoordinator {
this.oz = oz;
}
@Override public boolean setBiome(int x, int y, BiomeType biome) {
return super.setBiome(ox + x, oy + y, biome);
@Override public boolean setBiome(int x, int z, BiomeType biome) {
return super.setBiome(ox + x, oz + z, biome);
}
@Override public boolean setBiome(int x, int y, int z, BiomeType biome) {
return super.setBiome(ox + x, oy + y, oz + z, biome);
}
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {

View File

@ -52,6 +52,13 @@ public abstract class QueueCoordinator {
PlotSquared.platform().getInjector().injectMembers(this);
}
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));
}
public abstract int size();
public abstract void setModified(long modified);
@ -78,7 +85,9 @@ public abstract class QueueCoordinator {
public abstract BlockState getBlock(int x, int y, int z);
public abstract boolean setBiome(int x, int z, BiomeType biome);
@Deprecated public abstract boolean setBiome(int x, int z, BiomeType biome);
public abstract boolean setBiome(int x, int y, int z, BiomeType biome);
public abstract boolean isSettingBiomes();
@ -92,6 +101,8 @@ public abstract class QueueCoordinator {
return blockQueue.enqueue(this);
}
public abstract void setCompleteTask(Runnable whenDone);
public void setCuboid(Location pos1, Location pos2, BlockState block) {
int yMin = Math.min(pos1.getY(), pos2.getY());
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));

View File

@ -64,10 +64,17 @@ public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, z + minZ, biome);
}
@Override public boolean setBiome(int x, int y, int z, BiomeType biome) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super
.setBiome(x + minX, y + minY, z + minZ, biome);
}
public void fillBiome(BiomeType biome) {
for (int x = 0; x <= dx; x++) {
for (int z = 0; z < dz; z++) {
setBiome(x, z, biome);
for (int y = 0; y <= dy; y++) {
for (int x = 0; x <= dx; x++) {
for (int z = 0; z < dz; z++) {
setBiome(x, y, z, biome);
}
}
}
}

View File

@ -28,8 +28,8 @@ package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.math.BlockVector2;
@ -42,19 +42,21 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class ChunkManager {
private static final Map<BlockVector2, RunnableVal<ScopedLocalBlockQueue>> forceChunks =
private static final Map<BlockVector2, RunnableVal<ScopedQueueCoordinator>> forceChunks =
new ConcurrentHashMap<>();
private static final Map<BlockVector2, RunnableVal<ScopedLocalBlockQueue>> addChunks =
private static final Map<BlockVector2, RunnableVal<ScopedQueueCoordinator>> addChunks =
new ConcurrentHashMap<>();
public static void setChunkInPlotArea(RunnableVal<ScopedLocalBlockQueue> force,
RunnableVal<ScopedLocalBlockQueue> add, String world, BlockVector2 loc) {
LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false);
if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) {
public static void setChunkInPlotArea(RunnableVal<ScopedQueueCoordinator> force,
RunnableVal<ScopedQueueCoordinator> add, String world, BlockVector2 loc) {
QueueCoordinator queue =
PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false);
if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get()
.isNonStandardGeneration(world, loc)) {
int blockX = loc.getX() << 4;
int blockZ = loc.getZ() << 4;
ScopedLocalBlockQueue scoped =
new ScopedLocalBlockQueue(queue, Location.at(world, blockX, 0, blockZ),
ScopedQueueCoordinator scoped =
new ScopedQueueCoordinator(queue, Location.at(world, blockX, 0, blockZ),
Location.at(world, blockX + 15, 255, blockZ + 15));
if (force != null) {
force.run(scoped);
@ -64,7 +66,7 @@ public abstract class ChunkManager {
add.run(scoped);
}
}
queue.flush();
queue.enqueue();
} else {
if (force != null) {
forceChunks.put(loc, force);
@ -76,8 +78,8 @@ public abstract class ChunkManager {
}
}
public static boolean preProcessChunk(BlockVector2 loc, ScopedLocalBlockQueue queue) {
final RunnableVal<ScopedLocalBlockQueue> forceChunk = forceChunks.get(loc);
public static boolean preProcessChunk(BlockVector2 loc, ScopedQueueCoordinator queue) {
final RunnableVal<ScopedQueueCoordinator> forceChunk = forceChunks.get(loc);
if (forceChunk != null) {
forceChunk.run(queue);
forceChunks.remove(loc);
@ -86,8 +88,8 @@ public abstract class ChunkManager {
return false;
}
public static boolean postProcessChunk(BlockVector2 loc, ScopedLocalBlockQueue queue) {
final RunnableVal<ScopedLocalBlockQueue> addChunk = forceChunks.get(loc);
public static boolean postProcessChunk(BlockVector2 loc, ScopedQueueCoordinator queue) {
final RunnableVal<ScopedQueueCoordinator> addChunk = forceChunks.get(loc);
if (addChunk != null) {
addChunk.run(queue);
addChunks.remove(loc);

View File

@ -30,7 +30,7 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.function.pattern.Pattern;
@ -39,8 +39,8 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nonnull;
import java.io.File;
import java.util.Collection;
import java.util.HashSet;
@ -48,9 +48,15 @@ import java.util.Set;
public abstract class RegionManager {
private static final Logger logger = LoggerFactory.getLogger("P2/" + RegionManager.class.getSimpleName());
private static final Logger logger =
LoggerFactory.getLogger("P2/" + RegionManager.class.getSimpleName());
public static RegionManager manager = null;
private final ChunkManager chunkManager;
public RegionManager(@Nonnull final ChunkManager chunkManager) {
this.chunkManager = chunkManager;
}
public static BlockVector2 getRegion(Location location) {
int x = location.getX() >> 9;
@ -58,12 +64,6 @@ public abstract class RegionManager {
return BlockVector2.at(x, z);
}
private final ChunkManager chunkManager;
public RegionManager(@Nonnull final ChunkManager chunkManager) {
this.chunkManager = chunkManager;
}
public void largeRegionTask(final String world, final CuboidRegion region,
final RunnableVal<BlockVector2> task, final Runnable whenDone) {
TaskManager.runTaskAsync(() -> {
@ -96,8 +96,7 @@ public abstract class RegionManager {
}
TaskManager.objectTask(chunks, new RunnableVal<BlockVector2>() {
@Override public void run(BlockVector2 value) {
chunkManager.loadChunk(world, value, false)
.thenRun(() -> task.run(value));
chunkManager.loadChunk(world, value, false).thenRun(() -> task.run(value));
}
}, whenDone);
});
@ -164,7 +163,7 @@ public abstract class RegionManager {
public boolean setCuboids(final PlotArea area, final Set<CuboidRegion> regions,
final Pattern blocks, int minY, int maxY) {
LocalBlockQueue queue = area.getQueue(false);
QueueCoordinator queue = area.getQueue(false);
for (CuboidRegion region : regions) {
Location pos1 = Location.at(area.getWorldName(), region.getMinimumPoint().getX(), minY,
region.getMinimumPoint().getZ());

View File

@ -32,7 +32,7 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.jnbt.ByteArrayTag;
@ -58,12 +58,12 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import javax.annotation.Nonnull;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -96,12 +96,11 @@ import java.util.zip.GZIPOutputStream;
public abstract class SchematicHandler {
private static final Logger logger = LoggerFactory.getLogger("P2/" + SchematicHandler.class.getSimpleName());
private static final Logger logger =
LoggerFactory.getLogger("P2/" + SchematicHandler.class.getSimpleName());
public static SchematicHandler manager;
private boolean exportAll = false;
private final WorldUtil worldUtil;
private boolean exportAll = false;
public SchematicHandler(@Nonnull final WorldUtil worldUtil) {
this.worldUtil = worldUtil;
@ -158,7 +157,8 @@ public abstract class SchematicHandler {
@Override public void run(final CompoundTag value) {
if (value != null) {
TaskManager.runTaskAsync(() -> {
boolean result = save(value, directory + File.separator + name + ".schem");
boolean result =
save(value, directory + File.separator + name + ".schem");
if (!result) {
logger.error("[P2] Failed to save {}", plot.getId());
}
@ -193,7 +193,7 @@ public abstract class SchematicHandler {
return;
}
try {
final LocalBlockQueue queue = plot.getArea().getQueue(false);
final QueueCoordinator queue = plot.getArea().getQueue(false);
BlockVector3 dimension = schematic.getClipboard().getDimensions();
final int WIDTH = dimension.getX();
final int LENGTH = dimension.getZ();
@ -219,7 +219,7 @@ public abstract class SchematicHandler {
if (pw instanceof ClassicPlotWorld) {
y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT;
} else {
y_offset_actual = yOffset + 1 + this.worldUtil
y_offset_actual = yOffset + 1 + this.worldUtil
.getHighestBlockSynchronous(plot.getWorldName(),
region.getMinimumPoint().getX() + 1,
region.getMinimumPoint().getZ() + 1);
@ -229,8 +229,9 @@ public abstract class SchematicHandler {
y_offset_actual = yOffset;
}
final Location pos1 = Location.at(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset, y_offset_actual,
region.getMinimumPoint().getZ() + zOffset);
final Location pos1 = Location
.at(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset,
y_offset_actual, region.getMinimumPoint().getZ() + zOffset);
final Location pos2 = pos1.add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
final int p1x = pos1.getX();
@ -300,7 +301,7 @@ public abstract class SchematicHandler {
});
}
public abstract boolean restoreTile(LocalBlockQueue queue, CompoundTag tag, int x, int y,
public abstract boolean restoreTile(QueueCoordinator queue, CompoundTag tag, int x, int y,
int z);
/**