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;
}
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;
}
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;
}
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()));
}
}
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()));
}
}
Aggregations