Java Code Examples for com.sk89q.worldedit.session.ClipboardHolder#getClipboard()

The following examples show how to use com.sk89q.worldedit.session.ClipboardHolder#getClipboard() . 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: RandomFullClipboardPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
    AffineTransform transform = new AffineTransform();
    if (randomRotate) {
        transform = transform.rotateY(PseudoRandom.random.random(4) * 90);
        holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
    }
    if (randomFlip) {
        transform = transform.scale(new Vector(1, 0, 0).multiply(-2).add(1, 1, 1));
    }
    if (!transform.isIdentity()) {
        holder.setTransform(transform);
    }
    Clipboard clipboard = holder.getClipboard();
    Schematic schematic = new Schematic(clipboard);
    Transform newTransform = holder.getTransform();
    if (newTransform.isIdentity()) {
        schematic.paste(extent, setPosition, false);
    } else {
        schematic.paste(extent, worldData, setPosition, false, newTransform);
    }
    return true;
}
 
Example 2
Source File: SchemGen.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean spawn(PseudoRandom random, int x, int z) throws WorldEditException {
    mutable.mutX(x);
    mutable.mutZ(z);
    int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255);
    if (y == -1) return false;
    mutable.mutY(y);
    if (!mask.test(mutable)) {
        return false;
    }
    mutable.mutY(y + 1);
    ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
    if (randomRotate) {
        holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
    }
    Clipboard clipboard = holder.getClipboard();
    Schematic schematic = new Schematic(clipboard);
    Transform transform = holder.getTransform();
    if (transform.isIdentity()) {
        schematic.paste(extent, mutable, false);
    } else {
        schematic.paste(extent, worldData, mutable, false, transform);
    }
    mutable.mutY(y);
    return true;
}
 
Example 3
Source File: BrushCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"clipboard"},
        usage = "",
        desc = "Choose the clipboard brush (Recommended: `/br copypaste`)",
        help =
                "Chooses the clipboard brush.\n" +
                        "The -a flag makes it not paste air.\n" +
                        "Without the -p flag, the paste will appear centered at the target location. " +
                        "With the flag, then the paste will appear relative to where you had " +
                        "stood relative to the copied area when you copied it."
)
@CommandPermissions("worldedit.brush.clipboard")
public BrushSettings clipboardBrush(Player player, LocalSession session, @Switch('a') boolean ignoreAir, @Switch('p') boolean usingOrigin, CommandContext context) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    Clipboard clipboard = holder.getClipboard();

    Vector size = clipboard.getDimensions();

    WorldEdit.getInstance().checkMaxBrushRadius(size.getBlockX());
    WorldEdit.getInstance().checkMaxBrushRadius(size.getBlockY());
    WorldEdit.getInstance().checkMaxBrushRadius(size.getBlockZ());
    return set(session, context, new ClipboardBrush(holder, ignoreAir, usingOrigin));
}
 
Example 4
Source File: ClipboardCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"/flip"},
        usage = "[<direction>]",
        desc = "Flip the contents of the clipboard",
        help =
                "Flips the contents of the clipboard across the point from which the copy was made.\n",
        min = 0,
        max = 1
)
@CommandPermissions("worldedit.clipboard.flip")
public void flip(Player player, LocalSession session,
                 @Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    Clipboard clipboard = holder.getClipboard();
    AffineTransform transform = new AffineTransform();
    transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1));
    holder.setTransform(transform.combine(holder.getTransform()));
    BBC.COMMAND_FLIPPED.send(player);
}
 
Example 5
Source File: PatternCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#fullcopy"},
        desc = "Places your full clipboard at each block",
        usage = "[schem|folder|url=#copy] [rotate=false] [flip=false]",
        min = 0,
        max = 2
)
public Pattern fullcopy(Player player, Extent extent, LocalSession session, @Optional("#copy") String location, @Optional("false") boolean rotate, @Optional("false") boolean flip) throws EmptyClipboardException, InputParseException, IOException {
    List<ClipboardHolder> clipboards;
    switch (location.toLowerCase()) {
        case "#copy":
        case "#clipboard":
            ClipboardHolder clipboard = session.getExistingClipboard();
            if (clipboard == null) {
                throw new InputParseException("To use #fullcopy, please first copy something to your clipboard");
            }
            if (!rotate && !flip) {
                return new FullClipboardPattern(extent, clipboard.getClipboard());
            }
            clipboards = Collections.singletonList(clipboard);
            break;
        default:
            MultiClipboardHolder multi = ClipboardFormat.SCHEMATIC.loadAllFromInput(player, player.getWorld().getWorldData(), location, true);
            clipboards = multi != null ? multi.getHolders() : null;
            break;
    }
    if (clipboards == null) {
        throw new InputParseException("#fullcopy:<source>");
    }
    return new RandomFullClipboardPattern(extent, player.getWorld().getWorldData(), clipboards, rotate, flip);
}
 
Example 6
Source File: WorldEditHelper.java    From WorldEditSelectionVisualizer with MIT License 4 votes vote down vote up
public void updatePlayerVisualization(PlayerVisualizerInfos playerInfo, SelectionType type) {
    Player player = playerInfo.getPlayer();
    LocalSession session;
    try {
        session = worldEditPlugin.getSession(player);
    } catch (Exception e) {
        // sometimes after a reload getSession create errors with WorldEdit, this prevent error spam
        return;
    }

    PlayerSelection playerSelection = playerInfo.getSelection(type).orElse(null);

    if (playerSelection == null || session == null) {
        return;
    }

    Vector3d origin = Vector3d.ZERO;
    Region region;

    if (type == SelectionType.CLIPBOARD) {
        ClipboardHolder clipboardHolder = getClipboardHolder(session);

        if (clipboardHolder == null) {
            playerSelection.resetSelection();
            return;
        }

        Clipboard clipboard = clipboardHolder.getClipboard();
        Transform transform = clipboardHolder.getTransform();

        origin = plugin.getCompatibilityHelper().adaptClipboard(clipboard).getOrigin();
        region = clipboard.getRegion().clone();

        if (!transform.isIdentity()) {
            region = plugin.getCompatibilityHelper().adaptRegion(region).transform(transform, origin);
        }
    } else {
        region = getSelectedRegion(session);
    }

    if (region == null) {
        playerSelection.resetSelection();
        return;
    }

    if (type == SelectionType.SELECTION && (region.getWorld() == null || !region.getWorld().getName().equals(player.getWorld().getName()))) {
        playerSelection.resetSelection();
        return;
    }

    RegionAdapter regionAdapter = plugin.getCompatibilityHelper().adaptRegion(region);
    RegionInfos regionInfos = regionAdapter.getRegionsInfos();

    if (regionInfos.equals(playerSelection.getLastSelectedRegion())) {
        SelectionPoints points = playerSelection.getSelectionPoints();
        if (points == null || points.origin().equals(origin)) {
            return;
        }
    }

    if (!player.hasPermission("wesv.use")) {
        playerSelection.resetSelection(regionInfos);
        return;
    }

    GlobalSelectionConfig config = plugin.getSelectionConfig(type);
    if (region.getArea() > config.getMaxSelectionSize()) {
        if (!playerSelection.isLastSelectionTooLarge()) {
            String message = plugin.getMessage("selection-too-large").replace("%blocks%", Integer.toString(config.getMaxSelectionSize()));
            plugin.getCompatibilityHelper().sendActionBar(player, message);
        }

        playerSelection.resetSelection(regionInfos);
        playerSelection.setLastSelectionTooLarge(true);
        return;
    }

    plugin.updateHoldingSelectionItem(playerInfo);

    Bukkit.getPluginManager().callEvent(new SelectionChangeEvent(player, region));

    ShapeProcessor<?> shapeProcessor = shapeProcessors.get(region.getClass());

    if (shapeProcessor != null) {
        playerSelection.updateSelection(shapeProcessor.processSelection(regionAdapter, config, origin), regionInfos, config.getFadeDelay());
    } else {
        // Unsupported selection type
        playerSelection.resetSelection(regionInfos);
    }
}
 
Example 7
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 8
Source File: ClipboardSpline.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor with position-correction. Use this constructor for an interpolation implementation that needs position-correction.
 * <p>
 * Some interpolation implementations calculate the position on the curve (used by {@link #pastePosition(double)})
 * based on an equidistant distribution of the nodes on the curve. For example: on a spline with 5 nodes position 0.0 would refer
 * to the first node, 0.25 to the second, 0.5 to the third, ... .<br>
 * By providing this method with the amount of nodes used by the interpolation implementation the distribution of the
 * nodes is converted to a proportional distribution based on the length between two adjacent nodes calculated by {@link Interpolation#arcLength(double, double)}.<br>
 * This means that the distance between two positions used to paste the clipboard (e.g. 0.75 - 0.5 = 0.25) on the curve
 * will always amount to that part of the length (e.g. 40 units) of the curve. In this example it would amount to
 * 0.25 * 40 = 10 units of curve length between these two positions.
 * <p>
 * Be advised that currently subsequent changes to the interpolation parameters may not be supported.
 * @param editSession     The EditSession which will be used when pasting the clipboard content
 * @param clipboardHolder The clipboard that will be pasted along the spline
 * @param interpolation   An implementation of the interpolation algorithm used to calculate the curve
 * @param nodeCount       The number of nodes provided to the interpolation object
 */
public ClipboardSpline(EditSession editSession, ClipboardHolder clipboardHolder, Interpolation interpolation, Transform transform, int nodeCount) {
    super(editSession, interpolation, nodeCount);
    this.clipboardHolder = clipboardHolder;

    this.originalTransform = clipboardHolder.getTransform();
    Clipboard clipboard = clipboardHolder.getClipboard();
    this.originalOrigin = clipboard.getOrigin();

    Region region = clipboard.getRegion();
    Vector origin = clipboard.getOrigin();
    center = region.getCenter().setY(origin.getY() - 1);
    this.centerOffset = center.subtract(center.round());
    this.center = center.subtract(centerOffset);
    this.transform = transform;
    this.buffer = new LocalBlockVectorSet();
}
 
Example 9
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void addSchems(BufferedImage img, Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException {
    if (img.getWidth() != getWidth() || img.getHeight() != getLength())
        throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
    double doubleRarity = rarity / 100d;
    int index = 0;
    AffineTransform identity = new AffineTransform();
    LocalBlockVector2DSet placed = new LocalBlockVector2DSet();
    for (int z = 0; z < getLength(); z++) {
        mutable.mutZ(z);
        for (int x = 0; x < getWidth(); x++, index++) {
            int y = heights.getByte(index) & 0xFF;
            int height = img.getRGB(x, z) & 0xFF;
            if (height == 0 || PseudoRandom.random.nextInt(256) > height * doubleRarity) {
                continue;
            }
            mutable.mutX(x);
            mutable.mutY(y);
            if (!mask.test(mutable)) {
                continue;
            }
            if (placed.containsRadius(x, z, distance)) {
                continue;
            }
            placed.add(x, z);
            ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
            if (randomRotate) {
                int rotate = PseudoRandom.random.random(4) * 90;
                if (rotate != 0) {
                    holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
                } else {
                    holder.setTransform(identity);
                }
            }
            Clipboard clipboard = holder.getClipboard();
            Schematic schematic = new Schematic(clipboard);
            Transform transform = holder.getTransform();
            if (transform.isIdentity()) {
                schematic.paste(this, mutable, false);
            } else {
                schematic.paste(this, worldData, mutable, false, transform);
            }
            if (x + distance < getWidth()) {
                x += distance;
                index += distance;
            } else {
                break;
            }
        }
    }
}
 
Example 10
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void addSchems(Mask mask, WorldData worldData, List<ClipboardHolder> clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException {
    int scaledRarity = (256 * rarity) / 100;
    int index = 0;
    AffineTransform identity = new AffineTransform();
    LocalBlockVector2DSet placed = new LocalBlockVector2DSet();
    for (int z = 0; z < getLength(); z++) {
        mutable.mutZ(z);
        for (int x = 0; x < getWidth(); x++, index++) {
            int y = heights.getByte(index) & 0xFF;
            if (PseudoRandom.random.nextInt(256) > scaledRarity) {
                continue;
            }
            mutable.mutX(x);
            mutable.mutY(y);
            if (!mask.test(mutable)) {
                continue;
            }
            if (placed.containsRadius(x, z, distance)) {
                continue;
            }
            mutable.mutY(y + 1);
            placed.add(x, z);
            ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size()));
            if (randomRotate) {
                int rotate = PseudoRandom.random.random(4) * 90;
                if (rotate != 0) {
                    holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90));
                } else {
                    holder.setTransform(identity);
                }
            }
            Clipboard clipboard = holder.getClipboard();
            Schematic schematic = new Schematic(clipboard);
            Transform transform = holder.getTransform();
            if (transform.isIdentity()) {
                schematic.paste(this, mutable, false);
            } else {
                schematic.paste(this, worldData, mutable, false, transform);
            }
            if (x + distance < getWidth()) {
                x += distance;
                index += distance;
            } else {
                break;
            }
        }
    }
}
 
Example 11
Source File: CFICommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(
        aliases = {"paletteblocks", "colorpaletterblocks", "setcolorpaletteblocks"},
        usage = "<blocks|#clipboard|*>",
        desc = "Set the blocks used for coloring",
        help = "Allow only specific blocks to be used for coloring\n" +
                "`blocks` is a list of blocks e.g. stone,bedrock,wool\n" +
                "`#clipboard` will only use the blocks present in your clipboard."
)
@CommandPermissions("worldedit.anvil.cfi")
public void paletteblocks(FawePlayer fp, Player player, LocalSession session, @Optional String arg) throws ParameterException, EmptyClipboardException, InputParseException, FileNotFoundException {
    if (arg == null) {
        msg("What blocks do you want to color with?").newline()
        .text("&7[&aAll&7]").cmdTip(alias() + " PaletteBlocks *").text(" - All available blocks")
        .newline()
        .text("&7[&aClipboard&7]").cmdTip(alias() + " PaletteBlocks #clipboard").text(" - The blocks in your clipboard")
        .newline()
        .text("&7[&aList&7]").suggestTip(alias() + " PaletteBlocks stone,gravel").text(" - A comma separated list of blocks")
        .newline()
        .text("&7[&aComplexity&7]").cmdTip(alias() + " Complexity").text(" - Block textures within a complexity range")
        .newline()
        .text("&8< &7[&aBack&7]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "coloring"))
        .send(fp);
        return;
    }
    HeightMapMCAGenerator generator = assertSettings(fp).getGenerator();
    ParserContext context = new ParserContext();
    context.setActor(fp.getPlayer());
    context.setWorld(fp.getWorld());
    context.setSession(fp.getSession());
    context.setExtent(generator);
    Request.request().setExtent(generator);

    Set<BaseBlock> blocks;
    switch (arg.toLowerCase()) {
        case "true":
        case "*": {
            generator.setTextureUtil(Fawe.get().getTextureUtil());
            return;
        }
        case "#clipboard": {
            ClipboardHolder holder = fp.getSession().getClipboard();
            Clipboard clipboard = holder.getClipboard();
            boolean[] ids = new boolean[Character.MAX_VALUE + 1];
            for (Vector pt : clipboard.getRegion()) {
                ids[clipboard.getBlock(pt).getCombined()] = true;
            }
            blocks = new HashSet<>();
            for (int combined = 0; combined < ids.length; combined++) {
                if (ids[combined]) blocks.add(FaweCache.CACHE_BLOCK[combined]);
            }
            break;
        }
        default: {
            blocks = new HashSet<>();
            BlockPattern pattern = new BlockPattern(new BaseBlock(BlockID.AIR));
            PatternExtent extent = new PatternExtent(pattern);

            ParserContext parserContext = new ParserContext();
            parserContext.setActor(player);
            parserContext.setWorld(player.getWorld());
            parserContext.setSession(session);
            parserContext.setExtent(extent);
            Request.request().setExtent(extent);
            Mask mask = worldEdit.getMaskFactory().parseFromInput(arg, parserContext);
            TextureUtil tu = Fawe.get().getTextureUtil();
            for (int combinedId : tu.getValidBlockIds()) {
                BaseBlock block = FaweCache.CACHE_BLOCK[combinedId];
                pattern.setBlock(block);
                if (mask.test(Vector.ZERO)) blocks.add(block);
            }
            break;
        }
    }
    generator.setTextureUtil(new FilteredTextureUtil(Fawe.get().getTextureUtil(), blocks));
    coloring(fp);
}