Example #1
0
 public void createMap(String id, Player p) throws EmptyClipboardException {
   Selection sel = WorldEditUtilities.getWorldEdit().getSelection(p);
   if (sel != null) {
     MapConfiguration.getMaps().reloadMap(id);
     Location b1 =
         new Location(
             p.getWorld(),
             sel.getNativeMinimumPoint().getBlockX(),
             sel.getNativeMinimumPoint().getBlockY(),
             sel.getNativeMinimumPoint().getBlockZ());
     Location b2 =
         new Location(
             p.getWorld(),
             sel.getNativeMaximumPoint().getBlockX(),
             sel.getNativeMaximumPoint().getBlockY(),
             sel.getNativeMaximumPoint().getBlockZ());
     MapConfiguration.getMaps().getMap(id).set("region.p1.w", b1.getWorld().getName());
     MapConfiguration.getMaps().getMap(id).set("region.p1.x", b1.getBlockX());
     MapConfiguration.getMaps().getMap(id).set("region.p1.y", b1.getBlockY());
     MapConfiguration.getMaps().getMap(id).set("region.p1.z", b1.getBlockZ());
     MapConfiguration.getMaps().getMap(id).set("region.p2.w", b2.getWorld().getName());
     MapConfiguration.getMaps().getMap(id).set("region.p2.x", b2.getBlockX());
     MapConfiguration.getMaps().getMap(id).set("region.p2.y", b2.getBlockY());
     MapConfiguration.getMaps().getMap(id).set("region.p2.z", b2.getBlockZ());
     MapConfiguration.getMaps().saveMap(id);
     List<String> enabled =
         DataConfiguration.getData().getDataFile().getStringList("enabled-maps");
     enabled.add(id);
     DataConfiguration.getData().getDataFile().set("enabled-maps", enabled);
     DataConfiguration.getData().saveData();
   } else {
     throw new EmptyClipboardException();
   }
 }
Example #2
0
  public void regionPrice(Player player, String[] args) {
    Selection sel = worldEdit.getSelection(player);

    if (sel == null) {
      player.sendMessage(ChatColor.RED + "Select a region with a wooden axe first.");
      return;
    }

    ProtectedRegion region = null;
    String id = "icp__tempregion";

    if (sel instanceof Polygonal2DSelection) {
      Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
      int minY = polySel.getNativeMinimumPoint().getBlockY();
      int maxY = polySel.getNativeMaximumPoint().getBlockY();
      region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY);
    } else if (sel instanceof CuboidSelection) {
      BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
      BlockVector max = sel.getNativeMaximumPoint().toBlockVector();
      region = new ProtectedCuboidRegion(id, min, max);
    } else {
      player.sendMessage(
          ChatColor.RED
              + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!");
      return;
    }

    double cost = (int) Math.ceil(econ.getCost(region.volume()));

    player.sendMessage(ChatColor.AQUA + "That region will cost you $" + cost + ".");
  }
  public void createArenaFromSelection(Player pl, String name) {
    FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
    // SettingsManager s = SettingsManager.getInstance();

    WorldEditPlugin we = p.getWorldEdit();
    Selection sel = we.getSelection(pl);
    if (sel == null) {
      Message.send(pl, ChatColor.RED + "You must make a WorldEdit Selection first!");
      return;
    }
    Location max = sel.getMaximumPoint();
    Location min = sel.getMinimumPoint();

    /* if(max.getWorld()!=SettingsManager.getGameWorld() || min.getWorld()!=SettingsManager.getGameWorld()){
    	Message.send(pl, ChatColor.RED+"Wrong World!");
    	return;
    }*/
    SettingsManager.getInstance().getSpawns().set(("spawns." + name), null);
    c.set("system.arenas." + name + ".world", max.getWorld().getName());
    c.set("system.arenas." + name + ".x1", max.getBlockX());
    c.set("system.arenas." + name + ".y1", max.getBlockY());
    c.set("system.arenas." + name + ".z1", max.getBlockZ());
    c.set("system.arenas." + name + ".x2", min.getBlockX());
    c.set("system.arenas." + name + ".y2", min.getBlockY());
    c.set("system.arenas." + name + ".z2", min.getBlockZ());
    c.set("system.arenas." + name + ".enabled", false);
    c.set("system.arenas." + name + ".min", 3);
    c.set("system.arenas." + name + ".max", 4);
    SettingsManager.getInstance().saveSystemConfig();
    hotAddArena(name);
    Message.send(pl, ChatColor.GREEN + "Arena " + name.toUpperCase() + " succesfully added");
  }
  private static boolean addWorldGuardRegion(
      CommandSender sender, Arena arena, BattleArenaController ac, String value) {
    if (!checkWorldGuard(sender)) {
      return false;
    }
    Player p = (Player) sender;
    WorldEditPlugin wep = WorldEditUtil.getWorldEditPlugin();
    Selection sel = wep.getSelection(p);
    if (sel == null) {
      sendMessage(sender, "&cYou need to select a region to use this command.");
      return false;
    }

    String region = arena.getRegion();
    World w = sel.getWorld();
    try {
      String id = makeRegionName(arena);
      if (region != null) {
        WorldGuardInterface.updateProtectedRegion(p, id);
        sendMessage(sender, "&2Region updated! ");
      } else {
        WorldGuardInterface.createProtectedRegion(p, id);
        sendMessage(sender, "&2Region added! ");
      }
      arena.addRegion(w.getName(), id);
      WorldGuardInterface.saveSchematic(p, id);
    } catch (Exception e) {
      sendMessage(sender, "&cAdding WorldGuard region failed!");
      sendMessage(sender, "&c" + e.getMessage());
      e.printStackTrace();
    }
    return true;
  }
Example #5
0
  /**
   * Returns the selection of the players.
   *
   * @param player the players
   * @return the selection of the passed players.
   */
  public Area getSelectedArea(Player player) {
    if (worldEditPlugin != null) {
      Selection weSelection = worldEditPlugin.getSelection(player);

      if (weSelection != null && weSelection.getArea() > 0) {
        return new CuboidArea(weSelection.getMinimumPoint(), weSelection.getMaximumPoint());
      } else {
        return null;
      }
    } else {
      return null; // ToDo: Implement own selection tool!
    }
  }
  public void createArenaFromSelection(Player pl) {
    FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
    // SettingsManager s = SettingsManager.getInstance();

    WorldEditPlugin we = getWorldEdit();
    Selection sel = we.getSelection(pl);
    if (sel == null) {
      msgmgr.sendMessage(PrefixType.WARNING, "You must make a WorldEdit Selection first!", pl);
      return;
    }
    Location max = sel.getMaximumPoint();
    Location min = sel.getMinimumPoint();

    /* if(max.getWorld()!=SettingsManager.getGameWorld() || min.getWorld()!=SettingsManager.getGameWorld()){
        pl.sendMessage(ChatColor.RED+"Wrong World!");
        return;
    }*/

    /*
     *
     *
     *
     *     RE-IMPLEMENT THIS PART
     *     LEAVING AS A REFRENCE
     *
     *
     */

    int no = c.getInt("sg-system.arenano") + 1;
    c.set("sg-system.arenano", no);
    if (games.size() == 0) {
      no = 1;
    } else no = games.get(games.size() - 1).getID() + 1;
    SettingsManager.getInstance().getSpawns().set(("spawns." + no), null);
    c.set("sg-system.arenas." + no + ".world", max.getWorld().getName());
    c.set("sg-system.arenas." + no + ".x1", max.getBlockX());
    c.set("sg-system.arenas." + no + ".y1", max.getBlockY());
    c.set("sg-system.arenas." + no + ".z1", max.getBlockZ());
    c.set("sg-system.arenas." + no + ".x2", min.getBlockX());
    c.set("sg-system.arenas." + no + ".y2", min.getBlockY());
    c.set("sg-system.arenas." + no + ".z2", min.getBlockZ());
    c.set("sg-system.arenas." + no + ".enabled", true);

    SettingsManager.getInstance().saveSystemConfig();
    hotAddArena(no);
    pl.sendMessage(ChatColor.GREEN + "Arena ID " + no + " Succesfully added");
  }
 private static ProtectedRegion checkRegionFromSelection(Player player, String id)
     throws CommandException {
   Selection selection = checkSelection(player);
   if (selection instanceof Polygonal2DSelection) {
     Polygonal2DSelection polySel = (Polygonal2DSelection) selection;
     int minY = polySel.getNativeMinimumPoint().getBlockY();
     int maxY = polySel.getNativeMaximumPoint().getBlockY();
     return new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY);
   } else if (selection instanceof CuboidSelection) {
     BlockVector min = selection.getNativeMinimumPoint().toBlockVector();
     BlockVector max = selection.getNativeMaximumPoint().toBlockVector();
     return new ProtectedCuboidRegion(id, min, max);
   } else {
     throw new CommandException(
         "Sorry, you can only use cuboids and polygons for WorldGuard regions.");
   }
 }
 public void setLobbySignsFromSelection(Player pl, int a) {
   FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
   SettingsManager s = SettingsManager.getInstance();
   if (!c.getBoolean("walls-system.lobby.sign.set", false)) {
     c.set("walls-system.lobby.sign.set", true);
     s.saveSystemConfig();
   }
   WorldEditPlugin we = GameManager.getInstance().getWorldEdit();
   Selection sel = we.getSelection(pl);
   if (sel == null) {
     pl.sendMessage(ChatColor.RED + "You must make a WorldEdit Selection first");
     return;
   }
   if ((sel.getNativeMaximumPoint().getBlockX() - sel.getNativeMinimumPoint().getBlockX()) != 0
       && (sel.getNativeMinimumPoint().getBlockZ() - sel.getNativeMaximumPoint().getBlockZ()
           != 0)) {
     pl.sendMessage(ChatColor.RED + " Must be in a straight line!");
     return;
   }
   Vector max = sel.getNativeMaximumPoint();
   Vector min = sel.getNativeMinimumPoint();
   int i = c.getInt("walls-system.lobby.signno", 0) + 1;
   c.set("walls-system.lobby.signno", i);
   c.set("walls-system.lobby.signs." + i + ".id", a);
   c.set("walls-system.lobby.signs." + i + ".world", pl.getWorld().getName());
   c.set("walls-system.lobby.signs." + i + ".x1", max.getBlockX());
   c.set("walls-system.lobby.signs." + i + ".y1", max.getBlockY());
   c.set("walls-system.lobby.signs." + i + ".z1", max.getBlockZ());
   c.set("walls-system.lobby.signs." + i + ".x2", min.getBlockX());
   c.set("walls-system.lobby.signs." + i + ".y2", min.getBlockY());
   c.set("walls-system.lobby.signs." + i + ".z2", min.getBlockZ());
   pl.sendMessage(ChatColor.GREEN + "Added Lobby Wall"); // TODO
   s.saveSystemConfig();
   loadSign(i);
 }
Example #9
0
 @Override
 protected void execute() {
   Mine m = Mines.i.mm.getMine(args[1]);
   if (m == null) {
     sender.sendMessage(MessageUtil.get("mines.notFound"));
     return;
   }
   Selection s = Mines.i.getWE().getSelection(Prison.i().playerList.getPlayer(sender.getName()));
   if (s == null) {
     sender.sendMessage(MessageUtil.get("mines.makeWESel"));
     return;
   }
   m.minX = s.getMinimumPoint().getBlockX();
   m.minY = s.getMinimumPoint().getBlockY();
   m.minZ = s.getMinimumPoint().getBlockZ();
   m.maxX = s.getMaximumPoint().getBlockX();
   m.maxY = s.getMaximumPoint().getBlockY();
   m.maxZ = s.getMaximumPoint().getBlockZ();
   m.save();
   Mines.i.mm.mines.remove(args[1]);
   Mines.i.mm.addMine(m);
   sender.sendMessage(MessageUtil.get("mines.redefineSuccess", m.name));
 }
Example #10
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));
  }
Example #11
0
  public SearchParser(CommandSender player, List<String> args) throws IllegalArgumentException {
    this.player = player;

    String lastParam = "";
    boolean paramSet = false;
    boolean worldedit = false;

    for (int i = 0; i < args.size(); i++) {
      String arg = args.get(i);
      if (arg.isEmpty()) continue;

      if (!paramSet) {
        if (arg.length() < 2)
          throw new IllegalArgumentException("Invalid argument format: &7" + arg);
        if (!arg.substring(1, 2).equals(":")) {
          if (arg.contains(":"))
            throw new IllegalArgumentException("Invalid argument format: &7" + arg);

          // No arg specified, treat as player
          players.add(arg);
          continue;
        }

        lastParam = arg.substring(0, 1).toLowerCase();
        paramSet = true;

        if (arg.length() == 2) {
          if (i == (args.size() - 1)) // No values specified
          throw new IllegalArgumentException("Invalid argument format: &7" + arg);
          else // User put a space between the colon and value
          continue;
        }

        // Get values out of argument
        arg = arg.substring(2);
      }

      if (paramSet) {
        if (arg.isEmpty()) {
          throw new IllegalArgumentException("Invalid argument format: &7" + lastParam + ":");
        }

        String[] values = arg.split(",");

        // Players
        if (lastParam.equals("p")) for (String p : values) players.add(p);
        // Worlds
        else if (lastParam.equals("w")) worlds = values;
        // Filters
        else if (lastParam.equals("f")) {
          if (filters != null) filters = Util.concat(filters, values);
          else filters = values;
        }
        // Blocks
        else if (lastParam.equals("b")) {
          for (int j = 0; j < values.length; j++) {
            if (Material.getMaterial(values[j]) != null)
              values[j] = Integer.toString(Material.getMaterial(values[j]).getId());
          }
        }
        // Actions
        else if (lastParam.equals("a")) {
          for (String value : values) {
            DataType type = DataType.fromName(value);
            if (type == null)
              throw new IllegalArgumentException("Invalid action supplied: &7" + value);
            if (!Util.hasPerm(player, "search." + type.getConfigName().toLowerCase()))
              throw new IllegalArgumentException(
                  "You do not have permission to search for: &7" + type.getConfigName());
            actions.add(type);
          }
        }
        // Location
        else if (lastParam.equals("l") && player instanceof Player) {
          if (values[0].equalsIgnoreCase("here")) loc = ((Player) player).getLocation().toVector();
          else {
            loc = new Vector();
            loc.setX(Integer.parseInt(values[0]));
            loc.setY(Integer.parseInt(values[1]));
            loc.setZ(Integer.parseInt(values[2]));
          }
        }
        // Radius
        else if (lastParam.equals("r") && player instanceof Player) {
          if (!Util.isInteger(values[0])) {
            if ((values[0].equalsIgnoreCase("we") || values[0].equalsIgnoreCase("worldedit"))
                && HawkEye.worldEdit != null) {
              Selection sel = HawkEye.worldEdit.getSelection((Player) player);
              double lRadius = Math.ceil(sel.getLength() / 2);
              double wRadius = Math.ceil(sel.getWidth() / 2);
              double hRadius = Math.ceil(sel.getHeight() / 2);

              if (Config.MaxRadius != 0
                  && (lRadius > Config.MaxRadius
                      || wRadius > Config.MaxRadius
                      || hRadius > Config.MaxRadius))
                throw new IllegalArgumentException(
                    "Selection too large, max radius: &7" + Config.MaxRadius);

              worldedit = true;
              minLoc =
                  new Vector(
                      sel.getMinimumPoint().getX(),
                      sel.getMinimumPoint().getY(),
                      sel.getMinimumPoint().getZ());
              maxLoc =
                  new Vector(
                      sel.getMaximumPoint().getX(),
                      sel.getMaximumPoint().getY(),
                      sel.getMaximumPoint().getZ());
            } else {
              throw new IllegalArgumentException("Invalid radius supplied: &7" + values[0]);
            }
          } else {
            radius = Integer.parseInt(values[0]);
            if (Config.MaxRadius != 0 && radius > Config.MaxRadius)
              throw new IllegalArgumentException(
                  "Radius too large, max allowed: &7" + Config.MaxRadius);
          }
        }
        // Time
        else if (lastParam.equals("t")) {

          int type = 2;
          boolean isTo = false;
          for (int j = 0; j < arg.length(); j++) {
            String c = arg.substring(j, j + 1);
            if (!Util.isInteger(c)) {
              if (c.equals("m")
                  || c.equals("s")
                  || c.equals("h")
                  || c.equals("d")
                  || c.equals("w")) {
                type = 0;
              }
              if (c.equals("-") || c.equals(":")) type = 1;
            }
          }

          // If the time is in the format '0w0d0h0m0s'
          if (type == 0) {

            int weeks = 0;
            int days = 0;
            int hours = 0;
            int mins = 0;
            int secs = 0;

            String nums = "";
            for (int j = 0; j < values[0].length(); j++) {
              String c = values[0].substring(j, j + 1);
              if (c.equals("!")) { // If the number has a ! infront of it the time inverts
                c = values[0].substring(j, j + 2).replace("!", "");
                isTo = true;
              } else {
                if (Util.isInteger(c)) {
                  nums += c;
                  continue;
                }

                int num = Integer.parseInt(nums);
                if (c.equals("w")) weeks = num;
                else if (c.equals("d")) days = num;
                else if (c.equals("h")) hours = num;
                else if (c.equals("m")) mins = num;
                else if (c.equals("s")) secs = num;
                else throw new IllegalArgumentException("Invalid time measurement: &7" + c);
                nums = "";
              }
            }

            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.WEEK_OF_YEAR, -1 * weeks);
            cal.add(Calendar.DAY_OF_MONTH, -1 * days);
            cal.add(Calendar.HOUR, -1 * hours);
            cal.add(Calendar.MINUTE, -1 * mins);
            cal.add(Calendar.SECOND, -1 * secs);
            SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (isTo) dateTo = form.format(cal.getTime());
            else dateFrom = form.format(cal.getTime());
          }

          // If the time is in the format 'yyyy-MM-dd HH:mm:ss'
          else if (type == 1) {
            if (values.length == 1) {
              SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd");
              dateFrom = form.format(Calendar.getInstance().getTime()) + " " + values[0];
            }
            if (values.length >= 2) dateFrom = values[0] + " " + values[1];
            if (values.length == 4) dateTo = values[2] + " " + values[3];
          }
          // Invalid time format
          else if (type == 2) throw new IllegalArgumentException("Invalid time format!");

        } else throw new IllegalArgumentException("Invalid parameter supplied: &7" + lastParam);

        paramSet = false;
      }
    }

    // Sort out locations
    if (!worldedit) parseLocations();
  }
Example #12
0
 /**
  * Creates a new region from WorldEdit selection.
  *
  * @param selection worldedit selection
  */
 public Region(final Selection selection) {
   this.v1 = new SerializableVector(selection.getMinimumPoint().toVector());
   this.v2 = new SerializableVector(selection.getMaximumPoint().toVector());
   this.w = selection.getWorld();
   this.w_name = this.w.getName();
 }
Example #13
0
  public void setRegion(Player sender, String[] args) {
    if (args.length != 2) {
      sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    LocalPlayer wgPlayer = plugin.wrapPlayer(sender);

    String id = "icp_" + sender.getName() + "_" + args[1];

    if (!ProtectedRegion.isValidId(id)) {
      sender.sendMessage(ChatColor.RED + "Invalid region name specified!");
      return;
    }

    Selection sel = worldEdit.getSelection(sender);

    if (sel == null) {
      sender.sendMessage(ChatColor.RED + "Select a region with a wooden axe first.");
      return;
    }

    RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());

    if (mgr.hasRegion(id)) {
      sender.sendMessage(
          ChatColor.RED + "That region name is already taken. Please choose a new name.");
      return;
    }

    int regionCount = mgr.getRegionCountOfPlayer(wgPlayer);

    if (regionCount > Economy.maxDonatorAllowedRegions
        && !sender.isOp()
        && sender.hasPermission("iceprotect.freeprotect")) {
      sender.sendMessage(
          ChatColor.RED
              + "You have reached the maximum allowed regions per user ("
              + Economy.maxDonatorAllowedRegions
              + ").");
      sender.sendMessage(ChatColor.RED + "Please contact an admin.");
      return;
    }

    ProtectedRegion region = null;

    if (sel instanceof Polygonal2DSelection) {
      Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
      int minY = polySel.getNativeMinimumPoint().getBlockY();
      int maxY = polySel.getNativeMaximumPoint().getBlockY();
      region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY);
    } else if (sel instanceof CuboidSelection) {
      BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
      BlockVector max = sel.getNativeMaximumPoint().toBlockVector();
      region = new ProtectedCuboidRegion(id, min, max);
    } else {
      sender.sendMessage(
          ChatColor.RED
              + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!");
      return;
    }

    String[] names = new String[1];
    names[0] = sender.getName();
    region.setOwners(RegionUtil.parseDomainString(names, 0));

    ApplicableRegionSet regions = mgr.getApplicableRegions(region);

    if (!regions.isOwnerOfAll(wgPlayer)) {
      sender.sendMessage(ChatColor.RED + "That region overlaps with another one not owned by you!");
      return;
    }

    double cost = (int) Math.ceil(econ.getCost(region.volume()));

    if (cost > Economy.maxDonatorAllowedCost && sender.hasPermission("iceprotect.freeprotect")) {
      sender.sendMessage(
          ChatColor.RED + "You have exceeded the maximum allowed price for this region!");
      sender.sendMessage(
          ChatColor.RED
              + "Cost: "
              + ChatColor.GRAY
              + "$"
              + cost
              + ChatColor.RED
              + ", "
              + ChatColor.GRAY
              + "$"
              + Economy.maxDonatorAllowedCost
              + " allowed.");
      return;
    }

    if (!sender.hasPermission("iceprotect.freeprotect") && !econ.chargePlayer(sender, cost)) {
      sender.sendMessage(ChatColor.RED + "You don't have enough money! $" + cost + " needed.");
      return;
    }

    mgr.addRegion(region);

    try {
      mgr.save();
      sender.sendMessage(
          ChatColor.YELLOW
              + "Region saved as "
              + args[1]
              + ". "
              + (sender.hasPermission("iceprotect.freeprotect") ? "" : "Cost: $" + cost + "."));
    } catch (IOException e) {
      sender.sendMessage(
          ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage());
      e.printStackTrace();
      return;
    }
  }
  @Command(
      aliases = {"save"},
      desc = "Saves the selected area",
      usage = "[-n namespace ] <id>",
      flags = "n:",
      min = 1)
  public void saveArea(CommandContext context, CommandSender sender) throws CommandException {

    if (!(sender instanceof Player)) return;
    LocalPlayer player = plugin.wrapPlayer((Player) sender);

    String id;
    String namespace = player.getName();
    boolean personal = true;

    if (context.hasFlag('n')
        && player.hasPermission("craftbook.mech.area.save." + context.getFlag('n'))) {
      namespace = context.getFlag('n');
      personal = false;
    } else if (!player.hasPermission("craftbook.mech.area.save.self"))
      throw new CommandPermissionsException();

    if (plugin.getConfiguration().areaShortenNames && namespace.length() > 14)
      namespace = namespace.substring(0, 14);

    if (!CopyManager.isValidNamespace(namespace))
      throw new CommandException("Invalid namespace. Needs to be between 1 and 14 letters long.");

    if (personal) {
      namespace = "~" + namespace;
    }

    id = context.getString(0);

    if (!CopyManager.isValidName(id))
      throw new CommandException("Invalid area name. Needs to be between 1 and 13 letters long.");

    try {
      WorldEditPlugin worldEdit = CraftBookPlugin.plugins.getWorldEdit();

      World world = ((Player) sender).getWorld();
      Selection sel = worldEdit.getSelection((Player) sender);
      if (sel == null) {
        sender.sendMessage(ChatColor.RED + "You have not made a selection!");
        return;
      }
      Vector min = BukkitUtil.toVector(sel.getMinimumPoint());
      Vector max = BukkitUtil.toVector(sel.getMaximumPoint());
      Vector size = max.subtract(min).add(1, 1, 1);

      // Check maximum size
      if (config.areaMaxAreaSize != -1
          && size.getBlockX() * size.getBlockY() * size.getBlockZ() > config.areaMaxAreaSize) {
        throw new CommandException(
            "Area is larger than allowed " + config.areaMaxAreaSize + " blocks.");
      }

      // Check to make sure that a user doesn't have too many toggle
      // areas (to prevent flooding the server with files)
      if (config.areaMaxAreaPerUser >= 0 && !namespace.equals("global")) {
        int count = copyManager.meetsQuota(world, namespace, id, config.areaMaxAreaPerUser);

        if (count > -1) {
          throw new CommandException(
              "You are limited to "
                  + config.areaMaxAreaPerUser
                  + " toggle area(s). "
                  + "You have "
                  + count
                  + " areas.");
        }
      }

      // Copy
      CuboidCopy copy;

      if (config.areaUseSchematics) {
        copy = new MCEditCuboidCopy(min, size, world);
      } else {
        copy = new FlatCuboidCopy(min, size, world);
      }

      copy.copy();

      plugin
          .getServer()
          .getLogger()
          .info(
              player.getName()
                  + " saving toggle area with folder '"
                  + namespace
                  + "' and ID '"
                  + id
                  + "'.");

      // Save
      try {
        CopyManager.getInstance().save(world, namespace, id.toLowerCase(Locale.ENGLISH), copy);
        player.print("Area saved as '" + id + "' under the '" + namespace + "' namespace.");
      } catch (IOException e) {
        player.printError("Could not save area: " + e.getMessage());
      } catch (DataException e) {
        player.print(e.getMessage());
      }
    } catch (NoClassDefFoundError e) {
      throw new CommandException(
          "WorldEdit.jar does not exist in plugins/, or is outdated. (Or you are using an outdated version of CraftBook)");
    }
  }