@Command(
      aliases = {"clipboard", "copy"},
      usage = "",
      desc = "Choose the clipboard brush",
      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 void clipboardBrush(
      Player player,
      LocalSession session,
      EditSession editSession,
      @Switch('a') boolean ignoreAir,
      @Switch('p') boolean usingOrigin)
      throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    Clipboard clipboard = holder.getClipboard();

    Vector size = clipboard.getDimensions();

    worldEdit.checkMaxBrushRadius(size.getBlockX());
    worldEdit.checkMaxBrushRadius(size.getBlockY());
    worldEdit.checkMaxBrushRadius(size.getBlockZ());

    BrushTool tool = session.getBrushTool(player.getItemInHand());
    tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin), "worldedit.brush.clipboard");

    player.print("Clipboard brush shape equipped.");
  }
  @Command(
      aliases = {"/rotate"},
      usage = "<y-axis> [<x-axis>] [<z-axis>]",
      desc = "Rotate the contents of the clipboard",
      help =
          "Non-destructively rotate the contents of the clipboard.\n"
              + "Angles are provided in degrees and a positive angle will result in a clockwise rotation. "
              + "Multiple rotations can be stacked. Interpolation is not performed so angles should be a multiple of 90 degrees.\n")
  @CommandPermissions("worldedit.clipboard.rotate")
  public void rotate(
      Player player,
      LocalSession session,
      Double yRotate,
      @Optional Double xRotate,
      @Optional Double zRotate)
      throws WorldEditException {
    if ((yRotate != null && Math.abs(yRotate % 90) > 0.001)
        || xRotate != null && Math.abs(xRotate % 90) > 0.001
        || zRotate != null && Math.abs(zRotate % 90) > 0.001) {
      player.printDebug(
          "Note: Interpolation is not yet supported, so angles that are multiples of 90 is recommended.");
    }

    ClipboardHolder holder = session.getClipboard();
    AffineTransform transform = new AffineTransform();
    transform = transform.rotateY(-(yRotate != null ? yRotate : 0));
    transform = transform.rotateX(-(xRotate != null ? xRotate : 0));
    transform = transform.rotateZ(-(zRotate != null ? zRotate : 0));
    holder.setTransform(holder.getTransform().combine(transform));
    player.print("The clipboard copy has been rotated.");
  }
  @Command(
      aliases = {"/paste"},
      usage = "",
      flags = "sao",
      desc = "Paste the clipboard's contents",
      help =
          "Pastes the clipboard's contents.\n"
              + "Flags:\n"
              + "  -a skips air blocks\n"
              + "  -o pastes at the original position\n"
              + "  -s selects the region after pasting",
      min = 0,
      max = 0)
  @CommandPermissions("worldedit.clipboard.paste")
  @Logging(PLACEMENT)
  public void paste(
      Player player,
      LocalSession session,
      EditSession editSession,
      @Switch('a') boolean ignoreAirBlocks,
      @Switch('o') boolean atOrigin,
      @Switch('s') boolean selectPasted)
      throws WorldEditException {

    ClipboardHolder holder = session.getClipboard();
    Clipboard clipboard = holder.getClipboard();
    Region region = clipboard.getRegion();

    Vector to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player);
    Operation operation =
        holder
            .createPaste(editSession, editSession.getWorld().getWorldData())
            .to(to)
            .ignoreAirBlocks(ignoreAirBlocks)
            .build();
    Operations.completeLegacy(operation);

    if (selectPasted) {
      Vector clipboardOffset =
          clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
      Vector realTo = to.add(holder.getTransform().apply(clipboardOffset));
      Vector max =
          realTo.add(
              holder
                  .getTransform()
                  .apply(region.getMaximumPoint().subtract(region.getMinimumPoint())));
      RegionSelector selector = new CuboidRegionSelector(player.getWorld(), realTo, max);
      session.setRegionSelector(player.getWorld(), selector);
      selector.learnChanges();
      selector.explainRegionAdjust(player, session);
    }

    player.print("The clipboard has been pasted at " + to);
  }
 @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,
     EditSession editSession,
     @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(holder.getTransform().combine(transform));
   player.print("The clipboard copy has been flipped.");
 }