Search in sources :

Example 1 with ClassicPlotWorld

use of com.plotsquared.core.generator.ClassicPlotWorld in project PlotSquared by IntellectualSites.

the class Plot method getHome.

/**
 * Return the home location for the plot
 *
 * @param result consumer to pass location to when found
 */
public void getHome(final Consumer<Location> result) {
    BlockLoc home = this.getPosition();
    if (home == null || home.getX() == 0 && home.getZ() == 0) {
        this.getDefaultHome(result);
    } else {
        if (!isLoaded()) {
            result.accept(Location.at("", 0, this.getArea() instanceof ClassicPlotWorld ? ((ClassicPlotWorld) this.getArea()).PLOT_HEIGHT + 1 : 4, 0));
            return;
        }
        Location bottom = this.getBottomAbs();
        Location location = toHomeLocation(bottom, home);
        this.worldUtil.getBlock(location, block -> {
            if (!block.getBlockType().getMaterial().isAir()) {
                this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), y -> result.accept(location.withY(Math.max(1 + y, bottom.getY()))));
            } else {
                result.accept(location);
            }
        });
    }
}
Also used : ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) BlockLoc(com.plotsquared.core.location.BlockLoc) Location(com.plotsquared.core.location.Location)

Example 2 with ClassicPlotWorld

use of com.plotsquared.core.generator.ClassicPlotWorld in project PlotSquared by IntellectualSites.

the class Plot method getCenterSynchronous.

/**
 * @return Location of center
 * @deprecated May cause synchronous chunk loads
 */
@Deprecated
public Location getCenterSynchronous() {
    Location[] corners = getCorners();
    Location top = corners[0];
    Location bot = corners[1];
    if (!isLoaded()) {
        return Location.at("", 0, this.getArea() instanceof ClassicPlotWorld ? ((ClassicPlotWorld) this.getArea()).PLOT_HEIGHT + 1 : 4, 0);
    }
    Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
    int y = this.worldUtil.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ());
    if (area.allowSigns()) {
        y = Math.max(y, getManager().getSignLoc(this).getY());
    }
    return location.withY(1 + y);
}
Also used : ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) Location(com.plotsquared.core.location.Location)

Example 3 with ClassicPlotWorld

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

use of com.plotsquared.core.generator.ClassicPlotWorld in project PlotSquared by IntellectualSites.

the class Plot method getHomeSynchronous.

/**
 * @return the plot home location
 * @deprecated May cause synchronous chunk loading
 */
@Deprecated
public Location getHomeSynchronous() {
    BlockLoc home = this.getPosition();
    if (home == null || home.getX() == 0 && home.getZ() == 0) {
        return this.getDefaultHomeSynchronous(true);
    } else {
        Location bottom = this.getBottomAbs();
        if (!isLoaded()) {
            return Location.at("", 0, this.getArea() instanceof ClassicPlotWorld ? ((ClassicPlotWorld) this.getArea()).PLOT_HEIGHT + 1 : 4, 0);
        }
        Location location = toHomeLocation(bottom, home);
        if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
            location = location.withY(Math.max(1 + this.worldUtil.getHighestBlockSynchronous(this.getWorldName(), location.getX(), location.getZ()), bottom.getY()));
        }
        return location;
    }
}
Also used : ClassicPlotWorld(com.plotsquared.core.generator.ClassicPlotWorld) BlockLoc(com.plotsquared.core.location.BlockLoc) Location(com.plotsquared.core.location.Location)

Example 5 with ClassicPlotWorld

use of com.plotsquared.core.generator.ClassicPlotWorld 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

ClassicPlotWorld (com.plotsquared.core.generator.ClassicPlotWorld)5 Location (com.plotsquared.core.location.Location)5 BlockLoc (com.plotsquared.core.location.BlockLoc)3 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 JsonParseException (com.google.gson.JsonParseException)1 PlotArea (com.plotsquared.core.plot.PlotArea)1 SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)1 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 Region (com.sk89q.worldedit.regions.Region)1 RegionIntersection (com.sk89q.worldedit.regions.RegionIntersection)1 BiomeType (com.sk89q.worldedit.world.biome.BiomeType)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1