Magnetoelectric effect in the honeycomb-lattice antiferromagnet BaNi2(PO4)2