@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.getCraftBookId();
boolean personal = true;
if (context.hasFlag('n')) {
if (!player.hasPermission("craftbook.mech.area.save." + context.getFlag('n')))
throw new CommandException("You do not have permission to use this namespace.");
namespace = context.getFlag('n');
personal = false;
} else if (!player.hasPermission("craftbook.mech.area.save.self"))
throw new CommandPermissionsException();
if (Area.instance.shortenNames && 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 (Area.instance.maxAreaSize != -1 && size.getBlockX() * size.getBlockY() * size.getBlockZ()
> Area.instance.maxAreaSize) {
throw new CommandException("Area is larger than allowed " + Area.instance.maxAreaSize + " blocks.");
}
// Check to make sure that a user doesn't have too many toggle
// areas (to prevent flooding the server with files)
if (Area.instance.maxAreasPerUser >= 0 && !namespace.equals("global") && !player.hasPermission("craftbook.mech.area.bypass-limit")) {
int count = copyManager.meetsQuota(world, namespace, id,
Area.instance.maxAreasPerUser);
if (count > -1) {
throw new CommandException("You are limited to " + Area.instance.maxAreasPerUser + " toggle area(s). "
+ "You have " + count + " areas.");
}
}
// Copy
CuboidCopy copy;
if (Area.instance.useSchematics) {
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)");
}
}