This commit is contained in:
Jesse Boyd 2019-11-08 05:17:51 +00:00
parent 252fdefef3
commit 07fcd53bf8
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 41 additions and 32 deletions

View File

@ -51,7 +51,9 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean unClaimPlot(Plot plot, Runnable whenDone) { @Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING); setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING);
if (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) {
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); setWall(plot.getId(), classicPlotWorld.WALL_BLOCK);
}
return GlobalBlockQueue.IMP.addEmptyTask(whenDone); return GlobalBlockQueue.IMP.addEmptyTask(whenDone);
} }
@ -409,44 +411,29 @@ public class ClassicPlotManager extends SquarePlotManager {
* @return false if part of the merge failed, otherwise true if successful. * @return false if part of the merge failed, otherwise true if successful.
*/ */
@Override public boolean finishPlotMerge(List<PlotId> plotIds) { @Override public boolean finishPlotMerge(List<PlotId> plotIds) {
final BlockBucket block = classicPlotWorld.CLAIMED_WALL_BLOCK; final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
boolean success = true; if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
for (PlotId plotId : plotIds) { for (PlotId plotId : plotIds) {
success &= setWall(plotId, block); setWall(plotId, claim);
}
} }
if (Settings.General.MERGE_REPLACE_WALL) { if (Settings.General.MERGE_REPLACE_WALL) {
final BlockBucket wallBlock = classicPlotWorld.WALL_FILLING; final BlockBucket wallBlock = classicPlotWorld.WALL_FILLING;
for (PlotId id : plotIds) { for (PlotId id : plotIds) {
success &= setWallFilling(id, wallBlock); setWallFilling(id, wallBlock);
} }
} }
return success; return true;
} }
@Override public boolean finishPlotUnlink(List<PlotId> plotIds) { @Override public boolean finishPlotUnlink(List<PlotId> plotIds) {
final BlockBucket block = classicPlotWorld.CLAIMED_WALL_BLOCK; final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
boolean success = true; if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
for (PlotId id : plotIds) { for (PlotId id : plotIds) {
success &= setWall(id, block); setWall(id, claim);
}
return success;
}
/**
* Sets all the blocks along all the plot walls to their correct state (claimed or unclaimed).
*
* @return true if the wall blocks were successfully set
*/
@Override public boolean regenerateAllPlotWalls() {
boolean success = true;
for (Plot plot : classicPlotWorld.getPlots()) {
if (plot.hasOwner()) {
success &= setWall(plot.getId(), classicPlotWorld.CLAIMED_WALL_BLOCK);
} else {
success &= setWall(plot.getId(), classicPlotWorld.WALL_BLOCK);
} }
} }
return success; return true; // return false if unlink has been denied
} }
@Override public boolean startPlotMerge(List<PlotId> plotIds) { @Override public boolean startPlotMerge(List<PlotId> plotIds) {
@ -459,8 +446,11 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean claimPlot(Plot plot) { @Override public boolean claimPlot(Plot plot) {
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
return setWall(plot.getId(), claim); return setWall(plot.getId(), claim);
} }
return true;
}
@Override public String[] getPlotComponents(PlotId plotId) { @Override public String[] getPlotComponents(PlotId plotId) {
return new String[] {"main", "floor", "air", "all", "border", "wall", "outline", "middle"}; return new String[] {"main", "floor", "air", "all", "border", "wall", "outline", "middle"};

View File

@ -25,7 +25,7 @@ import java.util.Random;
* A block bucket is a container of block types, where each block * A block bucket is a container of block types, where each block
* has a specified chance of being randomly picked * has a specified chance of being randomly picked
*/ */
@EqualsAndHashCode @SuppressWarnings({"unused", "WeakerAccess"}) public final class BlockBucket @EqualsAndHashCode(of={"blocks"}) @SuppressWarnings({"unused", "WeakerAccess"}) public final class BlockBucket
implements Iterable<BlockState>, ConfigurationSerializable { implements Iterable<BlockState>, ConfigurationSerializable {
private final Random random = new Random(); private final Random random = new Random();
@ -194,6 +194,11 @@ import java.util.Random;
return builder.toString(); return builder.toString();
} }
public boolean isAir() {
compile();
return blocks.isEmpty() || (single != null && single.getBlockType().getMaterial().isAir());
}
@Override public Map<String, Object> serialize() { @Override public Map<String, Object> serialize() {
if (!isCompiled()) { if (!isCompiled()) {
compile(); compile();
@ -201,7 +206,6 @@ import java.util.Random;
return ImmutableMap.of("blocks", this.toString()); return ImmutableMap.of("blocks", this.toString());
} }
@Getter @EqualsAndHashCode @RequiredArgsConstructor private final static class Range { @Getter @EqualsAndHashCode @RequiredArgsConstructor private final static class Range {
private final int min; private final int min;

View File

@ -90,6 +90,21 @@ public abstract class PlotManager {
return 255; return 255;
} }
public abstract boolean regenerateAllPlotWalls(); /**
* Sets all the blocks along all the plot walls to their correct state (claimed or unclaimed).
*
* @return true if the wall blocks were successfully set
*/
public boolean regenerateAllPlotWalls() {
boolean success = true;
for (Plot plot : plotArea.getPlots()) {
if (plot.hasOwner()) {
success &= claimPlot(plot);
} else {
success &= unClaimPlot(plot, null);
}
}
return success;
}
} }