One of the most challenging problems in the optimal control theory consists of solving the nonsmooth optimal control problems where several discontinuities may be present in the control variable and derivative of the state variable. Recently some extended spectral collocation methods have been introduced for solving such problems, and a matrix of differentiation is usually used to discretize and to approximate the derivative of the state variable in the particular collocation points. In such methods, there is typically no condition for the continuity of the state variable at the switching points. In this article, we propose an efficient hp spectral collocation method for the general form of nonsmooth optimal control problems based on the operational integration matrix. The time interval of the problem is first partitioned into several variable subintervals, and the problem is then discretized by considering the Legendre-Gauss-Lobatto collocation points. Here, the switching points are unknown parameters, and having solved the final discretized problem, we achieve some approximations for the optimal solutions and the switching points. We solve some comparative numerical test problems to support of the performance of the suggested approach.