use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class PlotModificationManager method removeRoadSouth.
/**
* 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(@Nullable final QueueCoordinator queue) {
if (this.plot.getArea().getType() != PlotAreaType.NORMAL && this.plot.getArea().getTerrain() == PlotAreaTerrainType.ROAD) {
Plot other = this.plot.getRelative(Direction.SOUTH);
Location bot = other.getBottomAbs();
Location top = this.plot.getTopAbs();
Location pos1 = Location.at(this.plot.getWorldName(), bot.getX(), plot.getArea().getMinGenHeight(), top.getZ());
Location pos2 = Location.at(this.plot.getWorldName(), top.getX(), plot.getArea().getMaxGenHeight(), bot.getZ());
PlotSquared.platform().regionManager().regenerateRegion(pos1, pos2, true, null);
} else if (this.plot.getArea().getTerrain() != PlotAreaTerrainType.ALL) {
// no road generated => no road to remove
this.plot.getManager().removeRoadSouth(this.plot, queue);
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class PlotModificationManager method copy.
/**
* Copy a plot to a location, both physically and the settings
*
* @param destination destination plot
* @param actor the actor associated with the copy
* @return Future that completes with {@code true} if the copy was successful, else {@code false}
*/
public CompletableFuture<Boolean> copy(@NonNull final Plot destination, @Nullable PlotPlayer<?> actor) {
final CompletableFuture<Boolean> future = new CompletableFuture<>();
final PlotId offset = PlotId.of(destination.getId().getX() - this.plot.getId().getX(), destination.getId().getY() - this.plot.getId().getY());
final Location db = destination.getBottomAbs();
final Location ob = this.plot.getBottomAbs();
final int offsetX = db.getX() - ob.getX();
final int offsetZ = db.getZ() - ob.getZ();
if (!this.plot.hasOwner()) {
TaskManager.runTaskLater(() -> future.complete(false), TaskTime.ticks(1L));
return future;
}
final Set<Plot> plots = this.plot.getConnectedPlots();
for (final Plot plot : plots) {
final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY());
if (other.hasOwner()) {
TaskManager.runTaskLater(() -> future.complete(false), TaskTime.ticks(1L));
return future;
}
}
// world border
destination.updateWorldBorder();
// copy data
for (final Plot plot : plots) {
final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY());
other.getPlotModificationManager().create(plot.getOwner(), false);
if (!plot.getFlagContainer().getFlagMap().isEmpty()) {
final Collection<PlotFlag<?, ?>> existingFlags = other.getFlags();
other.getFlagContainer().clearLocal();
other.getFlagContainer().addAll(plot.getFlagContainer().getFlagMap().values());
// Update the database
for (final PlotFlag<?, ?> flag : existingFlags) {
final PlotFlag<?, ?> newFlag = other.getFlagContainer().queryLocal(flag.getClass());
if (other.getFlagContainer().queryLocal(flag.getClass()) == null) {
DBFunc.removeFlag(other, flag);
} else {
DBFunc.setFlag(other, newFlag);
}
}
}
if (plot.isMerged()) {
other.setMerged(plot.getMerged());
}
if (plot.members != null && !plot.members.isEmpty()) {
other.members = plot.members;
for (UUID member : plot.members) {
DBFunc.setMember(other, member);
}
}
if (plot.trusted != null && !plot.trusted.isEmpty()) {
other.trusted = plot.trusted;
for (UUID trusted : plot.trusted) {
DBFunc.setTrusted(other, trusted);
}
}
if (plot.denied != null && !plot.denied.isEmpty()) {
other.denied = plot.denied;
for (UUID denied : plot.denied) {
DBFunc.setDenied(other, denied);
}
}
}
// copy terrain
final ArrayDeque<CuboidRegion> regions = new ArrayDeque<>(this.plot.getRegions());
final Runnable run = new Runnable() {
@Override
public void run() {
if (regions.isEmpty()) {
final QueueCoordinator queue = plot.getArea().getQueue();
for (final Plot current : plot.getConnectedPlots()) {
destination.getManager().claimPlot(current, queue);
}
if (queue.size() > 0) {
queue.enqueue();
}
destination.getPlotModificationManager().setSign();
future.complete(true);
return;
}
CuboidRegion region = regions.poll();
Location[] corners = Plot.getCorners(plot.getWorldName(), region);
Location pos1 = corners[0];
Location pos2 = corners[1];
Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
PlotSquared.platform().regionManager().copyRegion(pos1, pos2, newPos, actor, this);
}
};
run.run();
return future;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class PlotModificationManager method removeRoadSouthEast.
/**
* 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(@Nullable QueueCoordinator queue) {
if (this.plot.getArea().getType() != PlotAreaType.NORMAL && this.plot.getArea().getTerrain() == PlotAreaTerrainType.ROAD) {
Plot other = this.plot.getRelative(1, 1);
Location pos1 = this.plot.getTopAbs().add(1, 0, 1);
Location pos2 = other.getBottomAbs().subtract(1, 0, 1);
PlotSquared.platform().regionManager().regenerateRegion(pos1, pos2, true, null);
} else if (this.plot.getArea().getTerrain() != PlotAreaTerrainType.ALL) {
// no road generated => no road to remove
this.plot.getArea().getPlotManager().removeRoadSouthEast(this.plot, queue);
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class PlotModificationManager method setSign.
/**
* Sets the sign for a plot to a specific name
*
* @param name name
*/
public void setSign(@NonNull final String name) {
if (!this.plot.isLoaded()) {
return;
}
PlotManager manager = this.plot.getArea().getPlotManager();
if (this.plot.getArea().allowSigns()) {
Location location = manager.getSignLoc(this.plot);
String id = this.plot.getId().toString();
Caption[] lines = new Caption[] { TranslatableCaption.of("signs.owner_sign_line_1"), TranslatableCaption.of("signs.owner_sign_line_2"), TranslatableCaption.of("signs.owner_sign_line_3"), TranslatableCaption.of("signs.owner_sign_line_4") };
PlotSquared.platform().worldUtil().setSign(location, lines, Template.of("id", id), Template.of("owner", name));
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getHome.
/**
* Return the home location for the plot
*
* @param result consumer to pass location to when found
*/
public void getHome(final Consumer<Location> result) {
BlockLoc home = this.getPosition();
if (home == null || home.getX() == 0 && home.getZ() == 0) {
this.getDefaultHome(result);
} else {
if (!isLoaded()) {
result.accept(Location.at("", 0, this.getArea() instanceof ClassicPlotWorld ? ((ClassicPlotWorld) this.getArea()).PLOT_HEIGHT + 1 : 4, 0));
return;
}
Location bottom = this.getBottomAbs();
Location location = toHomeLocation(bottom, home);
this.worldUtil.getBlock(location, block -> {
if (!block.getBlockType().getMaterial().isAir()) {
this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), y -> result.accept(location.withY(Math.max(1 + y, bottom.getY()))));
} else {
result.accept(location);
}
});
}
}
Aggregations