Search in sources :

Example 1 with RegionOperationException

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

the class WE6Adapter method pasteSchematic.

@Override
public CuboidRegion pasteSchematic(Location location, Path file) {
    World world = new BukkitWorld(location.getWorld());
    final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
    try (InputStream fis = Files.newInputStream(file)) {
        Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(fis).read(editSession.getWorld().getWorldData());
        Vector to = BukkitUtil.toVector(location).setY(clipboard.getOrigin().getY());
        final ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, editSession.getWorld().getWorldData());
        Operation operation = clipboardHolder.createPaste(editSession, editSession.getWorld().getWorldData()).to(to).ignoreAirBlocks(true).build();
        Operations.completeBlindly(operation);
        final Region region = clipboard.getRegion();
        final Vector diff = to.subtract(clipboard.getOrigin());
        region.shift(diff);
        return new CuboidRegion(BukkitUtil.toLocation(location.getWorld(), region.getMinimumPoint()), BukkitUtil.toLocation(location.getWorld(), region.getMaximumPoint()));
    } catch (IOException | RegionOperationException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) InputStream(java.io.InputStream) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) Operation(com.sk89q.worldedit.function.operation.Operation) CuboidRegion(redempt.redlib.region.CuboidRegion) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) CuboidRegion(redempt.redlib.region.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard)

Example 2 with RegionOperationException

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

the class RegionCommands method stack.

@Command(name = "/stack", desc = "Repeat the contents of the selection")
@CommandPermissions("worldedit.region.stack")
@Preload(Preload.PreloadCheck.PRELOAD)
@Logging(ORIENTATION_REGION)
public int stack(Actor actor, World world, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of copies to stack", def = "1") @Confirm(Confirm.Processor.REGION) int count, @Arg(desc = "The direction to stack", def = Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction, @Switch(name = 's', desc = "Shift the selection to the last stacked copy") boolean moveSelection, @Switch(name = 'a', desc = "Ignore air blocks") boolean ignoreAirBlocks, @Switch(name = 'e', desc = "Also copy entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air") Mask mask) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    Mask combinedMask;
    if (ignoreAirBlocks) {
        if (mask == null) {
            combinedMask = new ExistingBlockMask(editSession);
        } else {
            combinedMask = new MaskIntersection(mask, new ExistingBlockMask(editSession));
        }
    } else {
        combinedMask = mask;
    }
    int affected = editSession.stackCuboidRegion(region, direction, count, copyEntities, copyBiomes, combinedMask);
    if (moveSelection) {
        try {
            final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
            final BlockVector3 shiftVector = direction.multiply(size).multiply(count);
            region.shift(shiftVector);
            session.getRegionSelector(world).learnChanges();
            session.getRegionSelector(world).explainRegionAdjust(actor, session);
        } catch (RegionOperationException e) {
            actor.printError(TextComponent.of(e.getMessage()));
        }
    }
    actor.print(Caption.of("worldedit.stack.changed", TextComponent.of(affected)));
    return affected;
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 3 with RegionOperationException

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

the class RegionCommands method move.

@Command(name = "/move", aliases = { "/mv" }, desc = "Move the contents of the selection")
@CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int move(Actor actor, World world, EditSession editSession, LocalSession session, @Selection Region region, @Arg(desc = "# of blocks to move", def = "1") int count, @Arg(desc = "The direction to move", def = Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction, @Arg(desc = "The pattern of blocks to leave", def = "air") Pattern replace, @Switch(name = 's', desc = "Shift the selection to the target location") boolean moveSelection, @Switch(name = 'a', desc = "Ignore air blocks") boolean ignoreAirBlocks, @Switch(name = 'e', desc = "Also copy entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air") Mask mask) throws WorldEditException {
    checkCommandArgument(count >= 1, "Count must be >= 1");
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    Mask combinedMask;
    if (ignoreAirBlocks) {
        if (mask == null) {
            combinedMask = new ExistingBlockMask(editSession);
        } else {
            combinedMask = new MaskIntersection(mask, new ExistingBlockMask(editSession));
        }
    } else {
        combinedMask = mask;
    }
    int affected = editSession.moveRegion(region, direction, count, copyEntities, copyBiomes, combinedMask, replace);
    if (moveSelection) {
        try {
            region.shift(direction.multiply(count));
            session.getRegionSelector(world).learnChanges();
            session.getRegionSelector(world).explainRegionAdjust(actor, session);
        } catch (RegionOperationException e) {
            actor.printError(TextComponent.of(e.getMessage()));
        }
    }
    actor.print(Caption.of("worldedit.move.moved", TextComponent.of(affected)));
    return affected;
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) 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)

Example 4 with RegionOperationException

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

the class SelectionCommands method contract.

@Command(name = "/contract", desc = "Contract the selection area")
@Logging(REGION)
@CommandPermissions("worldedit.selection.contract")
public void contract(Actor actor, World world, LocalSession session, @Arg(desc = "Amount to contract the selection by") int amount, @Arg(desc = "Amount to contract the selection by in the other direction", def = "0") int reverseAmount, @Arg(desc = "Direction to contract", def = Direction.AIM) @MultiDirection List<BlockVector3> direction) throws WorldEditException {
    try {
        Region region = session.getSelection(world);
        long oldSize = region.getVolume();
        if (reverseAmount == 0) {
            for (BlockVector3 dir : direction) {
                region.contract(dir.multiply(amount));
            }
        } else {
            for (BlockVector3 dir : direction) {
                region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
            }
        }
        session.getRegionSelector(world).learnChanges();
        long newSize = region.getVolume();
        session.getRegionSelector(world).explainRegionAdjust(actor, session);
        actor.print(Caption.of("worldedit.contract.contracted", TextComponent.of(oldSize - newSize)));
    } catch (RegionOperationException e) {
        actor.printError(TextComponent.of(e.getMessage()));
    }
}
Also used : RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 5 with RegionOperationException

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

the class SelectionCommands method shift.

@Command(name = "/shift", desc = "Shift the selection area")
@Logging(REGION)
@CommandPermissions("worldedit.selection.shift")
public void shift(Actor actor, World world, LocalSession session, @Arg(desc = "Amount to shift the selection by") int amount, @Arg(desc = "Direction to contract", def = Direction.AIM) @MultiDirection List<BlockVector3> direction) throws WorldEditException {
    try {
        Region region = session.getSelection(world);
        for (BlockVector3 dir : direction) {
            region.shift(dir.multiply(amount));
        }
        session.getRegionSelector(world).learnChanges();
        session.getRegionSelector(world).explainRegionAdjust(actor, session);
        actor.print(Caption.of("worldedit.shift.shifted"));
    } catch (RegionOperationException e) {
        actor.printError(TextComponent.of(e.getMessage()));
    }
}
Also used : RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

RegionOperationException (com.sk89q.worldedit.regions.RegionOperationException)6 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)4 Logging (com.sk89q.worldedit.command.util.Logging)4 Region (com.sk89q.worldedit.regions.Region)4 Command (org.enginehub.piston.annotation.Command)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)2 Preload (com.sk89q.worldedit.command.util.annotation.Preload)2 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)2 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)2 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 Operation (com.sk89q.worldedit.function.operation.Operation)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 World (com.sk89q.worldedit.world.World)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1