Search in sources :

Example 1 with Result

use of com.plotsquared.core.events.Result in project PlotSquared by IntellectualSites.

the class Delete method onCommand.

@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
    Location location = player.getLocation();
    final Plot plot = location.getPlotAbs();
    if (plot == null) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
        return false;
    }
    if (!plot.hasOwner()) {
        player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
        return false;
    }
    if (plot.getVolume() > Integer.MAX_VALUE) {
        player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
        return false;
    }
    Result eventResult = this.eventDispatcher.callDelete(plot).getEventResult();
    if (eventResult == Result.DENY) {
        player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Delete"));
        return true;
    }
    boolean force = eventResult == Result.FORCE;
    if (!force && !plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DELETE)) {
        player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
        return false;
    }
    final PlotArea plotArea = plot.getArea();
    final java.util.Set<Plot> plots = plot.getConnectedPlots();
    final int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(location.getWorldName());
    Runnable run = () -> {
        if (plot.getRunning() > 0) {
            player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
            return;
        }
        final long start = System.currentTimeMillis();
        if (Settings.Teleport.ON_DELETE) {
            plot.getPlayersInPlot().forEach(playerInPlot -> plot.teleportPlayer(playerInPlot, TeleportCause.COMMAND_DELETE, result -> {
            }));
        }
        boolean result = plot.getPlotModificationManager().deletePlot(player, () -> {
            plot.removeRunning();
            if (this.econHandler.isEnabled(plotArea)) {
                PlotExpression valueExr = plotArea.getPrices().get("sell");
                double value = plots.size() * valueExr.evaluate(currentPlots);
                if (value > 0d) {
                    this.econHandler.depositMoney(player, value);
                    player.sendMessage(TranslatableCaption.of("economy.added_balance"), Template.of("money", this.econHandler.format(value)));
                }
            }
            player.sendMessage(TranslatableCaption.of("working.deleting_done"), Template.of("amount", String.valueOf(System.currentTimeMillis() - start)), Template.of("plot", plot.getId().toString()));
            eventDispatcher.callPostDelete(plot);
        });
        if (result) {
            plot.addRunning();
        } else {
            player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
        }
    };
    if (hasConfirmation(player)) {
        CmdConfirm.addPending(player, getCommandString() + ' ' + plot.getId(), run);
    } else {
        TaskManager.runTask(run);
    }
    return true;
}
Also used : TeleportCause(com.plotsquared.core.events.TeleportCause) Location(com.plotsquared.core.location.Location) Permissions(com.plotsquared.core.util.Permissions) NonNull(org.checkerframework.checker.nullness.qual.NonNull) Plot(com.plotsquared.core.plot.Plot) Inject(com.google.inject.Inject) TaskManager(com.plotsquared.core.util.task.TaskManager) Permission(com.plotsquared.core.permissions.Permission) EconHandler(com.plotsquared.core.util.EconHandler) Result(com.plotsquared.core.events.Result) PlotPlayer(com.plotsquared.core.player.PlotPlayer) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) PlotExpression(com.plotsquared.core.util.PlotExpression) Settings(com.plotsquared.core.configuration.Settings) PlotArea(com.plotsquared.core.plot.PlotArea) Template(net.kyori.adventure.text.minimessage.Template) EventDispatcher(com.plotsquared.core.util.EventDispatcher) PlotExpression(com.plotsquared.core.util.PlotExpression) PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) Location(com.plotsquared.core.location.Location) Result(com.plotsquared.core.events.Result)

Example 2 with Result

use of com.plotsquared.core.events.Result in project PlotSquared by IntellectualSites.

the class Clear method execute.

@Override
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
    if (args.length != 0) {
        sendUsage(player);
        return CompletableFuture.completedFuture(false);
    }
    final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
    Result eventResult = this.eventDispatcher.callClear(plot).getEventResult();
    if (eventResult == Result.DENY) {
        player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Clear"));
        return CompletableFuture.completedFuture(true);
    }
    if (plot.getVolume() > Integer.MAX_VALUE) {
        player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
        return CompletableFuture.completedFuture(true);
    }
    boolean force = eventResult == Result.FORCE;
    checkTrue(force || plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.clear"), TranslatableCaption.of("permission.no_plot_perms"));
    checkTrue(plot.getRunning() == 0, TranslatableCaption.of("errors.wait_for_timer"));
    checkTrue(force || !Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot) || Permissions.hasPermission(player, "plots.continue"), TranslatableCaption.of("done.done_already_done"));
    confirm.run(this, () -> {
        if (Settings.Teleport.ON_CLEAR) {
            plot.getPlayersInPlot().forEach(playerInPlot -> plot.teleportPlayer(playerInPlot, TeleportCause.COMMAND_CLEAR, result -> {
            }));
        }
        BackupManager.backup(player, plot, () -> {
            final long start = System.currentTimeMillis();
            boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> {
                plot.getPlotModificationManager().unlink();
                TaskManager.runTask(() -> {
                    plot.removeRunning();
                    // If the state changes, then mark it as no longer done
                    if (DoneFlag.isDone(plot)) {
                        PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class);
                        PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot);
                        if (event.getEventResult() != Result.DENY) {
                            plot.removeFlag(event.getFlag());
                        }
                    }
                    if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
                        PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(AnalysisFlag.class);
                        PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot);
                        if (event.getEventResult() != Result.DENY) {
                            plot.removeFlag(event.getFlag());
                        }
                    }
                    player.sendMessage(TranslatableCaption.of("working.clearing_done"), Template.of("amount", String.valueOf(System.currentTimeMillis() - start)), Template.of("plot", plot.getId().toString()));
                });
            });
            if (!result) {
                player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
            } else {
                plot.addRunning();
            }
        });
    }, null);
    return CompletableFuture.completedFuture(true);
}
Also used : TeleportCause(com.plotsquared.core.events.TeleportCause) GlobalBlockQueue(com.plotsquared.core.queue.GlobalBlockQueue) PlotFlagRemoveEvent(com.plotsquared.core.events.PlotFlagRemoveEvent) Permissions(com.plotsquared.core.util.Permissions) NonNull(org.checkerframework.checker.nullness.qual.NonNull) Plot(com.plotsquared.core.plot.Plot) Inject(com.google.inject.Inject) TaskManager(com.plotsquared.core.util.task.TaskManager) CompletableFuture(java.util.concurrent.CompletableFuture) PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) DoneFlag(com.plotsquared.core.plot.flag.implementations.DoneFlag) BackupManager(com.plotsquared.core.backup.BackupManager) Result(com.plotsquared.core.events.Result) RunnableVal3(com.plotsquared.core.util.task.RunnableVal3) PlotPlayer(com.plotsquared.core.player.PlotPlayer) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) RunnableVal2(com.plotsquared.core.util.task.RunnableVal2) Settings(com.plotsquared.core.configuration.Settings) AnalysisFlag(com.plotsquared.core.plot.flag.implementations.AnalysisFlag) Template(net.kyori.adventure.text.minimessage.Template) EventDispatcher(com.plotsquared.core.util.EventDispatcher) Plot(com.plotsquared.core.plot.Plot) PlotFlagRemoveEvent(com.plotsquared.core.events.PlotFlagRemoveEvent) Result(com.plotsquared.core.events.Result)

Example 3 with Result

use of com.plotsquared.core.events.Result 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 4 with Result

use of com.plotsquared.core.events.Result 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)

Example 5 with Result

use of com.plotsquared.core.events.Result in project PlotSquared by IntellectualSites.

the class Plot method claim.

/**
 * Claim the plot
 *
 * @param player    The player to set the owner to
 * @param teleport  If the player should be teleported
 * @param schematic The schematic name to paste on the plot
 * @param updateDB  If the database should be updated
 * @param auto      If the plot is being claimed by a /plot auto
 * @return success
 * @since 6.1.0
 */
public boolean claim(@NonNull final PlotPlayer<?> player, boolean teleport, String schematic, boolean updateDB, boolean auto) {
    this.eventDispatcher.callPlotClaimedNotify(this, auto);
    if (updateDB) {
        if (!this.getPlotModificationManager().create(player.getUUID(), true)) {
            LOGGER.error("Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString());
            return false;
        }
    } else {
        area.addPlot(this);
        updateWorldBorder();
    }
    player.sendMessage(TranslatableCaption.of("working.claimed"), Template.of("plot", this.getId().toString()));
    if (teleport) {
        if (!auto && Settings.Teleport.ON_CLAIM) {
            teleportPlayer(player, TeleportCause.COMMAND_CLAIM, result -> {
            });
        } else if (auto && Settings.Teleport.ON_AUTO) {
            teleportPlayer(player, TeleportCause.COMMAND_AUTO, result -> {
            });
        }
    }
    PlotArea plotworld = getArea();
    if (plotworld.isSchematicOnClaim()) {
        Schematic sch;
        try {
            if (schematic == null || schematic.isEmpty()) {
                sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
            } else {
                sch = schematicHandler.getSchematic(schematic);
                if (sch == null) {
                    sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
                }
            }
        } catch (SchematicHandler.UnsupportedFormatException e) {
            e.printStackTrace();
            return true;
        }
        schematicHandler.paste(sch, this, 0, getArea().getMinBuildHeight(), 0, Settings.Schematics.PASTE_ON_TOP, player, new RunnableVal<>() {

            @Override
            public void run(Boolean value) {
                if (value) {
                    player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
                } else {
                    player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
                }
            }
        });
    }
    plotworld.getPlotManager().claimPlot(this, null);
    this.getPlotModificationManager().setSign(player.getName());
    return true;
}
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) SchematicHandler(com.plotsquared.core.util.SchematicHandler) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) Schematic(com.plotsquared.core.plot.schematic.Schematic)

Aggregations

Inject (com.google.inject.Inject)5 Settings (com.plotsquared.core.configuration.Settings)5 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)5 Result (com.plotsquared.core.events.Result)5 PlotPlayer (com.plotsquared.core.player.PlotPlayer)5 TaskManager (com.plotsquared.core.util.task.TaskManager)5 Template (net.kyori.adventure.text.minimessage.Template)5 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 TeleportCause (com.plotsquared.core.events.TeleportCause)4 Location (com.plotsquared.core.location.Location)4 PlotFlag (com.plotsquared.core.plot.flag.PlotFlag)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 PlotSquared (com.plotsquared.core.PlotSquared)3 Caption (com.plotsquared.core.configuration.caption.Caption)3 DBFunc (com.plotsquared.core.database.DBFunc)3 Direction (com.plotsquared.core.location.Direction)3 Permission (com.plotsquared.core.permissions.Permission)3 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)3 PlayerManager (com.plotsquared.core.util.PlayerManager)3 TaskTime (com.plotsquared.core.util.task.TaskTime)3