Java Code Examples for com.sk89q.worldedit.EditSession#getPlayer()

The following examples show how to use com.sk89q.worldedit.EditSession#getPlayer() . 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: CommandBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    int radius = (int) size;
    CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
    String replaced = command.replace("{x}", position.getBlockX() + "")
            .replace("{y}", Integer.toString(position.getBlockY()))
            .replace("{z}", Integer.toString(position.getBlockZ()))
            .replace("{world}", editSession.getQueue().getWorldName())
            .replace("{size}", Integer.toString(radius));

    FawePlayer fp = editSession.getPlayer();
    Player player = fp.getPlayer();
    WorldVectorFace face = player.getBlockTraceFace(256, true);
    if (face == null) {
        position = position.add(0, 1, 1);
    } else {
        position = face.getFaceVector();
    }
    fp.setSelection(selector);
    PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position)));
    List<String> cmds = StringMan.split(replaced, ';');
    for (String cmd : cmds) {
        CommandEvent event = new CommandEvent(wePlayer, cmd);
        CommandManager.getInstance().handleCommandOnCurrentThread(event);
    }
}
 
Example 2
Source File: ScatterCommand.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector position, Pattern p, double size) throws MaxChangedBlocksException {
    int radius = getDistance();
    CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
    String replaced = command.replace("{x}", position.getBlockX() + "")
            .replace("{y}", Integer.toString(position.getBlockY()))
            .replace("{z}", Integer.toString(position.getBlockZ()))
            .replace("{world}", editSession.getQueue().getWorldName())
            .replace("{size}", Integer.toString(radius));

    FawePlayer fp = editSession.getPlayer();
    Player player = fp.getPlayer();
    fp.setSelection(selector);
    PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position)));
    List<String> cmds = StringMan.split(replaced, ';');
    for (String cmd : cmds) {
        CommandEvent event = new CommandEvent(wePlayer, cmd);
        CommandManager.getInstance().handleCommandOnCurrentThread(event);
    }
}
 
Example 3
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();
    }
}