Search in sources :

Example 76 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class Deny method handleKick.

private void handleKick(PlotPlayer<?> player, Plot plot) {
    if (player == null) {
        return;
    }
    if (!plot.equals(player.getCurrentPlot())) {
        return;
    }
    if (player.hasPermission("plots.admin.entry.denied")) {
        return;
    }
    if (player.getGameMode() == GameModes.SPECTATOR) {
        player.stopSpectating();
    }
    Location location = player.getLocation();
    Location spawn = this.worldUtil.getSpawn(location.getWorldName());
    player.sendMessage(TranslatableCaption.of("deny.you_got_denied"));
    if (plot.equals(spawn.getPlot())) {
        Location newSpawn = this.worldUtil.getSpawn(this.plotAreaManager.getAllWorlds()[0]);
        if (plot.equals(newSpawn.getPlot())) {
            // Kick from server if you can't be teleported to spawn
            // Use string based message here for legacy uses
            player.kick("You got kicked from the plot! This server did not set up a loaded spawn, so you got " + "kicked from the server.");
        } else {
            player.teleport(newSpawn, TeleportCause.DENIED);
        }
    } else {
        player.teleport(spawn, TeleportCause.DENIED);
    }
}
Also used : Location(com.plotsquared.core.location.Location)

Example 77 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class CreateRoadSchematic method onCommand.

@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
    Location location = player.getLocation();
    Plot plot = location.getPlotAbs();
    if (plot == null) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
        return false;
    }
    if (plot.getVolume() > Integer.MAX_VALUE) {
        player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
        return false;
    }
    if (!(location.getPlotArea() instanceof HybridPlotWorld)) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
    }
    this.hybridUtils.setupRoadSchematic(plot);
    player.sendMessage(TranslatableCaption.of("schematics.schematic_road_created"), Template.of("command", "/plot debugroadregen"));
    return true;
}
Also used : HybridPlotWorld(com.plotsquared.core.generator.HybridPlotWorld) Plot(com.plotsquared.core.plot.Plot) Location(com.plotsquared.core.location.Location)

Example 78 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class DebugRoadRegen method regenPlot.

public boolean regenPlot(PlotPlayer<?> player) {
    Location location = player.getLocation();
    PlotArea area = location.getPlotArea();
    if (area == null) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
    }
    Plot plot = player.getCurrentPlot();
    if (plot == null) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
    } else if (plot.isMerged()) {
        player.sendMessage(TranslatableCaption.of("debug.requires_unmerged"));
    } else {
        PlotManager manager = area.getPlotManager();
        QueueCoordinator queue = area.getQueue();
        queue.setCompleteTask(() -> {
            player.sendMessage(TranslatableCaption.of("debugroadregen.regen_done"), Template.of("value", plot.getId().toString()));
            player.sendMessage(TranslatableCaption.of("debugroadregen.regen_all"), Template.of("value", "/plot regenallroads"));
        });
        manager.createRoadEast(plot, queue);
        manager.createRoadSouth(plot, queue);
        manager.createRoadSouthEast(plot, queue);
        queue.enqueue();
    }
    return true;
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) HybridPlotManager(com.plotsquared.core.generator.HybridPlotManager) PlotManager(com.plotsquared.core.plot.PlotManager) Plot(com.plotsquared.core.plot.Plot) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) Location(com.plotsquared.core.location.Location)

Example 79 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class RegionUtil method getCorners.

@NonNull
public 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 80 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class SchematicHandler method paste.

/**
 * Paste a schematic.
 *
 * @param schematic  the schematic object to paste
 * @param plot       plot to paste in
 * @param xOffset    offset x to paste it from plot origin
 * @param yOffset    offset y to paste it from plot origin
 * @param zOffset    offset z to paste it from plot origin
 * @param autoHeight if to automatically choose height to paste from
 * @param actor      the actor pasting the schematic
 * @param whenDone   task to run when schematic is pasted
 */
public void paste(final Schematic schematic, final Plot plot, final int xOffset, final int yOffset, final int zOffset, final boolean autoHeight, final PlotPlayer<?> actor, final RunnableVal<Boolean> whenDone) {
    if (whenDone != null) {
        whenDone.value = false;
    }
    if (schematic == null) {
        TaskManager.runTask(whenDone);
        return;
    }
    try {
        BlockVector3 dimension = schematic.getClipboard().getDimensions();
        final int WIDTH = dimension.getX();
        final int LENGTH = dimension.getZ();
        final int HEIGHT = dimension.getY();
        final int worldHeight = plot.getArea().getMaxGenHeight() - plot.getArea().getMinGenHeight() + 1;
        // Validate dimensions
        CuboidRegion region = plot.getLargestRegion();
        boolean sizeMismatch = ((region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + xOffset + 1) < WIDTH) || ((region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + zOffset + 1) < LENGTH) || (HEIGHT > worldHeight);
        if (!Settings.Schematics.PASTE_MISMATCHES && sizeMismatch) {
            actor.sendMessage(TranslatableCaption.of("schematics.schematic_size_mismatch"));
            TaskManager.runTask(whenDone);
            return;
        }
        // block type and data arrays
        final Clipboard blockArrayClipboard = schematic.getClipboard();
        // Calculate the optimal height to paste the schematic at
        final int y_offset_actual;
        if (autoHeight) {
            if (HEIGHT >= worldHeight) {
                y_offset_actual = yOffset;
            } else {
                PlotArea pw = plot.getArea();
                if (pw instanceof ClassicPlotWorld) {
                    y_offset_actual = yOffset + pw.getMinBuildHeight() + ((ClassicPlotWorld) pw).PLOT_HEIGHT;
                } else {
                    y_offset_actual = yOffset + pw.getMinBuildHeight() + this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), region.getMinimumPoint().getX() + 1, region.getMinimumPoint().getZ() + 1);
                }
            }
        } else {
            y_offset_actual = yOffset;
        }
        final int p1x;
        final int p1z;
        final int p2x;
        final int p2z;
        final Region allRegion;
        if (!sizeMismatch || plot.getRegions().size() == 1) {
            p1x = region.getMinimumPoint().getX() + xOffset;
            p1z = region.getMinimumPoint().getZ() + zOffset;
            p2x = region.getMaximumPoint().getX() + xOffset;
            p2z = region.getMaximumPoint().getZ() + zOffset;
            allRegion = region;
        } else {
            Location[] corners = plot.getCorners();
            p1x = corners[0].getX() + xOffset;
            p1z = corners[0].getZ() + zOffset;
            p2x = corners[1].getX() + xOffset;
            p2z = corners[1].getZ() + zOffset;
            allRegion = new RegionIntersection(null, plot.getRegions().toArray(new CuboidRegion[] {}));
        }
        // Paste schematic here
        final QueueCoordinator queue = plot.getArea().getQueue();
        for (int ry = 0; ry < Math.min(worldHeight, HEIGHT); ry++) {
            int yy = y_offset_actual + ry;
            if (yy > plot.getArea().getMaxGenHeight() || yy < plot.getArea().getMinGenHeight()) {
                continue;
            }
            for (int rz = 0; rz < blockArrayClipboard.getDimensions().getZ(); rz++) {
                for (int rx = 0; rx < blockArrayClipboard.getDimensions().getX(); rx++) {
                    int xx = p1x + rx;
                    int zz = p1z + rz;
                    if (sizeMismatch && (xx < p1x || xx > p2x || zz < p1z || zz > p2z || !allRegion.contains(BlockVector3.at(xx, ry, zz)))) {
                        continue;
                    }
                    BlockVector3 loc = BlockVector3.at(rx, ry, rz);
                    BaseBlock id = blockArrayClipboard.getFullBlock(loc);
                    queue.setBlock(xx, yy, zz, id);
                    BiomeType biome = blockArrayClipboard.getBiome(loc);
                    queue.setBiome(xx, yy, zz, biome);
                }
            }
        }
        if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
            queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
        }
        if (whenDone != null) {
            whenDone.value = true;
            queue.setCompleteTask(whenDone);
        }
        queue.enqueue();
    } catch (Exception e) {
        e.printStackTrace();
        TaskManager.runTask(whenDone);
    }
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) FileNotFoundException(java.io.FileNotFoundException) JsonParseException(com.google.gson.JsonParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) Location(com.plotsquared.core.location.Location)

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