use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getDefaultHomeSynchronous.
/**
* @param member if to get the home for plot members
* @return location of home for members or visitors
* @deprecated May cause synchronous chunk loads
*/
@Deprecated
public Location getDefaultHomeSynchronous(final boolean member) {
Plot plot = this.getBasePlot(false);
BlockLoc loc = member ? area.defaultHome() : area.nonmemberHome();
if (loc != null) {
int x;
int z;
if (loc.getX() == Integer.MAX_VALUE && loc.getZ() == Integer.MAX_VALUE) {
// center
if (getArea() instanceof SinglePlotArea) {
int y = loc.getY() == Integer.MIN_VALUE ? (isLoaded() ? this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), 0, 0) + 1 : 63) : loc.getY();
return Location.at(plot.getWorldName(), 0, y, 0, 0, 0);
}
CuboidRegion largest = plot.getLargestRegion();
x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX();
z = (largest.getMaximumPoint().getZ() >> 1) - (largest.getMinimumPoint().getZ() >> 1) + largest.getMinimumPoint().getZ();
} else {
// specific
Location bot = plot.getBottomAbs();
x = bot.getX() + loc.getX();
z = bot.getZ() + loc.getZ();
}
int y = loc.getY() == Integer.MIN_VALUE ? (isLoaded() ? this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 : 63) : loc.getY();
return Location.at(plot.getWorldName(), x, y, z, loc.getYaw(), loc.getPitch());
}
if (getArea() instanceof SinglePlotArea) {
int y = isLoaded() ? this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), 0, 0) + 1 : 63;
return Location.at(plot.getWorldName(), 0, y, 0, 0, 0);
}
// Side
return plot.getSideSynchronous();
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getDefaultHome.
public void getDefaultHome(boolean member, Consumer<Location> result) {
Plot plot = this.getBasePlot(false);
if (!isLoaded()) {
result.accept(Location.at("", 0, this.getArea() instanceof ClassicPlotWorld ? ((ClassicPlotWorld) this.getArea()).PLOT_HEIGHT + 1 : 4, 0));
return;
}
BlockLoc loc = member ? area.defaultHome() : area.nonmemberHome();
if (loc != null) {
int x;
int z;
if (loc.getX() == Integer.MAX_VALUE && loc.getZ() == Integer.MAX_VALUE) {
// center
if (getArea() instanceof SinglePlotArea) {
x = 0;
z = 0;
} else {
CuboidRegion largest = plot.getLargestRegion();
x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX();
z = (largest.getMaximumPoint().getZ() >> 1) - (largest.getMinimumPoint().getZ() >> 1) + largest.getMinimumPoint().getZ();
}
} else {
// specific
Location bot = plot.getBottomAbs();
x = bot.getX() + loc.getX();
z = bot.getZ() + loc.getZ();
}
if (loc.getY() == Integer.MIN_VALUE) {
if (isLoaded()) {
this.worldUtil.getHighestBlock(plot.getWorldName(), x, z, y -> result.accept(Location.at(plot.getWorldName(), x, y + 1, z)));
} else {
int y = this.getArea() instanceof ClassicPlotWorld ? ((ClassicPlotWorld) this.getArea()).PLOT_HEIGHT + 1 : 63;
result.accept(Location.at(plot.getWorldName(), x, y, z, loc.getYaw(), loc.getPitch()));
}
} else {
result.accept(Location.at(plot.getWorldName(), x, loc.getY(), z, loc.getYaw(), loc.getPitch()));
}
return;
}
// Side
if (getArea() instanceof SinglePlotArea) {
int y = isLoaded() ? this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), 0, 0) + 1 : 63;
result.accept(Location.at(plot.getWorldName(), 0, y, 0, 0, 0));
}
plot.getSide(result);
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getCorners.
@NonNull
static Location[] getCorners(@NonNull final String world, @NonNull final CuboidRegion region) {
final BlockVector3 min = region.getMinimumPoint();
final BlockVector3 max = region.getMaximumPoint();
return new Location[] { Location.at(world, min), Location.at(world, max) };
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method teleportPlayer.
/**
* Teleport a player to a plot and send them the teleport message.
*
* @param player the player
* @param cause the cause of the teleport
* @param resultConsumer Called with the result of the teleportation
*/
public void teleportPlayer(final PlotPlayer<?> player, TeleportCause cause, Consumer<Boolean> resultConsumer) {
Plot plot = this.getBasePlot(false);
Result result = this.eventDispatcher.callTeleport(player, player.getLocation(), plot, cause).getEventResult();
if (result == Result.DENY) {
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Teleport"));
resultConsumer.accept(false);
return;
}
final Consumer<Location> locationConsumer = location -> {
if (Settings.Teleport.DELAY == 0 || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) {
player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
player.teleport(location, cause);
resultConsumer.accept(true);
return;
}
player.sendMessage(TranslatableCaption.of("teleport.teleport_in_seconds"), Template.of("amount", String.valueOf(Settings.Teleport.DELAY)));
final String name = player.getName();
TaskManager.addToTeleportQueue(name);
TaskManager.runTaskLater(() -> {
if (!TaskManager.removeFromTeleportQueue(name)) {
return;
}
try {
player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
player.teleport(location, cause);
} catch (final Exception ignored) {
}
}, TaskTime.seconds(Settings.Teleport.DELAY));
resultConsumer.accept(true);
};
if (this.area.isHomeAllowNonmember() || plot.isAdded(player.getUUID())) {
this.getHome(locationConsumer);
} else {
this.getDefaultHome(false, locationConsumer);
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class PlotModificationManager method move.
/**
* Moves a plot physically, as well as the corresponding settings.
*
* @param destination Plot moved to
* @param actor The actor executing the task
* @param whenDone task when done
* @param allowSwap whether to swap plots
* @return {@code true} if the move was successful, else {@code false}
*/
@NonNull
public CompletableFuture<Boolean> move(@NonNull final Plot destination, @Nullable final PlotPlayer<?> actor, @NonNull final Runnable whenDone, final boolean allowSwap) {
final PlotId offset = PlotId.of(destination.getId().getX() - this.plot.getId().getX(), destination.getId().getY() - this.plot.getId().getY());
Location db = destination.getBottomAbs();
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(whenDone, TaskTime.ticks(1L));
return CompletableFuture.completedFuture(false);
}
AtomicBoolean occupied = new AtomicBoolean(false);
Set<Plot> plots = this.plot.getConnectedPlots();
for (Plot plot : plots) {
Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY());
if (other.hasOwner()) {
if (!allowSwap) {
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
return CompletableFuture.completedFuture(false);
}
occupied.set(true);
} else {
plot.getPlotModificationManager().removeSign();
}
}
// world border
destination.updateWorldBorder();
final ArrayDeque<CuboidRegion> regions = new ArrayDeque<>(this.plot.getRegions());
// move / swap data
final PlotArea originArea = this.plot.getArea();
final Iterator<Plot> plotIterator = plots.iterator();
CompletableFuture<Boolean> future = null;
if (plotIterator.hasNext()) {
while (plotIterator.hasNext()) {
final Plot plot = plotIterator.next();
final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY());
final CompletableFuture<Boolean> swapResult = plot.swapData(other);
if (future == null) {
future = swapResult;
} else {
future = future.thenCombine(swapResult, (fn, th) -> fn);
}
}
} else {
future = CompletableFuture.completedFuture(true);
}
return future.thenApply(result -> {
if (!result) {
return false;
}
// copy terrain
if (occupied.get()) {
new Runnable() {
@Override
public void run() {
if (regions.isEmpty()) {
// Update signs
destination.getPlotModificationManager().setSign();
setSign();
// Run final tasks
TaskManager.runTask(whenDone);
} else {
CuboidRegion region = regions.poll();
Location[] corners = Plot.getCorners(plot.getWorldName(), region);
Location pos1 = corners[0];
Location pos2 = corners[1];
Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
PlotSquared.platform().regionManager().swap(pos1, pos2, pos3, actor, this);
}
}
}.run();
} else {
new Runnable() {
@Override
public void run() {
if (regions.isEmpty()) {
Plot plot = destination.getRelative(0, 0);
Plot originPlot = originArea.getPlotAbs(PlotId.of(plot.getId().getX() - offset.getX(), plot.getId().getY() - offset.getY()));
final Runnable clearDone = () -> {
QueueCoordinator queue = PlotModificationManager.this.plot.getArea().getQueue();
for (final Plot current : plot.getConnectedPlots()) {
PlotModificationManager.this.plot.getManager().claimPlot(current, queue);
}
if (queue.size() > 0) {
queue.enqueue();
}
plot.getPlotModificationManager().setSign();
TaskManager.runTask(whenDone);
};
if (originPlot != null) {
originPlot.getPlotModificationManager().clear(false, true, actor, clearDone);
} else {
clearDone.run();
}
return;
}
final Runnable task = this;
CuboidRegion region = regions.poll();
Location[] corners = Plot.getCorners(PlotModificationManager.this.plot.getWorldName(), region);
final Location pos1 = corners[0];
final Location pos2 = corners[1];
Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
PlotSquared.platform().regionManager().copyRegion(pos1, pos2, newPos, actor, task);
}
}.run();
}
return true;
});
}
Aggregations