Search in sources :

Example 1 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project PrivateMinesOOP by UntouchedOdin0.

the class WE7Adapter method walls.

public static Region walls(com.sk89q.worldedit.regions.CuboidRegion region) {
    BlockVector3 pos1 = region.getPos1();
    BlockVector3 pos2 = region.getPos2();
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    return new RegionIntersection(// Project to Z-Y plane
    new com.sk89q.worldedit.regions.CuboidRegion(pos1.withX(min.getX()), pos2.withX(min.getX())), new com.sk89q.worldedit.regions.CuboidRegion(pos1.withX(max.getX()), pos2.withX(max.getX())), // Project to X-Y plane
    new com.sk89q.worldedit.regions.CuboidRegion(pos1.withZ(min.getZ()), pos2.withZ(min.getZ())), new com.sk89q.worldedit.regions.CuboidRegion(pos1.withZ(max.getZ()), pos2.withZ(max.getZ())), // Project to the X-Z plane
    new com.sk89q.worldedit.regions.CuboidRegion(pos1.withY(min.getY()), pos2.withY(min.getY())));
}
Also used : RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 2 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project PrivateMinesOOP by UntouchedOdin0.

the class WE7Adapter method walls.

public static Region walls(CuboidRegion region) {
    BlockVector3 pos1 = BlockVector3.at(region.getStart().getBlockX(), region.getStart().getBlockY(), region.getStart().getBlockZ());
    BlockVector3 pos2 = BlockVector3.at(region.getEnd().getBlockX(), region.getEnd().getBlockY(), region.getEnd().getBlockZ());
    BlockVector3 min = BlockVector3.at(region.getStart().getBlockX(), region.getStart().getBlockY(), region.getStart().getBlockZ());
    BlockVector3 max = BlockVector3.at(region.getEnd().getBlockX(), region.getEnd().getBlockY(), region.getEnd().getBlockZ());
    return new RegionIntersection(// Project to Z-Y plane
    new com.sk89q.worldedit.regions.CuboidRegion(pos1.withX(min.getX()), pos2.withX(min.getX())), new com.sk89q.worldedit.regions.CuboidRegion(pos1.withX(max.getX()), pos2.withX(max.getX())), // Project to X-Y plane
    new com.sk89q.worldedit.regions.CuboidRegion(pos1.withZ(min.getZ()), pos2.withZ(min.getZ())), new com.sk89q.worldedit.regions.CuboidRegion(pos1.withZ(max.getZ()), pos2.withZ(max.getZ())), // Project to the X-Z plane
    new com.sk89q.worldedit.regions.CuboidRegion(pos1.withY(min.getY()), pos2.withY(min.getY())));
}
Also used : RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 3 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method copy.

@Command(name = "/copy", aliases = "/cp", desc = "Copy the selection to the clipboard")
@CommandPermissions("worldedit.clipboard.copy")
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void copy(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Switch(name = 'e', desc = "Also copy entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, // FAWE start
@Switch(name = 'c', desc = "Set the origin of the clipboard to the center of the region, at the region's lowest " + "y-level.") boolean centerClipboard, @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "") Mask mask) throws WorldEditException {
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    session.setClipboard(null);
    Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
    clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint().withY(region.getMinimumY()) : session.getPlacementPosition(actor));
    ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
    copy.setCopyingEntities(copyEntities);
    copy.setCopyingBiomes(copyBiomes);
    Mask sourceMask = editSession.getSourceMask();
    Region[] regions = editSession.getAllowedRegions();
    Region allowedRegion;
    if (regions == null || regions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(regions);
    }
    final Mask firstSourceMask = mask != null ? mask : sourceMask;
    final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
    if (finalMask != Masks.alwaysTrue()) {
        copy.setSourceMask(finalMask);
    }
    if (sourceMask != null) {
        editSession.setSourceMask(null);
        new MaskTraverser(sourceMask).reset(editSession);
        editSession.setSourceMask(null);
    }
    try {
        Operations.completeLegacy(copy);
    } catch (Throwable e) {
        throw e;
    } finally {
        clipboard.flush();
    }
    session.setClipboard(new ClipboardHolder(clipboard));
    copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ClipboardMask(com.sk89q.worldedit.internal.annotation.ClipboardMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class PlotSquaredFeature method getMask.

@Override
public FaweMask getMask(Player player, MaskType type, boolean isWhitelist) {
    final PlotPlayer<org.bukkit.entity.Player> pp = PlotPlayer.from(BukkitAdapter.adapt(player));
    if (pp == null) {
        return null;
    }
    final Set<CuboidRegion> regions;
    Plot plot = pp.getCurrentPlot();
    if (isAllowed(player, plot, type)) {
        regions = plot.getRegions();
    } else {
        plot = null;
        regions = WEManager.getMask(pp);
        if (regions.size() == 1) {
            CuboidRegion region = regions.iterator().next();
            if (region.getMinimumPoint().getX() == Integer.MIN_VALUE && region.getMaximumPoint().getX() == Integer.MAX_VALUE) {
                regions.clear();
            }
        }
    }
    if (regions.isEmpty()) {
        return null;
    }
    PlotArea area = pp.getApplicablePlotArea();
    final Plot finalPlot = plot;
    if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(finalPlot) || regions.isEmpty()) {
        return null;
    }
    Region maskedRegion;
    if (regions.size() == 1) {
        int min = area != null ? area.getMinBuildHeight() : player.getWorld().getMinY();
        int max = area != null ? Math.min(player.getWorld().getMaxY(), area.getMaxBuildHeight()) : player.getWorld().getMaxY();
        final CuboidRegion region = regions.iterator().next();
        final BlockVector3 pos1 = BlockVector3.at(region.getMinimumX(), min, region.getMinimumZ());
        final BlockVector3 pos2 = BlockVector3.at(region.getMaximumX(), max, region.getMaximumZ());
        maskedRegion = new CuboidRegion(pos1, pos2);
    } else {
        World world = FaweAPI.getWorld(area.getWorldName());
        List<Region> weRegions = regions.stream().map(r -> new CuboidRegion(world, BlockVector3.at(r.getMinimumX(), r.getMinimumY(), r.getMinimumZ()), BlockVector3.at(r.getMaximumX(), r.getMaximumY(), r.getMaximumZ()))).collect(Collectors.toList());
        maskedRegion = new RegionIntersection(world, weRegions);
    }
    return new FaweMask(maskedRegion) {

        @Override
        public boolean isValid(Player player, MaskType type) {
            if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(finalPlot)) {
                return false;
            }
            return isAllowed(player, finalPlot, type);
        }
    };
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) Player(com.sk89q.worldedit.entity.Player) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) World(com.sk89q.worldedit.world.World) Caption(com.fastasyncworldedit.core.configuration.Caption) DoneFlag(com.plotsquared.core.plot.flag.implementations.DoneFlag) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) WEManager(com.plotsquared.core.util.WEManager) Locale(java.util.Locale) Region(com.sk89q.worldedit.regions.Region) Bukkit(org.bukkit.Bukkit) DBFunc(com.plotsquared.core.database.DBFunc) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) Plot(com.plotsquared.core.plot.Plot) LogManagerCompat(com.sk89q.worldedit.internal.util.LogManagerCompat) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NoWorldeditFlag(com.plotsquared.core.plot.flag.implementations.NoWorldeditFlag) List(java.util.List) Logger(org.apache.logging.log4j.Logger) PlotPlayer(com.plotsquared.core.player.PlotPlayer) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) FaweMaskManager(com.fastasyncworldedit.core.regions.FaweMaskManager) FaweAPI(com.fastasyncworldedit.core.FaweAPI) Settings(com.plotsquared.core.configuration.Settings) PlotArea(com.plotsquared.core.plot.PlotArea) Player(com.sk89q.worldedit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) PlotArea(com.plotsquared.core.plot.PlotArea) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) Plot(com.plotsquared.core.plot.Plot) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) World(com.sk89q.worldedit.world.World) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region)

Example 5 with RegionIntersection

use of com.sk89q.worldedit.regions.RegionIntersection in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method cut.

/*
    @Command(
        name = "/lazycut",
        desc = "Lazily cut the selection to the clipboard"
    )
    @CommandPermissions("worldedit.clipboard.lazycut")
    public void lazyCut(Actor actor, LocalSession session, EditSession editSession,
                        @Selection final Region region,
                        @Switch(name = 'e', desc = "Skip copy entities")
                            boolean skipEntities,
                        @ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
                            Mask maskOpt,
                        @Switch(name = 'b', desc = "Also copy biomes")
                            boolean copyBiomes) throws WorldEditException {
        BlockVector3 min = region.getMinimumPoint();
        BlockVector3 max = region.getMaximumPoint();
        long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
        FaweLimit limit = actor.getLimit();
        if (volume >= limit.MAX_CHECKS) {
            throw FaweCache.MAX_CHECKS;
        }
        if (volume >= limit.MAX_CHANGES) {
            throw FaweCache.MAX_CHANGES;
        }
        session.setClipboard(null);

        ReadOnlyClipboard lazyClipboard = new WorldCutClipboard(editSession, region, !skipEntities, copyBiomes);
        clipboard.setOrigin(session.getPlacementPosition(actor));
        session.setClipboard(new ClipboardHolder(lazyClipboard));
        actor.print(Caption.of("fawe.worldedit.cut.command.cut.lazy", region.getArea()));
    }*/
// FAWE end
@Command(name = "/cut", desc = "Cut the selection to the clipboard", descFooter = "WARNING: Cutting and pasting entities cannot be undone!")
@CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void cut(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Pattern to leave in place of the selection", def = "air") Pattern leavePattern, @Switch(name = 'e', desc = "Also cut entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the exclude mask, non-matching blocks become air") Mask mask) throws WorldEditException {
    // FAWE start - Inject limits & respect source mask
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    if (volume >= limit.MAX_CHANGES) {
        throw FaweCache.MAX_CHANGES;
    }
    session.setClipboard(null);
    BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
    clipboard.setOrigin(session.getPlacementPosition(actor));
    ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
    copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
    copy.setCopyingEntities(copyEntities);
    copy.setRemovingEntities(true);
    copy.setCopyingBiomes(copyBiomes);
    Mask sourceMask = editSession.getSourceMask();
    Region[] regions = editSession.getAllowedRegions();
    Region allowedRegion;
    if (regions == null || regions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(regions);
    }
    final Mask firstSourceMask = mask != null ? mask : sourceMask;
    final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
    if (finalMask != Masks.alwaysTrue()) {
        copy.setSourceMask(finalMask);
    }
    if (sourceMask != null) {
        editSession.setSourceMask(null);
        new MaskTraverser(sourceMask).reset(editSession);
        editSession.setSourceMask(null);
    }
    try {
        Operations.completeLegacy(copy);
    } catch (Throwable e) {
        throw e;
    } finally {
        clipboard.flush();
    }
    session.setClipboard(new ClipboardHolder(clipboard));
    if (!actor.hasPermission("fawe.tips")) {
        actor.print(Caption.of("fawe.tips.tip.lazycut"));
    }
    copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ClipboardMask(com.sk89q.worldedit.internal.annotation.ClipboardMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

BlockVector3 (com.sk89q.worldedit.math.BlockVector3)7 RegionIntersection (com.sk89q.worldedit.regions.RegionIntersection)7 Region (com.sk89q.worldedit.regions.Region)5 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)4 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)4 NullRegion (com.sk89q.worldedit.regions.NullRegion)4 Mask (com.sk89q.worldedit.function.mask.Mask)3 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)3 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)2 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)2 FaweLimit (com.fastasyncworldedit.core.limit.FaweLimit)2 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)2 Preload (com.sk89q.worldedit.command.util.annotation.Preload)2 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)2 CylinderRegion (com.sk89q.worldedit.regions.CylinderRegion)2 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)2 FlatRegion (com.sk89q.worldedit.regions.FlatRegion)2