mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
A little spring cleaning
- Add Javadoc comments for where QueueCoordinator can be given or nulled - Add some more Javadoc comments in general - Squash methods into one where QueueCoordinator can be given - Only use one queue in some places where it makes sense
This commit is contained in:
parent
704e92c3d0
commit
38988b4819
@ -34,9 +34,10 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
@CommandDeclaration(command = "debugroadregen",
|
||||
@ -85,12 +86,15 @@ public class DebugRoadRegen extends SubCommand {
|
||||
Captions.REQUIRES_UNMERGED.send(player);
|
||||
} else {
|
||||
PlotManager manager = area.getPlotManager();
|
||||
manager.createRoadEast(plot);
|
||||
manager.createRoadSouth(plot);
|
||||
manager.createRoadSouthEast(plot);
|
||||
MainUtil.sendMessage(player, "&6Regenerating plot south/east roads: " + plot.getId()
|
||||
+ "\n&6 - Result: &aSuccess");
|
||||
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
|
||||
QueueCoordinator queue = area.getQueue();
|
||||
manager.createRoadEast(plot, queue);
|
||||
manager.createRoadSouth(plot, queue);
|
||||
manager.createRoadSouthEast(plot, queue);
|
||||
queue.setCompleteTask(() -> {
|
||||
MainUtil.sendMessage(player, "&6Regenerating plot south/east roads: " + plot.getId() + "\n&6 - Result: &aSuccess");
|
||||
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
|
||||
});
|
||||
queue.enqueue();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -60,8 +60,10 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComponent(@Nonnull PlotId plotId, @Nonnull String component, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
@Override public boolean setComponent(@Nonnull PlotId plotId,
|
||||
@Nonnull String component,
|
||||
@Nonnull Pattern blocks,
|
||||
@Nullable QueueCoordinator queue) {
|
||||
final Optional<ClassicPlotManagerComponent> componentOptional = ClassicPlotManagerComponent.fromString(component);
|
||||
if (componentOptional.isPresent()) {
|
||||
switch (componentOptional.get()) {
|
||||
@ -96,6 +98,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plot floor
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setFloor(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot != null && plot.isBasePlot()) {
|
||||
@ -105,6 +113,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the plot main, floor and air areas.
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setAll(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot != null && plot.isBasePlot()) {
|
||||
@ -113,6 +127,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the plot air region.
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setAir(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot != null && plot.isBasePlot()) {
|
||||
@ -122,6 +142,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the plot main blocks.
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setMain(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot == null || plot.isBasePlot()) {
|
||||
@ -130,6 +156,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the middle plot block to a Pattern
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setMiddle(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot == null || !plot.isBasePlot()) {
|
||||
@ -149,6 +181,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a plot's outline
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setOutline(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
if (classicPlotWorld.ROAD_WIDTH == 0) {
|
||||
return false;
|
||||
@ -216,6 +254,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the wall filling for a plot
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setWallFilling(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
if (classicPlotWorld.ROAD_WIDTH == 0) {
|
||||
return false;
|
||||
@ -274,6 +318,12 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a plot's wall top block only
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean setWall(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
if (classicPlotWorld.ROAD_WIDTH == 0) {
|
||||
return false;
|
||||
@ -325,9 +375,6 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* PLOT MERGING.
|
||||
*/
|
||||
@Override public boolean createRoadEast(@Nonnull Plot plot, @Nullable QueueCoordinator queue) {
|
||||
Location pos1 = getPlotBottomLocAbs(plot.getId());
|
||||
Location pos2 = getPlotTopLocAbs(plot.getId());
|
||||
@ -363,7 +410,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
}
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
@Override public boolean createRoadSouth(@Nonnull Plot plot, @Nullable QueueCoordinator queue) {
|
||||
@ -401,9 +448,10 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
}
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
|
||||
@Override public boolean createRoadSouthEast(@Nonnull Plot plot, @Nullable QueueCoordinator queue) {
|
||||
Location pos2 = getPlotTopLocAbs(plot.getId());
|
||||
int sx = pos2.getX() + 1;
|
||||
@ -504,11 +552,6 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED).
|
||||
*
|
||||
* @return false if part of the merge failed, otherwise true if successful.
|
||||
*/
|
||||
@Override public boolean finishPlotMerge(@Nonnull List<PlotId> plotIds, @Nullable QueueCoordinator queue) {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
|
@ -93,8 +93,8 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
Template.zipAll(hybridPlotWorld.getWorldName(), files);
|
||||
}
|
||||
|
||||
@Override public boolean createRoadEast(@Nonnull final Plot plot) {
|
||||
super.createRoadEast(plot);
|
||||
@Override public boolean createRoadEast(@Nonnull final Plot plot, @Nullable QueueCoordinator queue) {
|
||||
super.createRoadEast(plot, queue);
|
||||
PlotId id = plot.getId();
|
||||
PlotId id2 = PlotId.of(id.getX() + 1, id.getY());
|
||||
Location bot = getPlotBottomLocAbs(id2);
|
||||
@ -105,10 +105,13 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
QueueCoordinator queue = hybridPlotWorld.getQueue();
|
||||
boolean enqueue = false;
|
||||
if (queue == null) {
|
||||
queue = hybridPlotWorld.getQueue();
|
||||
enqueue = true;
|
||||
}
|
||||
createSchemAbs(queue, pos1, pos2, true);
|
||||
queue.enqueue();
|
||||
return true;
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
private void resetBiome(@Nonnull final HybridPlotWorld hybridPlotWorld, @Nonnull final Location pos1, @Nonnull final Location pos2) {
|
||||
@ -159,8 +162,8 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean createRoadSouth(@Nonnull final Plot plot) {
|
||||
super.createRoadSouth(plot);
|
||||
@Override public boolean createRoadSouth(@Nonnull final Plot plot, @Nullable QueueCoordinator queue) {
|
||||
super.createRoadSouth(plot, queue);
|
||||
PlotId id = plot.getId();
|
||||
PlotId id2 = PlotId.of(id.getX(), id.getY() + 1);
|
||||
Location bot = getPlotBottomLocAbs(id2);
|
||||
@ -171,24 +174,31 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
return true;
|
||||
}
|
||||
QueueCoordinator queue = hybridPlotWorld.getQueue();
|
||||
boolean enqueue = false;
|
||||
if (queue == null) {
|
||||
enqueue = true;
|
||||
queue = hybridPlotWorld.getQueue();
|
||||
}
|
||||
createSchemAbs(queue, pos1, pos2, true);
|
||||
queue.enqueue();
|
||||
return true;
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
@Override public boolean createRoadSouthEast(@Nonnull final Plot plot) {
|
||||
super.createRoadSouthEast(plot);
|
||||
@Override public boolean createRoadSouthEast(@Nonnull final Plot plot, @Nullable QueueCoordinator queue) {
|
||||
super.createRoadSouthEast(plot, queue);
|
||||
PlotId id = plot.getId();
|
||||
PlotId id2 = PlotId.of(id.getX() + 1, id.getY() + 1);
|
||||
Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1).withY(0);
|
||||
Location pos2 = getPlotBottomLocAbs(id2).withY(Math.min(getWorldHeight(), 255));
|
||||
QueueCoordinator queue = hybridPlotWorld.getQueue();
|
||||
boolean enqueue = false;
|
||||
if (queue == null) {
|
||||
enqueue = true;
|
||||
queue = hybridPlotWorld.getQueue();
|
||||
}
|
||||
createSchemAbs(queue, pos1, pos2, true);
|
||||
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
createSchemAbs(queue, pos1, pos2, true);
|
||||
}
|
||||
return queue.enqueue();
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +208,7 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
* don't need to do something quite as complex unless you happen to have 512x512 sized plots.
|
||||
* </p>
|
||||
*/
|
||||
@Override public boolean clearPlot(@Nonnull final Plot plot, @Nullable final Runnable whenDone) {
|
||||
@Override public boolean clearPlot(@Nonnull final Plot plot, @Nullable final Runnable whenDone, @Nullable QueueCoordinator queue) {
|
||||
if (this.regionManager.notifyClear(this)) {
|
||||
//If this returns false, the clear didn't work
|
||||
if (this.regionManager.handleClear(plot, whenDone, this)) {
|
||||
@ -224,7 +234,11 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
}
|
||||
|
||||
final BiomeType biome = hybridPlotWorld.getPlotBiome();
|
||||
final QueueCoordinator queue = hybridPlotWorld.getQueue();
|
||||
boolean enqueue = false;
|
||||
if (queue == null) {
|
||||
enqueue = true;
|
||||
queue = hybridPlotWorld.getQueue();
|
||||
}
|
||||
if (!canRegen) {
|
||||
queue.setCuboid(pos1.withY(0), pos2.withY(0), bedrock);
|
||||
// Each component has a different layer
|
||||
@ -236,8 +250,10 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
queue.setRegenRegion(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()));
|
||||
}
|
||||
pastePlotSchematic(queue, pos1, pos2);
|
||||
queue.setCompleteTask(whenDone);
|
||||
return queue.enqueue();
|
||||
if (whenDone != null) {
|
||||
queue.setCompleteTask(whenDone);
|
||||
}
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
public void pastePlotSchematic(@Nonnull final QueueCoordinator queue, @Nonnull final Location bottom, @Nonnull final Location top) {
|
||||
|
@ -109,7 +109,7 @@ public class HybridUtils {
|
||||
|
||||
public void regeneratePlotWalls(final PlotArea area) {
|
||||
PlotManager plotManager = area.getPlotManager();
|
||||
plotManager.regenerateAllPlotWalls();
|
||||
plotManager.regenerateAllPlotWalls(null);
|
||||
}
|
||||
|
||||
public void analyzeRegion(final String world, final CuboidRegion region, final RunnableVal<PlotAnalysis> whenDone) {
|
||||
|
@ -1061,13 +1061,17 @@ public class Plot {
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
};
|
||||
QueueCoordinator queue = getArea().getQueue();
|
||||
for (Plot current : plots) {
|
||||
if (isDelete || !current.hasOwner()) {
|
||||
manager.unClaimPlot(current, null);
|
||||
manager.unClaimPlot(current, null, queue);
|
||||
} else {
|
||||
manager.claimPlot(current);
|
||||
manager.claimPlot(current, queue);
|
||||
}
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
TaskManager.runTask(run);
|
||||
return;
|
||||
}
|
||||
@ -1082,7 +1086,7 @@ public class Plot {
|
||||
}
|
||||
return;
|
||||
}
|
||||
manager.clearPlot(current, this);
|
||||
manager.clearPlot(current, this, null);
|
||||
}
|
||||
};
|
||||
run.run();
|
||||
@ -1861,7 +1865,7 @@ public class Plot {
|
||||
}
|
||||
});
|
||||
}
|
||||
plotworld.getPlotManager().claimPlot(this);
|
||||
plotworld.getPlotManager().claimPlot(this, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2074,8 +2078,11 @@ public class Plot {
|
||||
/**
|
||||
* Remove the east road section of a plot<br>
|
||||
* - Used when a plot is merged<br>
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public void removeRoadEast() {
|
||||
public void removeRoadEast(@Nullable QueueCoordinator queue) {
|
||||
if (this.area.getType() != PlotAreaType.NORMAL && this.area.getTerrain() == PlotAreaTerrainType.ROAD) {
|
||||
Plot other = this.getRelative(Direction.EAST);
|
||||
Location bot = other.getBottomAbs();
|
||||
@ -2084,7 +2091,7 @@ public class Plot {
|
||||
Location pos2 = Location.at(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ());
|
||||
this.regionManager.regenerateRegion(pos1, pos2, true, null);
|
||||
} else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove
|
||||
this.area.getPlotManager().removeRoadEast(this);
|
||||
this.area.getPlotManager().removeRoadEast(this, queue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2440,8 +2447,11 @@ public class Plot {
|
||||
/**
|
||||
* Remove the south road section of a plot<br>
|
||||
* - Used when a plot is merged<br>
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public void removeRoadSouth() {
|
||||
public void removeRoadSouth(@Nullable QueueCoordinator queue) {
|
||||
if (this.area.getType() != PlotAreaType.NORMAL && this.area.getTerrain() == PlotAreaTerrainType.ROAD) {
|
||||
Plot other = this.getRelative(Direction.SOUTH);
|
||||
Location bot = other.getBottomAbs();
|
||||
@ -2450,7 +2460,7 @@ public class Plot {
|
||||
Location pos2 = Location.at(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ());
|
||||
this.regionManager.regenerateRegion(pos1, pos2, true, null);
|
||||
} else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove
|
||||
this.getManager().removeRoadSouth(this);
|
||||
this.getManager().removeRoadSouth(this, queue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2474,6 +2484,7 @@ public class Plot {
|
||||
Plot current;
|
||||
boolean toReturn = false;
|
||||
HashSet<Plot> visited = new HashSet<>();
|
||||
QueueCoordinator queue = getArea().getQueue();
|
||||
while ((current = frontier.poll()) != null && max >= 0) {
|
||||
if (visited.contains(current)) {
|
||||
continue;
|
||||
@ -2484,7 +2495,7 @@ public class Plot {
|
||||
Plot other = current.getRelative(Direction.NORTH);
|
||||
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|
||||
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
|
||||
current.mergePlot(other, removeRoads);
|
||||
current.mergePlot(other, removeRoads, queue);
|
||||
merged.add(current.getId());
|
||||
merged.add(other.getId());
|
||||
toReturn = true;
|
||||
@ -2493,7 +2504,7 @@ public class Plot {
|
||||
ArrayList<PlotId> ids = new ArrayList<>();
|
||||
ids.add(current.getId());
|
||||
ids.add(other.getId());
|
||||
this.getManager().finishPlotMerge(ids);
|
||||
this.getManager().finishPlotMerge(ids, queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2501,7 +2512,7 @@ public class Plot {
|
||||
Plot other = current.getRelative(Direction.EAST);
|
||||
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|
||||
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
|
||||
current.mergePlot(other, removeRoads);
|
||||
current.mergePlot(other, removeRoads, queue);
|
||||
merged.add(current.getId());
|
||||
merged.add(other.getId());
|
||||
toReturn = true;
|
||||
@ -2510,7 +2521,7 @@ public class Plot {
|
||||
ArrayList<PlotId> ids = new ArrayList<>();
|
||||
ids.add(current.getId());
|
||||
ids.add(other.getId());
|
||||
this.getManager().finishPlotMerge(ids);
|
||||
this.getManager().finishPlotMerge(ids, queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2518,7 +2529,7 @@ public class Plot {
|
||||
Plot other = current.getRelative(Direction.SOUTH);
|
||||
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|
||||
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
|
||||
current.mergePlot(other, removeRoads);
|
||||
current.mergePlot(other, removeRoads, queue);
|
||||
merged.add(current.getId());
|
||||
merged.add(other.getId());
|
||||
toReturn = true;
|
||||
@ -2527,7 +2538,7 @@ public class Plot {
|
||||
ArrayList<PlotId> ids = new ArrayList<>();
|
||||
ids.add(current.getId());
|
||||
ids.add(other.getId());
|
||||
this.getManager().finishPlotMerge(ids);
|
||||
this.getManager().finishPlotMerge(ids, queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2535,7 +2546,7 @@ public class Plot {
|
||||
Plot other = current.getRelative(Direction.WEST);
|
||||
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|
||||
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
|
||||
current.mergePlot(other, removeRoads);
|
||||
current.mergePlot(other, removeRoads, queue);
|
||||
merged.add(current.getId());
|
||||
merged.add(other.getId());
|
||||
toReturn = true;
|
||||
@ -2544,10 +2555,13 @@ public class Plot {
|
||||
ArrayList<PlotId> ids = new ArrayList<>();
|
||||
ids.add(current.getId());
|
||||
ids.add(other.getId());
|
||||
this.getManager().finishPlotMerge(ids);
|
||||
this.getManager().finishPlotMerge(ids, queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
@ -2603,15 +2617,18 @@ public class Plot {
|
||||
|
||||
/**
|
||||
* Remove the SE road (only effects terrain)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public void removeRoadSouthEast() {
|
||||
public void removeRoadSouthEast(@Nullable QueueCoordinator queue) {
|
||||
if (this.area.getType() != PlotAreaType.NORMAL && this.area.getTerrain() == PlotAreaTerrainType.ROAD) {
|
||||
Plot other = this.getRelative(1, 1);
|
||||
Location pos1 = this.getTopAbs().add(1, 0, 1).withY(0);
|
||||
Location pos2 = other.getBottomAbs().subtract(1, 0, 1).withY(MAX_HEIGHT);
|
||||
this.regionManager.regenerateRegion(pos1, pos2, true, null);
|
||||
} else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove
|
||||
this.area.getPlotManager().removeRoadSouthEast(this);
|
||||
this.area.getPlotManager().removeRoadSouthEast(this, queue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3088,10 +3105,10 @@ public class Plot {
|
||||
/**
|
||||
* Merges two plots. <br>- Assumes plots are directly next to each other <br> - saves to DB
|
||||
*
|
||||
* @param lesserPlot
|
||||
* @param removeRoads
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public void mergePlot(Plot lesserPlot, boolean removeRoads) {
|
||||
public void mergePlot(Plot lesserPlot, boolean removeRoads, @Nullable QueueCoordinator queue) {
|
||||
Plot greaterPlot = this;
|
||||
lesserPlot.removeSign();
|
||||
if (lesserPlot.getId().getX() == greaterPlot.getId().getX()) {
|
||||
@ -3108,14 +3125,14 @@ public class Plot {
|
||||
lesserPlot.mergeData(greaterPlot);
|
||||
if (removeRoads) {
|
||||
//lesserPlot.removeSign();
|
||||
lesserPlot.removeRoadSouth();
|
||||
lesserPlot.removeRoadSouth(queue);
|
||||
Plot diagonal = greaterPlot.getRelative(Direction.EAST);
|
||||
if (diagonal.getMerged(Direction.NORTHWEST)) {
|
||||
lesserPlot.removeRoadSouthEast();
|
||||
lesserPlot.removeRoadSouthEast(queue);
|
||||
}
|
||||
Plot below = greaterPlot.getRelative(Direction.WEST);
|
||||
if (below.getMerged(Direction.NORTHEAST)) {
|
||||
below.getRelative(Direction.NORTH).removeRoadSouthEast();
|
||||
below.getRelative(Direction.NORTH).removeRoadSouthEast(queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3135,17 +3152,16 @@ public class Plot {
|
||||
//lesserPlot.removeSign();
|
||||
Plot diagonal = greaterPlot.getRelative(Direction.SOUTH);
|
||||
if (diagonal.getMerged(Direction.NORTHWEST)) {
|
||||
lesserPlot.removeRoadSouthEast();
|
||||
lesserPlot.removeRoadSouthEast(queue);
|
||||
}
|
||||
lesserPlot.removeRoadEast();
|
||||
lesserPlot.removeRoadEast(queue);
|
||||
}
|
||||
Plot below = greaterPlot.getRelative(Direction.NORTH);
|
||||
if (below.getMerged(Direction.SOUTHWEST)) {
|
||||
below.getRelative(Direction.WEST).removeRoadSouthEast();
|
||||
below.getRelative(Direction.WEST).removeRoadSouthEast(queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3235,8 +3251,12 @@ public class Plot {
|
||||
Plot plot = destination.getRelative(0, 0);
|
||||
Plot originPlot = originArea.getPlotAbs(PlotId.of(plot.id.getX() - offset.getX(), plot.id.getY() - offset.getY()));
|
||||
final Runnable clearDone = () -> {
|
||||
QueueCoordinator queue = getArea().getQueue();
|
||||
for (final Plot current : plot.getConnectedPlots()) {
|
||||
getManager().claimPlot(current);
|
||||
getManager().claimPlot(current, queue);
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
plot.setSign();
|
||||
TaskManager.runTask(whenDone);
|
||||
@ -3334,8 +3354,12 @@ public class Plot {
|
||||
Runnable run = new Runnable() {
|
||||
@Override public void run() {
|
||||
if (regions.isEmpty()) {
|
||||
QueueCoordinator queue = getArea().getQueue();
|
||||
for (Plot current : getConnectedPlots()) {
|
||||
destination.getManager().claimPlot(current);
|
||||
destination.getManager().claimPlot(current, queue);
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
destination.setSign();
|
||||
TaskManager.runTask(whenDone);
|
||||
|
@ -934,7 +934,8 @@ public abstract class PlotArea {
|
||||
final PlotId pos2 = plotIds.get(plotIds.size() - 1);
|
||||
final PlotManager manager = getPlotManager();
|
||||
|
||||
manager.startPlotMerge(plotIds);
|
||||
QueueCoordinator queue = getQueue();
|
||||
manager.startPlotMerge(plotIds, queue);
|
||||
final Set<UUID> trusted = new HashSet<>();
|
||||
final Set<UUID> members = new HashSet<>();
|
||||
final Set<UUID> denied = new HashSet<>();
|
||||
@ -969,24 +970,25 @@ public abstract class PlotArea {
|
||||
if (ly) {
|
||||
if (!plot.getMerged(Direction.EAST) || !plot.getMerged(Direction.SOUTH)) {
|
||||
if (removeRoads) {
|
||||
plot.removeRoadSouthEast();
|
||||
plot.removeRoadSouthEast(queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!plot.getMerged(Direction.EAST)) {
|
||||
plot2 = plot.getRelative(1, 0);
|
||||
plot.mergePlot(plot2, removeRoads);
|
||||
plot.mergePlot(plot2, removeRoads, queue);
|
||||
}
|
||||
}
|
||||
if (ly) {
|
||||
if (!plot.getMerged(Direction.SOUTH)) {
|
||||
plot2 = plot.getRelative(0, 1);
|
||||
plot.mergePlot(plot2, removeRoads);
|
||||
plot.mergePlot(plot2, removeRoads, queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
manager.finishPlotMerge(plotIds);
|
||||
manager.finishPlotMerge(plotIds, queue);
|
||||
queue.enqueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -61,27 +61,16 @@ public abstract class PlotManager {
|
||||
// the same applies here
|
||||
public abstract Location getPlotTopLocAbs(@Nonnull PlotId plotId);
|
||||
|
||||
/*
|
||||
* Plot clearing (return false if you do not support some method)
|
||||
*/
|
||||
public boolean clearPlot(@Nonnull Plot plot, @Nullable Runnable whenDone) {
|
||||
return clearPlot(plot, whenDone, null);
|
||||
}
|
||||
|
||||
public boolean claimPlot(@Nonnull Plot plot) {
|
||||
return claimPlot(plot, null);
|
||||
|
||||
}
|
||||
|
||||
public boolean unClaimPlot(@Nonnull Plot plot, @Nullable Runnable whenDone) {
|
||||
return unClaimPlot(plot, whenDone, null);
|
||||
|
||||
}
|
||||
|
||||
public abstract boolean clearPlot(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nullable QueueCoordinator queue);
|
||||
|
||||
public abstract boolean claimPlot(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Completes block changes associated with plot unclaim.
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean unClaimPlot(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
@ -98,77 +87,85 @@ public abstract class PlotManager {
|
||||
*/
|
||||
public abstract String[] getPlotComponents(@Nonnull PlotId plotId);
|
||||
|
||||
public boolean setComponent(@Nonnull PlotId plotId, @Nonnull String component, @Nonnull Pattern blocks) {
|
||||
return setComponent(plotId, component, blocks, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the specified components to the specified Pattern on the specified plot.
|
||||
*
|
||||
* @param component FLOOR, WALL, AIR, MAIN, MIDDLE, OUTLINE, BORDER, ALL (floor, air and main).
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean setComponent(@Nonnull PlotId plotId,
|
||||
@Nonnull String component,
|
||||
@Nonnull Pattern blocks,
|
||||
@Nullable QueueCoordinator queue);
|
||||
|
||||
/*
|
||||
* PLOT MERGING (return false if your generator does not support plot
|
||||
* merging).
|
||||
/**
|
||||
* Create the road east of the plot (not schematic-based)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public boolean createRoadEast(@Nonnull Plot plot) {
|
||||
return createRoadEast(plot, null);
|
||||
}
|
||||
|
||||
public boolean createRoadSouth(@Nonnull Plot plot) {
|
||||
return createRoadSouth(plot, null);
|
||||
}
|
||||
|
||||
public boolean createRoadSouthEast(@Nonnull Plot plot) {
|
||||
return createRoadSouthEast(plot, null);
|
||||
}
|
||||
|
||||
public boolean removeRoadEast(@Nonnull Plot plot) {
|
||||
return removeRoadEast(plot, null);
|
||||
}
|
||||
|
||||
public boolean removeRoadSouth(@Nonnull Plot plot) {
|
||||
return removeRoadSouth(plot, null);
|
||||
}
|
||||
|
||||
public boolean removeRoadSouthEast(@Nonnull Plot plot) {
|
||||
return removeRoadSouthEast(plot, null);
|
||||
}
|
||||
|
||||
public boolean startPlotMerge(@Nonnull List<PlotId> plotIds) {
|
||||
return startPlotMerge(plotIds, null);
|
||||
}
|
||||
|
||||
public boolean startPlotUnlink(@Nonnull List<PlotId> plotIds) {
|
||||
return startPlotUnlink(plotIds, null);
|
||||
}
|
||||
|
||||
public boolean finishPlotMerge(@Nonnull List<PlotId> plotIds) {
|
||||
return finishPlotMerge(plotIds, null);
|
||||
}
|
||||
|
||||
public boolean finishPlotUnlink(@Nonnull List<PlotId> plotIds) {
|
||||
return finishPlotUnlink(plotIds, null);
|
||||
}
|
||||
|
||||
public abstract boolean createRoadEast(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Create the road south of the plot (not schematic-based)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean createRoadSouth(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Create the south-east corner of the road (intersection, not schematic-based)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean createRoadSouthEast(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Replace the road to the east of the plot with standard plot blocks (for when merging plots)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean removeRoadEast(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Replace the road to the south of the plot with standard plot blocks (for when merging plots)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean removeRoadSouth(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Replace the road to the south east of the plot (intersection) with standard plot blocks (for when merging plots)
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean removeRoadSouthEast(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
public abstract boolean startPlotMerge(@Nonnull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
||||
|
||||
public abstract boolean startPlotUnlink(@Nonnull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED).
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return false if part if the merge failed, otherwise true if successful.
|
||||
*/
|
||||
public abstract boolean finishPlotMerge(@Nonnull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
* Finished off an unlink by resetting the top wall block for unlinked plots
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*/
|
||||
public abstract boolean finishPlotUnlink(@Nonnull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
||||
|
||||
public void exportTemplate() throws IOException {
|
||||
@ -184,12 +181,10 @@ public abstract class PlotManager {
|
||||
/**
|
||||
* Sets all the blocks along all the plot walls to their correct state (claimed or unclaimed).
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return true if the wall blocks were successfully set
|
||||
*/
|
||||
public boolean regenerateAllPlotWalls() {
|
||||
return regenerateAllPlotWalls(null);
|
||||
}
|
||||
|
||||
public boolean regenerateAllPlotWalls(@Nullable QueueCoordinator queue) {
|
||||
boolean success = true;
|
||||
for (Plot plot : plotArea.getPlots()) {
|
||||
|
@ -95,6 +95,13 @@ public abstract class RegionManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a number of cuboids to a certain block between two y values.
|
||||
*
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return true if not enqueued, otherwise whether the created queue enqueued.
|
||||
*/
|
||||
public boolean setCuboids(final PlotArea area,
|
||||
final Set<CuboidRegion> regions,
|
||||
final Pattern blocks,
|
||||
|
Loading…
Reference in New Issue
Block a user