@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.");
  }
  /**
   * Called when a player interacts
   *
   * @param event Relevant event details
   */
  @EventHandler(event = PlayerInteractEvent.class)
  public void onPlayerInteract(PlayerInteractEvent event) {

    final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
    final LocalWorld world = player.getWorld();
    final WorldEdit we = plugin.getWorldEdit();

    PlayerInteractEvent.Action action = event.getAction();
    if (action == Action.LEFT_CLICK) {
      if (event.isAir() && ignoreLeftClickAir) {
        return;
      }

      if (!event.isAir()) {
        final Point clickedBlock = event.getInteractedPoint();
        final WorldVector pos =
            new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

        if (we.handleBlockLeftClick(player, pos)) {
          event.setCancelled(true);
        }
      }

      if (we.handleArmSwing(player)) {
        event.setCancelled(true);
      }

      if (!event.isAir() && !ignoreLeftClickAir) {
        final int taskId =
            Spout.getGame()
                .getScheduler()
                .scheduleSyncDelayedTask(
                    plugin,
                    new Runnable() {
                      public void run() {
                        ignoreLeftClickAir = false;
                      }
                    },
                    2);

        if (taskId != -1) {
          ignoreLeftClickAir = true;
        }
      }
    } else if (action == Action.RIGHT_CLICK) {
      if (!event.isAir()) {
        final Point clickedBlock = event.getInteractedPoint();
        final WorldVector pos =
            new WorldVector(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());

        if (we.handleBlockRightClick(player, pos)) {
          event.setCancelled(true);
        }
      }

      if (we.handleRightClick(player)) {
        event.setCancelled(true);
      }
    }
  }
  @Command(
      aliases = {"/fillr"},
      usage = "<block> <radius> [depth]",
      desc = "Fill a hole recursively",
      min = 2,
      max = 3)
  @CommandPermissions("worldedit.fill.recursive")
  @Logging(PLACEMENT)
  public void fillr(
      CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
      throws WorldEditException {

    Pattern pattern = we.getBlockPattern(player, args.getString(0));
    double radius = Math.max(1, args.getDouble(1));
    we.checkMaxRadius(radius);
    int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;

    Vector pos = session.getPlacementPosition(player);
    int affected = 0;
    if (pattern instanceof SingleBlockPattern) {
      affected =
          editSession.fillXZ(pos, ((SingleBlockPattern) pattern).getBlock(), radius, depth, true);
    } else {
      affected = editSession.fillXZ(pos, pattern, radius, depth, true);
    }
    player.print(affected + " block(s) have been created.");
  }
Example #4
0
  @Command(
      aliases = {"/redo", "redo"},
      usage = "[times] [player]",
      desc = "Redoes the last action (from history)",
      min = 0,
      max = 2)
  @CommandPermissions("worldedit.history.redo")
  public void redo(
      CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
      throws WorldEditException {

    int times = Math.max(1, args.getInteger(0, 1));

    for (int i = 0; i < times; ++i) {
      EditSession redone;
      if (args.argsLength() < 2) {
        redone = session.redo(session.getBlockBag(player));
      } else {
        player.checkPermission("worldedit.history.redo.other");
        LocalSession sess = we.getSession(args.getString(1));
        if (sess == null) {
          player.printError("Unable to find session for " + args.getString(1));
          break;
        }
        redone = sess.redo(session.getBlockBag(player));
      }
      if (redone != null) {
        player.print("Redo successful.");
        we.flushBlockBag(player, redone);
      } else {
        player.printError("Nothing left to redo.");
      }
    }
  }
Example #5
0
  /**
   * Remember an edit session.
   *
   * @param player
   * @param editSession
   */
  public void remember(Player player, EditSession editSession) {
    LocalPlayer wePlayer = wrapPlayer(player);
    LocalSession session = controller.getSession(wePlayer);

    session.remember(editSession);
    editSession.flushQueue();

    controller.flushBlockBag(wePlayer, editSession);
  }
Example #6
0
  /**
   * Gets the session for the player.
   *
   * @param player
   * @return
   */
  public EditSession createEditSession(Player player) {
    LocalPlayer wePlayer = wrapPlayer(player);
    LocalSession session = controller.getSession(wePlayer);
    BlockBag blockBag = session.getBlockBag(wePlayer);

    EditSession editSession =
        controller
            .getEditSessionFactory()
            .getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
    editSession.enableQueue();

    return editSession;
  }
  @Command(
      aliases = {"/move"},
      usage = "[count] [direction] [leave-id]",
      flags = "s",
      desc = "Move the contents of the selection",
      min = 0,
      max = 3)
  @CommandPermissions("worldedit.region.move")
  @Logging(ORIENTATION_REGION)
  public static void move(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
    Vector dir =
        we.getDirection(player, args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
    BaseBlock replace;

    // Replacement block argument
    if (args.argsLength() > 2) {
      replace = we.getBlock(player, args.getString(2));
    } else {
      replace = new BaseBlock(BlockID.AIR);
    }

    int affected =
        editSession.moveCuboidRegion(
            session.getSelection(player.getWorld()), dir, count, true, replace);

    if (args.hasFlag('s')) {
      try {
        Region region = session.getSelection(player.getWorld());
        region.expand(dir.multiply(count));
        region.contract(dir.multiply(count));

        session.getRegionSelector().learnChanges();
        session.getRegionSelector().explainRegionAdjust(player, session);
      } catch (RegionOperationException e) {
        player.printError(e.getMessage());
      }
    }

    player.print(affected + " blocks moved.");
  }
Example #8
0
  /**
   * Gets the region selection for the player.
   *
   * @param player
   * @return the selection or null if there was none
   */
  public Selection getSelection(Player player) {
    if (player == null) {
      throw new IllegalArgumentException("Null player not allowed");
    }
    if (!player.isOnline()) {
      throw new IllegalArgumentException("Offline player not allowed");
    }

    LocalSession session = controller.getSession(wrapPlayer(player));
    RegionSelector selector =
        session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));

    try {
      Region region = selector.getRegion();
      World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();

      if (region instanceof CuboidRegion) {
        return new CuboidSelection(world, selector, (CuboidRegion) region);
      } else if (region instanceof Polygonal2DRegion) {
        return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
      } else {
        return null;
      }
    } catch (IncompleteRegionException e) {
      return null;
    }
  }
  @Command(
      aliases = {"/overlay"},
      usage = "<block>",
      desc = "Set a block on top of blocks in the region",
      min = 1,
      max = 1)
  @CommandPermissions("worldedit.region.overlay")
  @Logging(REGION)
  public static void overlay(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    Pattern pat = we.getBlockPattern(player, args.getString(0));

    Region region = session.getSelection(player.getWorld());
    int affected = 0;
    if (pat instanceof SingleBlockPattern) {
      affected = editSession.overlayCuboidBlocks(region, ((SingleBlockPattern) pat).getBlock());
    } else {
      affected = editSession.overlayCuboidBlocks(region, pat);
    }
    player.print(affected + " block(s) have been overlayed.");
  }
Example #10
0
  @Command(
      aliases = {"/faces", "/outline"},
      usage = "<block>",
      desc = "Build the walls, ceiling, and floor of a selection",
      min = 1,
      max = 1)
  @CommandPermissions("worldedit.region.faces")
  @Logging(REGION)
  public static void faces(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    Pattern pattern = we.getBlockPattern(player, args.getString(0));
    int affected;
    if (pattern instanceof SingleBlockPattern) {
      affected =
          editSession.makeCuboidFaces(
              session.getSelection(player.getWorld()), ((SingleBlockPattern) pattern).getBlock());
    } else {
      affected = editSession.makeCuboidFaces(session.getSelection(player.getWorld()), pattern);
    }

    player.print(affected + " block(s) have been changed.");
  }
Example #11
0
  @Command(
      aliases = {"/hpyramid"},
      usage = "<block> <range>",
      desc = "Generate a hollow pyramid",
      min = 2,
      max = 2)
  @CommandPermissions({"worldedit.generation.pyramid"})
  @Logging(PLACEMENT)
  public static void hpyramid(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    Pattern block = we.getBlockPattern(player, args.getString(0));
    int size = Math.max(1, args.getInteger(1));
    Vector pos = session.getPlacementPosition(player);

    int affected = editSession.makePyramid(pos, block, size, false);

    player.findFreePosition();
    player.print(affected + " block(s) have been created.");
  }
Example #12
0
  public boolean actPrimary(
      ServerInterface server,
      LocalConfiguration config,
      LocalPlayer player,
      LocalSession session,
      WorldVector clicked) {

    BlockBag bag = session.getBlockBag(player);

    LocalWorld world = clicked.getWorld();
    EditSession editSession =
        WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag, player);

    try {
      editSession.setBlock(clicked, targetBlock);
    } catch (MaxChangedBlocksException e) {
    } finally {
      if (bag != null) {
        bag.flushChanges();
      }
      session.remember(editSession);
    }

    return true;
  }
Example #13
0
  @Command(
      aliases = {"/hsphere"},
      usage = "<block> <radius> [raised?] ",
      desc = "Generate a hollow sphere",
      min = 2,
      max = 3)
  @CommandPermissions({"worldedit.generation.sphere"})
  @Logging(PLACEMENT)
  public static void hsphere(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    Pattern block = we.getBlockPattern(player, args.getString(0));
    double radius = Math.max(1, args.getDouble(1));
    boolean raised =
        args.argsLength() > 2
            ? (args.getString(2).equalsIgnoreCase("true")
                || args.getString(2).equalsIgnoreCase("yes"))
            : false;

    Vector pos = session.getPlacementPosition(player);
    if (raised) {
      pos = pos.add(0, radius, 0);
    }

    int affected = editSession.makeSphere(pos, block, radius, false);
    player.findFreePosition();
    player.print(affected + " block(s) have been created.");
  }
  @Command(
      aliases = {"smooth"},
      usage = "[size] [iterations]",
      flags = "n",
      desc = "Choose the terrain softener brush",
      help =
          "Chooses the terrain softener brush.\n"
              + "The -n flag makes it only consider naturally occurring blocks.",
      min = 0,
      max = 2)
  @CommandPermissions("worldedit.brush.smooth")
  public void smoothBrush(
      Player player,
      LocalSession session,
      EditSession editSession,
      @Optional("2") double radius,
      @Optional("4") int iterations,
      @Switch('n') boolean naturalBlocksOnly)
      throws WorldEditException {

    worldEdit.checkMaxBrushRadius(radius);

    BrushTool tool = session.getBrushTool(player.getItemInHand());
    tool.setSize(radius);
    tool.setBrush(new SmoothBrush(iterations, naturalBlocksOnly), "worldedit.brush.smooth");

    player.print(
        String.format(
            "Smooth brush equipped (%.0f x %dx, using "
                + (naturalBlocksOnly ? "natural blocks only" : "any block")
                + ").",
            radius,
            iterations));
  }
  @Command(
      aliases = {"gravity", "grav"},
      usage = "[radius]",
      flags = "h",
      desc = "Gravity brush",
      help =
          "This brush simulates the affect of gravity.\n"
              + "The -h flag makes it affect blocks starting at the world's max y, "
              + "instead of the clicked block's y + radius.",
      min = 0,
      max = 1)
  @CommandPermissions("worldedit.brush.gravity")
  public void gravityBrush(
      Player player,
      LocalSession session,
      EditSession editSession,
      @Optional("5") double radius,
      @Switch('h') boolean fromMaxY)
      throws WorldEditException {
    worldEdit.checkMaxBrushRadius(radius);

    BrushTool tool = session.getBrushTool(player.getItemInHand());
    tool.setSize(radius);
    tool.setBrush(new GravityBrush(fromMaxY), "worldedit.brush.gravity");

    player.print(String.format("Gravity brush equipped (%.0f).", radius));
  }
  @Command(
      aliases = {"cylinder", "cyl", "c"},
      usage = "<block> [radius] [height]",
      flags = "h",
      desc = "Choose the cylinder brush",
      help = "Chooses the cylinder brush.\n" + "The -h flag creates hollow cylinders instead.",
      min = 1,
      max = 3)
  @CommandPermissions("worldedit.brush.cylinder")
  public void cylinderBrush(
      Player player,
      LocalSession session,
      EditSession editSession,
      Pattern fill,
      @Optional("2") double radius,
      @Optional("1") int height,
      @Switch('h') boolean hollow)
      throws WorldEditException {
    worldEdit.checkMaxBrushRadius(radius);
    worldEdit.checkMaxBrushRadius(height);

    BrushTool tool = session.getBrushTool(player.getItemInHand());
    tool.setFill(fill);
    tool.setSize(radius);

    if (hollow) {
      tool.setBrush(new HollowCylinderBrush(height), "worldedit.brush.cylinder");
    } else {
      tool.setBrush(new CylinderBrush(height), "worldedit.brush.cylinder");
    }

    player.print(String.format("Cylinder brush shape equipped (%.0f by %d).", radius, height));
  }
Example #17
0
  @Command(
      aliases = {"/set"},
      usage = "<block>",
      desc = "Set all the blocks inside the selection to a block",
      min = 1,
      max = 1)
  @CommandPermissions("worldedit.region.set")
  @Logging(REGION)
  public static void set(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    Pattern pattern = we.getBlockPattern(player, args.getString(0));

    int affected;

    if (pattern instanceof SingleBlockPattern) {
      affected =
          editSession.setBlocks(
              session.getSelection(player.getWorld()), ((SingleBlockPattern) pattern).getBlock());
    } else {
      affected = editSession.setBlocks(session.getSelection(player.getWorld()), pattern);
    }

    player.print(affected + " block(s) have been changed.");
  }
Example #18
0
 /** Called on plugin disable. */
 @Override
 public void onDisable() {
   for (Player player : getServer().getOnlinePlayers()) {
     LocalPlayer lPlayer = wrapPlayer(player);
     if (controller.getSession(lPlayer).hasCUISupport()) {
       lPlayer.dispatchCUIHandshake();
     }
   }
   controller.clearSessions();
   for (Handler h : controller.commandLogger.getHandlers()) {
     h.close();
   }
   config.unload();
   server.unregisterCommands();
   this.getServer().getScheduler().cancelTasks(this);
 }
  @Command(
      aliases = {"/removenear", "removenear"},
      usage = "<block> [size]",
      desc = "Remove blocks near you.",
      min = 1,
      max = 2)
  @CommandPermissions("worldedit.removenear")
  @Logging(PLACEMENT)
  public void removeNear(
      CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
      throws WorldEditException {

    BaseBlock block = we.getBlock(player, args.getString(0), true);
    int size = Math.max(1, args.getInteger(1, 50));
    we.checkMaxRadius(size);

    int affected =
        editSession.removeNear(session.getPlacementPosition(player), block.getType(), size);
    player.print(affected + " block(s) have been removed.");
  }
Example #20
0
  /**
   * Wrap an operation into an EditSession.
   *
   * @param player
   * @param op
   * @throws Throwable
   */
  public void perform(Player player, WorldEditOperation op) throws Throwable {
    LocalPlayer wePlayer = wrapPlayer(player);
    LocalSession session = controller.getSession(wePlayer);

    EditSession editSession = createEditSession(player);
    try {
      op.run(session, wePlayer, editSession);
    } finally {
      remember(player, editSession);
    }
  }
Example #21
0
  /** Called on plugin enable. */
  @Override
  public void onEnable() {
    final String pluginYmlVersion = getDescription().getVersion();
    final String manifestVersion = WorldEdit.getVersion();

    if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) {
      WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")");
    }

    // Make the data folders that WorldEdit uses
    getDataFolder().mkdirs();

    // Create the default configuration file
    createDefaultConfiguration("config.yml");

    // Set up configuration and such, including the permissions
    // resolver
    config =
        new BukkitConfiguration(
            new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
    PermissionsResolverManager.initialize(this);

    // Load the configuration
    config.load();

    // Setup interfaces
    server = new BukkitServerInterface(this, getServer());
    controller = new WorldEdit(server, config);
    WorldEdit.getInstance().logger.setParent(Bukkit.getLogger());
    api = new WorldEditAPI(this);
    getServer()
        .getMessenger()
        .registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
    getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL);
    // Now we can register events!
    getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);

    getServer()
        .getScheduler()
        .scheduleAsyncRepeatingTask(this, new SessionTimer(controller, getServer()), 120, 120);
  }
  @Command(
      aliases = {"/ex", "/ext", "/extinguish", "ex", "ext", "extinguish"},
      usage = "[radius]",
      desc = "Extinguish nearby fire",
      min = 0,
      max = 1)
  @CommandPermissions("worldedit.extinguish")
  @Logging(PLACEMENT)
  public void extinguish(
      CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
      throws WorldEditException {

    LocalConfiguration config = we.getConfiguration();

    int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
    int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : defaultRadius;
    we.checkMaxRadius(size);

    int affected = editSession.removeNear(session.getPlacementPosition(player), 51, size);
    player.print(affected + " block(s) have been removed.");
  }
  public static void help(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession) {
    final CommandsManager<LocalPlayer> commandsManager = we.getCommandsManager();

    if (args.argsLength() == 0) {
      SortedSet<String> commands =
          new TreeSet<String>(
              new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                  final int ret =
                      o1.replaceAll("/", "").compareToIgnoreCase(o2.replaceAll("/", ""));
                  if (ret == 0) {
                    return o1.compareToIgnoreCase(o2);
                  }
                  return ret;
                }
              });
      commands.addAll(commandsManager.getCommands().keySet());

      StringBuilder sb = new StringBuilder();
      boolean first = true;
      for (String command : commands) {
        if (!first) {
          sb.append(", ");
        }

        sb.append('/');
        sb.append(command);
        first = false;
      }

      player.print(sb.toString());

      return;
    }

    String command = args.getJoinedStrings(0).replaceAll("/", "");

    String helpMessage = commandsManager.getHelpMessages().get(command);
    if (helpMessage == null) {
      player.printError("Unknown command '" + command + "'.");
      return;
    }

    player.print(helpMessage);
  }
Example #24
0
  @Command(
      aliases = {"/replace"},
      usage = "[from-block] <to-block>",
      desc = "Replace all blocks in the selection with another",
      flags = "f",
      min = 1,
      max = 2)
  @CommandPermissions("worldedit.region.replace")
  @Logging(REGION)
  public static void replace(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession)
      throws WorldEditException {

    Set<BaseBlock> from;
    Pattern to;
    if (args.argsLength() == 1) {
      from = null;
      to = we.getBlockPattern(player, args.getString(0));
    } else {
      from = we.getBlocks(player, args.getString(0), true, !args.hasFlag('f'));
      to = we.getBlockPattern(player, args.getString(1));
    }

    int affected = 0;
    if (to instanceof SingleBlockPattern) {
      affected =
          editSession.replaceBlocks(
              session.getSelection(player.getWorld()), from, ((SingleBlockPattern) to).getBlock());
    } else {
      affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from, to);
    }

    player.print(affected + " block(s) have been replaced.");
  }
Example #25
0
  /** Called on WorldEdit command. */
  @Override
  public boolean onCommand(
      CommandSender sender, org.bukkit.command.Command cmd, String commandLabel, String[] args) {

    // Add the command to the array because the underlying command handling
    // code of WorldEdit expects it
    String[] split = new String[args.length + 1];
    System.arraycopy(args, 0, split, 1, args.length);
    split[0] = "/" + cmd.getName();

    controller.handleCommand(wrapCommandSender(sender), split);

    return true;
  }
  @Command(
      aliases = {"/replacenear", "replacenear"},
      usage = "<size> <from-id> <to-id>",
      desc = "Replace nearby blocks",
      flags = "f",
      min = 3,
      max = 3)
  @CommandPermissions("worldedit.replacenear")
  @Logging(PLACEMENT)
  public void replaceNear(
      CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
      throws WorldEditException {

    int size = Math.max(1, args.getInteger(0));
    int affected;
    Set<BaseBlock> from;
    Pattern to;
    if (args.argsLength() == 2) {
      from = null;
      to = we.getBlockPattern(player, args.getString(1));
    } else {
      from = we.getBlocks(player, args.getString(1), true, !args.hasFlag('f'));
      to = we.getBlockPattern(player, args.getString(2));
    }

    Vector base = session.getPlacementPosition(player);
    Vector min = base.subtract(size, size, size);
    Vector max = base.add(size, size, size);
    Region region = new CuboidRegion(player.getWorld(), min, max);

    if (to instanceof SingleBlockPattern) {
      affected = editSession.replaceBlocks(region, from, ((SingleBlockPattern) to).getBlock());
    } else {
      affected = editSession.replaceBlocks(region, from, to);
    }
    player.print(affected + " block(s) have been replaced.");
  }
Example #27
0
  @Command(
      aliases = {"/cut"},
      usage = "[leave-id]",
      desc = "Вырезает выделенную территорию в буфер обмена",
      help =
          "Вырезает выделенную территорию в буфер обмена\n"
              + "Флаги:\n"
              + "  -e controls определяет, будут ли объекты копироваться в буфер обмена\n"
              + "ПРЕДУПРЕЖДЕНИЕ: Вырезанные и вставленные объекты не могут быть отменены!",
      flags = "e",
      min = 0,
      max = 1)
  @CommandPermissions("worldedit.clipboard.cut")
  @Logging(REGION)
  public void cut(
      CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
      throws WorldEditException {

    BaseBlock block = new BaseBlock(BlockID.AIR);
    LocalWorld world = player.getWorld();

    if (args.argsLength() > 0) {
      block = we.getBlock(player, args.getString(0));
    }

    Region region = session.getSelection(world);
    Vector min = region.getMinimumPoint();
    Vector max = region.getMaximumPoint();
    Vector pos = session.getPlacementPosition(player);

    CuboidClipboard clipboard =
        new CuboidClipboard(max.subtract(min).add(new Vector(1, 1, 1)), min, min.subtract(pos));
    clipboard.copy(editSession);
    if (args.hasFlag('e')) {
      LocalEntity[] entities = world.getEntities(region);
      for (LocalEntity entity : entities) {
        clipboard.storeEntity(entity);
      }
      world.killEntities(entities);
    }
    session.setClipboard(clipboard);

    int affected = editSession.setBlocks(session.getSelection(world), block);
    player.print(
        affected
            + " "
            + StringUtil.plural(affected, "блок вырезан", "блока вырезано", "блоков вырезано")
            + ".");
  }
Example #28
0
  /**
   * Sets the region selection for a player.
   *
   * @param player
   * @param selection
   */
  public void setSelection(Player player, Selection selection) {
    if (player == null) {
      throw new IllegalArgumentException("Null player not allowed");
    }
    if (!player.isOnline()) {
      throw new IllegalArgumentException("Offline player not allowed");
    }
    if (selection == null) {
      throw new IllegalArgumentException("Null selection not allowed");
    }

    LocalSession session = controller.getSession(wrapPlayer(player));
    RegionSelector sel = selection.getRegionSelector();
    session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
    session.dispatchCUISelection(wrapPlayer(player));
  }
 @Override
 public void registerWorldEditEvents() {
   if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
     PS.get().worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
     final String version = PS.get().worldEdit.getDescription().getVersion();
     if ((version != null) && version.startsWith("5.")) {
       log("&cThis version of WorldEdit does not support PlotSquared.");
       log("&cPlease use WorldEdit 6+ for masking support");
       log("&c - http://builds.enginehub.org/job/worldedit");
     } else {
       getServer().getPluginManager().registerEvents(new WEListener(), this);
       WorldEdit.getInstance().getEventBus().register(new WESubscriber());
       MainCommand.subCommands.add(new WE_Anywhere());
     }
   }
 }
  @Command(
      aliases = {"butcher", "kill"},
      usage = "[radius]",
      flags = "plangbtfr",
      desc = "Butcher brush",
      help =
          "Kills nearby mobs within the specified radius.\n"
              + "Flags:\n"
              + "  -p also kills pets.\n"
              + "  -n also kills NPCs.\n"
              + "  -g also kills Golems.\n"
              + "  -a also kills animals.\n"
              + "  -b also kills ambient mobs.\n"
              + "  -t also kills mobs with name tags.\n"
              + "  -f compounds all previous flags.\n"
              + "  -r also destroys armor stands.\n"
              + "  -l currently does nothing.",
      min = 0,
      max = 1)
  @CommandPermissions("worldedit.brush.butcher")
  public void butcherBrush(
      Player player, LocalSession session, EditSession editSession, CommandContext args)
      throws WorldEditException {
    LocalConfiguration config = worldEdit.getConfiguration();

    double radius = args.argsLength() > 0 ? args.getDouble(0) : 5;
    double maxRadius = config.maxBrushRadius;
    // hmmmm not horribly worried about this because -1 is still rather efficient,
    // the problem arises when butcherMaxRadius is some really high number but not infinite
    // - original idea taken from https://github.com/sk89q/worldedit/pull/198#issuecomment-6463108
    if (player.hasPermission("worldedit.butcher")) {
      maxRadius = Math.max(config.maxBrushRadius, config.butcherMaxRadius);
    }
    if (radius > maxRadius) {
      player.printError("Maximum allowed brush radius: " + maxRadius);
      return;
    }

    CreatureButcher flags = new CreatureButcher(player);
    flags.fromCommand(args);

    BrushTool tool = session.getBrushTool(player.getItemInHand());
    tool.setSize(radius);
    tool.setBrush(new ButcherBrush(flags), "worldedit.brush.butcher");

    player.print(String.format("Butcher brush equipped (%.0f).", radius));
  }