Search in sources :

Example 56 with Location

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();
}
Also used : SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockLoc(com.plotsquared.core.location.BlockLoc) Location(com.plotsquared.core.location.Location)

Example 57 with Location

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);
}
Also used : SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockLoc(com.plotsquared.core.location.BlockLoc) Location(com.plotsquared.core.location.Location)

Example 58 with Location

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) };
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.plotsquared.core.location.Location) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 59 with Location

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);
    }
}
Also used : TeleportCause(com.plotsquared.core.events.TeleportCause) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Inject(com.google.inject.Inject) Like(com.plotsquared.core.command.Like) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Permission(com.plotsquared.core.permissions.Permission) StaticCaption(com.plotsquared.core.configuration.caption.StaticCaption) BlockLoc(com.plotsquared.core.location.BlockLoc) Schematic(com.plotsquared.core.plot.schematic.Schematic) Map(java.util.Map) PlotListener(com.plotsquared.core.listener.PlotListener) FlagContainer(com.plotsquared.core.plot.flag.FlagContainer) DescriptionFlag(com.plotsquared.core.plot.flag.implementations.DescriptionFlag) Template(net.kyori.adventure.text.minimessage.Template) EventDispatcher(com.plotsquared.core.util.EventDispatcher) Caption(com.plotsquared.core.configuration.caption.Caption) DBFunc(com.plotsquared.core.database.DBFunc) RegionManager(com.plotsquared.core.util.RegionManager) WorldUtil(com.plotsquared.core.util.WorldUtil) TextComponent(net.kyori.adventure.text.TextComponent) ImmutableSet(com.google.common.collect.ImmutableSet) RunnableVal(com.plotsquared.core.util.task.RunnableVal) TimeZone(java.util.TimeZone) ServerPlotFlag(com.plotsquared.core.plot.flag.implementations.ServerPlotFlag) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Set(java.util.Set) UUID(java.util.UUID) CAP_MONSTER(com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER) Sets(com.google.common.collect.Sets) Result(com.plotsquared.core.events.Result) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CAP_MOB(com.plotsquared.core.util.entity.EntityCategories.CAP_MOB) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) Entry(java.util.Map.Entry) InternalFlag(com.plotsquared.core.plot.flag.InternalFlag) TaskTime(com.plotsquared.core.util.task.TaskTime) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) CAP_VEHICLE(com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE) NonNull(org.checkerframework.checker.nullness.qual.NonNull) CAP_ENTITY(com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CaptionUtility(com.plotsquared.core.configuration.caption.CaptionUtility) ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) Direction(com.plotsquared.core.location.Direction) PlotQuery(com.plotsquared.core.util.query.PlotQuery) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) SchematicHandler(com.plotsquared.core.util.SchematicHandler) Component(net.kyori.adventure.text.Component) ConsolePlayer(com.plotsquared.core.player.ConsolePlayer) ExpireManager(com.plotsquared.core.plot.expiration.ExpireManager) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Location(com.plotsquared.core.location.Location) GlobalFlagContainer(com.plotsquared.core.plot.flag.GlobalFlagContainer) RegionUtil(com.plotsquared.core.util.RegionUtil) KeepFlag(com.plotsquared.core.plot.flag.implementations.KeepFlag) Permissions(com.plotsquared.core.util.Permissions) MathMan(com.plotsquared.core.util.MathMan) TaskManager(com.plotsquared.core.util.task.TaskManager) Cleaner(java.lang.ref.Cleaner) DecimalFormat(java.text.DecimalFormat) DoubleFlag(com.plotsquared.core.plot.flag.types.DoubleFlag) TimeUtil(com.plotsquared.core.util.TimeUtil) CAP_MISC(com.plotsquared.core.util.entity.EntityCategories.CAP_MISC) Consumer(java.util.function.Consumer) PlotAnalysis(com.plotsquared.core.plot.expiration.PlotAnalysis) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) PlotSquared(com.plotsquared.core.PlotSquared) PlayerManager(com.plotsquared.core.util.PlayerManager) PlotPlayer(com.plotsquared.core.player.PlotPlayer) CAP_ANIMAL(com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL) Settings(com.plotsquared.core.configuration.Settings) ArrayDeque(java.util.ArrayDeque) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Result(com.plotsquared.core.events.Result) Location(com.plotsquared.core.location.Location)

Example 60 with Location

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;
    });
}
Also used : SquarePlotWorld(com.plotsquared.core.generator.SquarePlotWorld) NonNull(org.checkerframework.checker.nullness.qual.NonNull) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) PlotComponentSetEvent(com.plotsquared.core.events.PlotComponentSetEvent) PlotMergeEvent(com.plotsquared.core.events.PlotMergeEvent) Inject(com.google.inject.Inject) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) Direction(com.plotsquared.core.location.Direction) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LocaleHolder(com.plotsquared.core.configuration.caption.LocaleHolder) Template(net.kyori.adventure.text.minimessage.Template) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Caption(com.plotsquared.core.configuration.caption.Caption) DBFunc(com.plotsquared.core.database.DBFunc) Location(com.plotsquared.core.location.Location) Iterator(java.util.Iterator) TaskManager(com.plotsquared.core.util.task.TaskManager) Collection(java.util.Collection) ConfigurationUtil(com.plotsquared.core.configuration.ConfigurationUtil) Set(java.util.Set) UUID(java.util.UUID) PlotUnlinkEvent(com.plotsquared.core.events.PlotUnlinkEvent) Collectors(java.util.stream.Collectors) Result(com.plotsquared.core.events.Result) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) PlotSquared(com.plotsquared.core.PlotSquared) Logger(org.apache.logging.log4j.Logger) PlayerManager(com.plotsquared.core.util.PlayerManager) PlotPlayer(com.plotsquared.core.player.PlotPlayer) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) Settings(com.plotsquared.core.configuration.Settings) ArrayDeque(java.util.ArrayDeque) Pattern(com.sk89q.worldedit.function.pattern.Pattern) LogManager(org.apache.logging.log4j.LogManager) ProgressSubscriberFactory(com.plotsquared.core.inject.factory.ProgressSubscriberFactory) TaskTime(com.plotsquared.core.util.task.TaskTime) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ArrayDeque(java.util.ArrayDeque) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Location(com.plotsquared.core.location.Location) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

Location (com.plotsquared.core.location.Location)82 Plot (com.plotsquared.core.plot.Plot)41 PlotArea (com.plotsquared.core.plot.PlotArea)26 EventHandler (org.bukkit.event.EventHandler)15 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)14 PlotPlayer (com.plotsquared.core.player.PlotPlayer)12 UUID (java.util.UUID)12 HashSet (java.util.HashSet)10 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)9 NonNull (org.checkerframework.checker.nullness.qual.NonNull)9 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)8 Caption (com.plotsquared.core.configuration.caption.Caption)7 BlockLoc (com.plotsquared.core.location.BlockLoc)7 Template (net.kyori.adventure.text.minimessage.Template)7 Entity (org.bukkit.entity.Entity)7 Settings (com.plotsquared.core.configuration.Settings)6 ClassicPlotWorld (com.plotsquared.core.generator.ClassicPlotWorld)6 PlotFlag (com.plotsquared.core.plot.flag.PlotFlag)6 SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)6 PlotSquared (com.plotsquared.core.PlotSquared)5