Search in sources :

Example 1 with SinglePlotArea

use of com.plotsquared.core.plot.world.SinglePlotArea in project PlotSquared by IntellectualSites.

the class EventDispatcher method doJoinTask.

public void doJoinTask(final PlotPlayer<?> player) {
    if (player == null) {
        // possible future warning message to figure out where we are retrieving null
        return;
    }
    if (ExpireManager.IMP != null) {
        ExpireManager.IMP.handleJoin(player);
    }
    if (this.worldEdit != null) {
        if (player.getAttribute("worldedit")) {
            player.sendMessage(TranslatableCaption.of("worldedit.worldedit_bypassed"));
        }
    }
    final Plot plot = player.getCurrentPlot();
    if (Settings.Teleport.ON_LOGIN && plot != null && !(plot.getArea() instanceof SinglePlotArea)) {
        TaskManager.runTask(() -> plot.teleportPlayer(player, TeleportCause.LOGIN, result -> {
        }));
        player.sendMessage(TranslatableCaption.of("teleport.teleported_to_road"));
    }
}
Also used : TeleportCause(com.plotsquared.core.events.TeleportCause) DeviceInteractFlag(com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) PlotComponentSetEvent(com.plotsquared.core.events.PlotComponentSetEvent) PlotMergeEvent(com.plotsquared.core.events.PlotMergeEvent) VehiclePlaceFlag(com.plotsquared.core.plot.flag.implementations.VehiclePlaceFlag) Permission(com.plotsquared.core.permissions.Permission) PlayerLeavePlotEvent(com.plotsquared.core.events.PlayerLeavePlotEvent) PlaceFlag(com.plotsquared.core.plot.flag.implementations.PlaceFlag) PlayerPlotTrustedEvent(com.plotsquared.core.events.PlayerPlotTrustedEvent) PlayerAutoPlotEvent(com.plotsquared.core.events.PlayerAutoPlotEvent) PlotEvent(com.plotsquared.core.events.PlotEvent) PlotChangeOwnerEvent(com.plotsquared.core.events.PlotChangeOwnerEvent) Template(net.kyori.adventure.text.minimessage.Template) PlayerPlotDeniedEvent(com.plotsquared.core.events.PlayerPlotDeniedEvent) PlotDoneEvent(com.plotsquared.core.events.PlotDoneEvent) BlockType(com.sk89q.worldedit.world.block.BlockType) UseFlag(com.plotsquared.core.plot.flag.implementations.UseFlag) PlotClaimedNotifyEvent(com.plotsquared.core.events.PlotClaimedNotifyEvent) PlayerAutoPlotsChosenEvent(com.plotsquared.core.events.PlayerAutoPlotsChosenEvent) UUID(java.util.UUID) PostPlotMergeEvent(com.plotsquared.core.events.post.PostPlotMergeEvent) MobPlaceFlag(com.plotsquared.core.plot.flag.implementations.MobPlaceFlag) List(java.util.List) PlayerClaimPlotEvent(com.plotsquared.core.events.PlayerClaimPlotEvent) PlotFlagAddEvent(com.plotsquared.core.events.PlotFlagAddEvent) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) PlotDeleteEvent(com.plotsquared.core.events.PlotDeleteEvent) PostPlayerAutoPlotEvent(com.plotsquared.core.events.post.PostPlayerAutoPlotEvent) PostPlotChangeOwnerEvent(com.plotsquared.core.events.post.PostPlotChangeOwnerEvent) PostPlotDeleteEvent(com.plotsquared.core.events.post.PostPlotDeleteEvent) BlockTypeWrapper(com.plotsquared.core.plot.flag.types.BlockTypeWrapper) NonNull(org.checkerframework.checker.nullness.qual.NonNull) PlayerEnterPlotEvent(com.plotsquared.core.events.PlayerEnterPlotEvent) Rating(com.plotsquared.core.plot.Rating) PostPlotUnlinkEvent(com.plotsquared.core.events.post.PostPlotUnlinkEvent) PlotId(com.plotsquared.core.plot.PlotId) PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) Direction(com.plotsquared.core.location.Direction) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) ExpireManager(com.plotsquared.core.plot.expiration.ExpireManager) WorldEdit(com.sk89q.worldedit.WorldEdit) Nullable(org.checkerframework.checker.nullness.qual.Nullable) PlotClearEvent(com.plotsquared.core.events.PlotClearEvent) Location(com.plotsquared.core.location.Location) PlayerTeleportToPlotEvent(com.plotsquared.core.events.PlayerTeleportToPlotEvent) PlotFlagRemoveEvent(com.plotsquared.core.events.PlotFlagRemoveEvent) Plot(com.plotsquared.core.plot.Plot) PlayerBlockEventType(com.plotsquared.core.listener.PlayerBlockEventType) MiscPlaceFlag(com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag) TaskManager(com.plotsquared.core.util.task.TaskManager) PlotRateEvent(com.plotsquared.core.events.PlotRateEvent) PlotUnlinkEvent(com.plotsquared.core.events.PlotUnlinkEvent) PlotAutoMergeEvent(com.plotsquared.core.events.PlotAutoMergeEvent) PlotPlayer(com.plotsquared.core.player.PlotPlayer) PlayerPlotHelperEvent(com.plotsquared.core.events.PlayerPlotHelperEvent) Settings(com.plotsquared.core.configuration.Settings) PlotArea(com.plotsquared.core.plot.PlotArea) Pattern(com.sk89q.worldedit.function.pattern.Pattern) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) Plot(com.plotsquared.core.plot.Plot)

Example 2 with SinglePlotArea

use of com.plotsquared.core.plot.world.SinglePlotArea in project PlotSquared by IntellectualSites.

the class MainCommand method execute.

@Override
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
    // Optional command scope //
    Location location = null;
    Plot plot = null;
    boolean tp = false;
    if (args.length >= 2) {
        PlotArea area = player.getApplicablePlotArea();
        Plot newPlot = Plot.fromString(area, args[0]);
        if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea().equals(area) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_AREA_SUDO)) && !newPlot.isDenied(player.getUUID())) {
            final Location newLoc;
            if (newPlot.getArea() instanceof SinglePlotArea) {
                newLoc = newPlot.isLoaded() ? newPlot.getCenterSynchronous() : Location.at("", 0, 0, 0);
            } else {
                newLoc = newPlot.getCenterSynchronous();
            }
            if (player.canTeleport(newLoc)) {
                // Save meta
                try (final MetaDataAccess<Location> locationMetaDataAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
                    location = locationMetaDataAccess.get().orElse(null);
                    locationMetaDataAccess.set(newLoc);
                }
                try (final MetaDataAccess<Plot> plotMetaDataAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
                    plot = plotMetaDataAccess.get().orElse(null);
                    plotMetaDataAccess.set(newPlot);
                }
                tp = true;
            } else {
                player.sendMessage(TranslatableCaption.of("border.denied"));
            }
            // Trim command
            args = Arrays.copyOfRange(args, 1, args.length);
        }
        if (args.length >= 2 && !args[0].isEmpty() && args[0].charAt(0) == '-') {
            if ("f".equals(args[0].substring(1))) {
                confirm = new RunnableVal3<>() {

                    @Override
                    public void run(Command cmd, Runnable success, Runnable failure) {
                        if (area != null && PlotSquared.platform().econHandler().isEnabled(area)) {
                            PlotExpression priceEval = area.getPrices().get(cmd.getFullId());
                            double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
                            if (price != 0d && PlotSquared.platform().econHandler().getMoney(player) < price) {
                                if (failure != null) {
                                    failure.run();
                                }
                                return;
                            }
                        }
                        if (success != null) {
                            success.run();
                        }
                    }
                };
                args = Arrays.copyOfRange(args, 1, args.length);
            } else {
                player.sendMessage(TranslatableCaption.of("errors.invalid_command_flag"));
                return CompletableFuture.completedFuture(false);
            }
        }
    }
    try {
        super.execute(player, args, confirm, whenDone);
    } catch (CommandException e) {
        throw e;
    } catch (Throwable e) {
        e.printStackTrace();
        String message = e.getMessage();
        if (message != null) {
            player.sendMessage(TranslatableCaption.of("errors.error"), net.kyori.adventure.text.minimessage.Template.of("value", message));
        } else {
            player.sendMessage(TranslatableCaption.of("errors.error_console"));
        }
    }
    // Reset command scope //
    if (tp && !(player instanceof ConsolePlayer)) {
        try (final MetaDataAccess<Location> locationMetaDataAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
            if (location == null) {
                locationMetaDataAccess.remove();
            } else {
                locationMetaDataAccess.set(location);
            }
        }
        try (final MetaDataAccess<Plot> plotMetaDataAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
            if (plot == null) {
                plotMetaDataAccess.remove();
            } else {
                plotMetaDataAccess.set(plot);
            }
        }
    }
    return CompletableFuture.completedFuture(true);
}
Also used : SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) ConsolePlayer(com.plotsquared.core.player.ConsolePlayer) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) PlotExpression(com.plotsquared.core.util.PlotExpression) Location(com.plotsquared.core.location.Location)

Example 3 with SinglePlotArea

use of com.plotsquared.core.plot.world.SinglePlotArea 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 4 with SinglePlotArea

use of com.plotsquared.core.plot.world.SinglePlotArea 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 5 with SinglePlotArea

use of com.plotsquared.core.plot.world.SinglePlotArea in project PlotSquared by IntellectualSites.

the class SingleWorldGenerator method generateChunk.

@Override
public void generateChunk(ScopedQueueCoordinator result, PlotArea settings) {
    SinglePlotArea area = (SinglePlotArea) settings;
    if (area.VOID) {
        Location min = result.getMin();
        if (min.getX() == 0 && min.getZ() == 0) {
            result.setBlock(0, 0, 0, BlockTypes.BEDROCK.getDefaultState());
        }
    } else {
        result.setCuboid(bedrock1, bedrock2, BlockTypes.BEDROCK.getDefaultState());
        result.setCuboid(dirt1, dirt2, BlockTypes.DIRT.getDefaultState());
        result.setCuboid(grass1, grass2, BlockTypes.GRASS_BLOCK.getDefaultState());
    }
    result.fillBiome(BiomeTypes.PLAINS);
}
Also used : SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) Location(com.plotsquared.core.location.Location)

Aggregations

SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)6 Location (com.plotsquared.core.location.Location)5 BlockLoc (com.plotsquared.core.location.BlockLoc)2 Plot (com.plotsquared.core.plot.Plot)2 PlotArea (com.plotsquared.core.plot.PlotArea)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 EventBus (com.google.common.eventbus.EventBus)1 Settings (com.plotsquared.core.configuration.Settings)1 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)1 PlayerAutoPlotEvent (com.plotsquared.core.events.PlayerAutoPlotEvent)1 PlayerAutoPlotsChosenEvent (com.plotsquared.core.events.PlayerAutoPlotsChosenEvent)1 PlayerClaimPlotEvent (com.plotsquared.core.events.PlayerClaimPlotEvent)1 PlayerEnterPlotEvent (com.plotsquared.core.events.PlayerEnterPlotEvent)1 PlayerLeavePlotEvent (com.plotsquared.core.events.PlayerLeavePlotEvent)1 PlayerPlotDeniedEvent (com.plotsquared.core.events.PlayerPlotDeniedEvent)1 PlayerPlotHelperEvent (com.plotsquared.core.events.PlayerPlotHelperEvent)1 PlayerPlotTrustedEvent (com.plotsquared.core.events.PlayerPlotTrustedEvent)1 PlayerTeleportToPlotEvent (com.plotsquared.core.events.PlayerTeleportToPlotEvent)1 PlotAutoMergeEvent (com.plotsquared.core.events.PlotAutoMergeEvent)1 PlotChangeOwnerEvent (com.plotsquared.core.events.PlotChangeOwnerEvent)1