com.sk89q.worldedit.function.operation.Operation Java Examples

The following examples show how to use com.sk89q.worldedit.function.operation.Operation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchematicHelper.java    From FunnyGuilds with Apache License 2.0 8 votes vote down vote up
public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
    try {
        Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ());
        World pasteWorld = new BukkitWorld(location.getWorld());
        WorldData pasteWorldData = pasteWorld.getWorldData();

        Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData);
        ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, pasteWorldData);

        EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);

        Operation operation = clipboardHolder
                .createPaste(editSession, pasteWorldData)
                .to(pasteLocation)
                .ignoreAirBlocks(!withAir)
                .build();

        Operations.completeLegacy(operation);
        return true;
    }
    catch (IOException | MaxChangedBlocksException e) {
        FunnyGuilds.getInstance().getPluginLogger().error("Could not paste schematic: " + schematicFile.getAbsolutePath(), e);
        return false;
    }
}
 
Example #2
Source File: SimpleClipboardFloor.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Deprecated
public void generate(EditSession session) {
	Region region = floorClipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(floorClipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example #3
Source File: DefaultFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	Clipboard clipboard = floor.getClipboard();
	
	Region region = clipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(clipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example #4
Source File: PasteBuilder.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Build the operation.
 *
 * @return the operation
 */
public Operation build() {
    Extent extent = clipboard;
    if (!transform.isIdentity()) {
        extent = new BlockTransformExtent(extent, transform, targetWorldData.getBlockRegistry());
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
    copy.setTransform(transform);
    copy.setCopyEntities(!ignoreEntities);
    copy.setCopyBiomes((!ignoreBiomes) && (!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes()));
    if (this.canApply != null) {
        copy.setFilterFunction(this.canApply);
    }
    if (targetExtent instanceof EditSession) {
        Mask sourceMask = ((EditSession) targetExtent).getSourceMask();
        if (sourceMask != null) {
            new MaskTraverser(sourceMask).reset(extent);
            copy.setSourceMask(sourceMask);
            ((EditSession) targetExtent).setSourceMask(null);
        }
    }
    if (ignoreAirBlocks) {
        copy.setSourceMask(new ExistingBlockMask(clipboard));
    }
    return copy;
}
 
Example #5
Source File: SchematicHandler13.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static ArrayList<Integer> pasteSchematic(Location loc, String path) throws Exception{
	Bukkit.getLogger().info("[UhcCore] Pasting "+path);
	File schematic = new File(path);
       World world = BukkitAdapter.adapt(loc.getWorld());

       ClipboardFormat format = ClipboardFormats.findByFile(schematic);
       ClipboardReader reader = format.getReader(new FileInputStream(schematic));
       Clipboard clipboard = reader.read();

       EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);

       enableWatchdog(editSession);

       Operation operation = new ClipboardHolder(clipboard)
               .createPaste(editSession)
               .to(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()))
               .ignoreAirBlocks(false)
               .build();

       Operations.complete(operation);
       editSession.flushSession();

	ArrayList<Integer> dimensions = new ArrayList<>();
	dimensions.add(clipboard.getDimensions().getY());
	dimensions.add(clipboard.getDimensions().getX());
	dimensions.add(clipboard.getDimensions().getZ());
	
	Bukkit.getLogger().info("[UhcCore] Successfully pasted '"+path+"' at "+loc.getBlockX()+" "+loc.getBlockY()+" "+loc.getBlockZ());
	return dimensions;
}
 
Example #6
Source File: PasteSchematicEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    try {
        Location location = loc.getLocation(playerID);
        ClipboardFormat format = ClipboardFormats.findByFile(file);
        if (format == null) {
            throw new IOException("Unknown Schematic Format");
        }

        Clipboard clipboard;
        try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
            clipboard = reader.read();
        }


        try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(location.getWorld()), -1)) {
            Operation operation = new ClipboardHolder(clipboard)
                    .createPaste(editSession)
                    .to(BukkitAdapter.asBlockVector(location))
                    .ignoreAirBlocks(noAir)
                    .build();

            Operations.complete(operation);
        }
    } catch (IOException | WorldEditException e) {
        LogUtils.getLogger().log(Level.WARNING, "Error while pasting a schematic: " + e.getMessage());
        LogUtils.logThrowable(e);
    }
    return null;
}
 
Example #7
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static void loadIslandSchematic(final File file, final Location origin, PlayerPerk playerPerk) {
    log.finer("Trying to load schematic " + file);
    if (file == null || !file.exists() || !file.canRead()) {
        LogUtil.log(Level.WARNING, "Unable to load schematic " + file);
    }
    boolean noAir = false;
    BlockVector3 to = BlockVector3.at(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
    EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(origin.getWorld()), -1);
    editSession.setFastMode(true);
    ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(origin);
    if (region != null) {
        editSession.setMask(new RegionMask(getRegion(origin.getWorld(), region)));
    }
    try {
        ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(file);
        try (InputStream in = new FileInputStream(file)) {
            Clipboard clipboard = clipboardFormat.getReader(in).read();
            Operation operation = new ClipboardHolder(clipboard)
                    .createPaste(editSession)
                    .to(to)
                    .ignoreAirBlocks(noAir)
                    .build();
            Operations.completeBlindly(operation);
        }
        editSession.flushSession();
    } catch (IOException e) {
        log.log(Level.INFO, "Unable to paste schematic " + file, e);
    }
}
 
Example #8
Source File: SelectionCommand.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public SelectionCommand(CommandExecutor<Contextual<? extends Operation>> delegate, String permission) {
    checkNotNull(delegate, "delegate");
    checkNotNull(permission, "permission");
    this.delegate = delegate;
    this.permission = permission;
    addParameter(delegate);
}
 
Example #9
Source File: FlattenedClipboardTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an operation to copy from the original clipboard to the given extent.
 *
 * @param target the target
 * @return the operation
 */
public Operation copyTo(Extent target) {
    BlockTransformExtent extent = new BlockTransformExtent(original, transform, worldData.getBlockRegistry());
    ForwardExtentCopy copy = new ForwardExtentCopy(extent, original.getRegion(), original.getOrigin(), target, original.getOrigin());
    copy.setTransform(transform);
    return copy;
}
 
Example #10
Source File: AbstractDelegateExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable Operation commit() {
    Operation ours = commitBefore();
    Operation other = null;
    if (extent != this) other = extent.commit();
    if (ours != null && other != null) {
        return new OperationQueue(ours, other);
    } else if (ours != null) {
        return ours;
    } else if (other != null) {
        return other;
    } else {
        return null;
    }
}
 
Example #11
Source File: EntityVisitor.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Operation resume(final RunContext run) throws WorldEditException {
    while (this.iterator.hasNext()) {
        if (this.function.apply(this.iterator.next())) {
            affected++;
        }
    }
    return null;
}
 
Example #12
Source File: WorldEdit7.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paste(File file, Location location, Island island) {
    try {
        ClipboardFormat format = ClipboardFormats.findByFile(file);
        ClipboardReader reader = format.getReader(new FileInputStream(file));
        Clipboard clipboard = reader.read();
        try (EditSession editSession = com.sk89q.worldedit.WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(location.getWorld()), -1)) {
            Operation operation = new ClipboardHolder(clipboard)
                    .createPaste(editSession)
                    .to(BlockVector3.at(location.getX(), location.getY(), location.getZ()))
                    .copyEntities(true)
                    .ignoreAirBlocks(true)
                    .build();
            Operations.complete(operation);
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().getLogger().warning("Failed to paste schematic using worldedit");
        IridiumSkyblock.schematic.paste(file, location, island);
    }
}
 
Example #13
Source File: ClipboardSpline.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected int pasteBlocks(Vector target, Vector offset, double angle) throws MaxChangedBlocksException {
    RoundedTransform transform = new RoundedTransform(new AffineTransform()
            .translate(offset)
            .rotateY(angle));
    if (!this.transform.isIdentity()) {
        transform = transform.combine(this.transform);
    }
    if (!originalTransform.isIdentity()) {
        transform = transform.combine(originalTransform);
    }

    // Pasting
    Clipboard clipboard = clipboardHolder.getClipboard();
    clipboard.setOrigin(center.subtract(centerOffset).round());
    clipboardHolder.setTransform(transform);

    Vector functionOffset = target.subtract(clipboard.getOrigin());
    final int offX = functionOffset.getBlockX();
    final int offY = functionOffset.getBlockY();
    final int offZ = functionOffset.getBlockZ();

    Operation operation = clipboardHolder
            .createPaste(editSession, editSession.getWorldData())
            .to(target)
            .ignoreAirBlocks(true)
            .filter(v -> buffer.add(v.getBlockX() + offX, v.getBlockY() + offY, v.getBlockZ() + offZ))
            .build();
    Operations.completeLegacy(operation);

    // Cleanup
    clipboardHolder.setTransform(originalTransform);
    clipboard.setOrigin(originalOrigin);

    return operation instanceof ForwardExtentCopy ? ((ForwardExtentCopy) operation).getAffected() : 0;
}
 
Example #14
Source File: BlockArrayClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Operation commit() {
    return null;
}
 
Example #15
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public Operation commit() {
    flush();
    return null;
}
 
Example #16
Source File: PatternExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Operation commit() {
    return null;
}
 
Example #17
Source File: NullExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Operation commitBefore() {
    return null;
}
 
Example #18
Source File: NullExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Operation commit() {
    return null;
}
 
Example #19
Source File: WEHook.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static Region pasteWithWE(Player p, File file) {
    Location<World> loc = p.getLocation();
    Region r = null;

    if (p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.WATER) ||
            p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.FLOWING_WATER)) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.needground");
        return null;
    }

    SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
    SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());

    LocalSession session = SpongeWorldEdit.inst().getSession(p);

    Closer closer = Closer.create();
    try {
        ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
        FileInputStream fis = closer.register(new FileInputStream(file));
        BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
        ClipboardReader reader = format.getReader(bis);

        WorldData worldData = ws.getWorldData();
        Clipboard clipboard = reader.read(ws.getWorldData());
        session.setClipboard(new ClipboardHolder(clipboard, worldData));

        Vector bmin = clipboard.getMinimumPoint();
        Vector bmax = clipboard.getMaximumPoint();

        Location<World> min = loc.add(bmin.getX(), bmin.getY(), bmin.getZ());
        Location<World> max = loc.add(bmax.getX(), bmax.getY(), bmax.getZ());

        PlayerRegion leader = new PlayerRegion(p.getUniqueId().toString(), p.getName());
        RegionBuilder rb2 = new DefineRegionBuilder(p, min, max, "", leader, new HashSet<>(), false);
        if (rb2.ready()) {
            r = rb2.build();
        }

        ClipboardHolder holder = session.getClipboard();

        Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
        Operations.completeLegacy(op);
    } catch (IOException | EmptyClipboardException | IncompleteRegionException | MaxChangedBlocksException e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
    }

    return r;
}
 
Example #20
Source File: EmptyExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
public Operation commit() {
    return null;
}
 
Example #21
Source File: DFSVisitor.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Operation resume(RunContext run) throws WorldEditException {
    NodePair current;
    Node from;
    Node adjacent;
    MutableBlockVector mutable = new MutableBlockVector();
    Vector mutable2 = new Vector();
    int countAdd, countAttempt;
    IntegerTrio[] dirs = getIntDirections();

    for (int layer = 0; !queue.isEmpty(); layer++) {
        current = queue.poll();
        from = current.to;
        hashQueue.remove(from);
        if (visited.containsKey(from)) {
            continue;
        }
        mutable.mutX(from.getX());
        mutable.mutY(from.getY());
        mutable.mutZ(from.getZ());
        function.apply(mutable);
        countAdd = 0;
        countAttempt = 0;
        for (IntegerTrio direction : dirs) {
            mutable2.mutX(from.getX() + direction.x);
            mutable2.mutY(from.getY() + direction.y);
            mutable2.mutZ(from.getZ() + direction.z);
            if (isVisitable(mutable, mutable2)) {
                adjacent = new Node(mutable2.getBlockX(), mutable2.getBlockY(), mutable2.getBlockZ());
                if ((current.from == null || !adjacent.equals(current.from))) {
                    AtomicInteger adjacentCount = visited.get(adjacent);
                    if (adjacentCount == null) {
                        if (countAdd++ < maxBranch) {
                            if (!hashQueue.contains(adjacent)) {
                                if (current.depth == maxDepth) {
                                    countAttempt++;
                                } else {
                                    hashQueue.add(adjacent);
                                    queue.addFirst(new NodePair(from, adjacent, current.depth + 1));
                                }
                            } else {
                                countAttempt++;
                            }
                        } else {
                            countAttempt++;
                        }
                    } else if (adjacentCount.decrementAndGet() == 0) {
                        visited.remove(adjacent);
                    } else if (hashQueue.contains(adjacent)) {
                        countAttempt++;
                    }
                }
            }
        }
        if (countAttempt > 0) {
            visited.put(from, new AtomicInteger(countAttempt));
        }
        affected++;
    }
    return null;
}
 
Example #22
Source File: LocalWorldAdapter.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public Operation commit() {
    return world.commit();
}
 
Example #23
Source File: IDelegateFaweQueue.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
default Operation commit() {
    return getQueue().commit();
}
 
Example #24
Source File: AbstractDelegateExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
protected Operation commitBefore() {
    return null;
}
 
Example #25
Source File: Extent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
default Operation commit() {
    return null;
}
 
Example #26
Source File: CopyPastaBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void build(final EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    FawePlayer fp = editSession.getPlayer();
    ClipboardHolder clipboard = session.getExistingClipboard();
    if (clipboard == null) {
        if (editSession.getExtent() instanceof VisualExtent) {
            return;
        }
        Mask mask = editSession.getMask();
        if (mask == null) {
            mask = Masks.alwaysTrue();
        }
        final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
        final int size2 = (int) (size * size);
        final int minY = position.getBlockY();
        mask = new AbstractDelegateMask(mask) {
            @Override
            public boolean test(Vector vector) {
                if (super.test(vector) && vector.getBlockY() >= minY) {
                    BaseBlock block = editSession.getLazyBlock(vector);
                    if (block.getId() != 0) {
                        builder.add(vector, EditSession.nullBlock, block);
                        return true;
                    }
                }
                return false;
            }
        };
        // Add origin
        mask.test(position);
        RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size, editSession);
        visitor.visit(position);
        Operations.completeBlindly(visitor);
        // Build the clipboard
        Clipboard newClipboard = builder.build();
        newClipboard.setOrigin(position);
        ClipboardHolder holder = new ClipboardHolder(newClipboard, editSession.getWorld().getWorldData());
        session.setClipboard(holder);
        int blocks = builder.size();
        BBC.COMMAND_COPY.send(fp, blocks);
        return;
    } else {
        AffineTransform transform = null;
        if (randomRotate) {
            if (transform == null) transform = new AffineTransform();
            int rotate = 90 * PseudoRandom.random.nextInt(4);
            transform = transform.rotateY(rotate);
        }
        if (autoRotate) {
            if (transform == null) transform = new AffineTransform();
            Location loc = editSession.getPlayer().getPlayer().getLocation();
            float yaw = loc.getYaw();
            float pitch = loc.getPitch();
            transform = transform.rotateY((-yaw) % 360);
            transform = transform.rotateX(pitch - 90);
        }
        if (transform != null && !transform.isIdentity()) {
            clipboard.setTransform(transform);
        }
        Clipboard faweClip = clipboard.getClipboard();
        Region region = faweClip.getRegion();

        Operation operation = clipboard
                .createPaste(editSession, editSession.getWorldData())
                .to(position.add(0, 1, 0))
                .ignoreAirBlocks(true)
                .build();
        Operations.completeLegacy(operation);
        editSession.flushQueue();
    }
}
 
Example #27
Source File: ImmutableVirtualWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Operation commit() {
    return null;
}
 
Example #28
Source File: SimpleWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
default @Nullable
Operation commit() {
    return null;
}
 
Example #29
Source File: WorldWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public Operation commit() {
    return parent.commit();
}
 
Example #30
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Operation commit() {
    return null;
}