@Command(
      aliases = {"delete"},
      desc = "Lists the areas of the given namespace or lists all areas.",
      usage = "[-n namespace] [area]",
      flags = "an:")
  public void delete(CommandContext context, CommandSender sender) throws CommandException {

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

    String namespace = "~" + player.getName();
    String areaId = null;

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

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

    boolean deleteAll = false;
    if (context.argsLength() > 0 && !context.hasFlag('a')) {
      areaId = context.getString(0);
    } else if (context.hasFlag('a')
        && player.hasPermission("craftbook.mech.area.delete." + namespace + ".all")) {
      deleteAll = true;
    } else throw new CommandException("You need to define an area or -a to delete all areas.");

    // add the area suffix
    areaId = areaId + (config.areaUseSchematics ? ".schematic" : ".cbcopy");

    File areas = null;
    try {
      areas = new File(plugin.getDataFolder(), "areas/" + namespace);
    } catch (Exception ignored) {
    }

    if (areas == null || !areas.exists())
      throw new CommandException("The namespace " + namespace + " does not exist.");

    if (deleteAll) {
      if (deleteDir(areas)) {
        player.print("All areas in the namespace " + namespace + " have been deleted.");
      }
    } else {
      File file = new File(areas, areaId);
      if (file.delete()) {
        player.print(
            "The area '" + areaId + " in the namespace '" + namespace + "' has been deleted.");
      }
    }
  }