Matt Barnes is getting court-ordered protection from his fiancee's ex husband ... after the former NBA champ said the guy had terrorized him in the leadup to a wild spitting incident at the 49ers game on Sunday.
Barnes got a judge to sign off on a temporary restraining order against David Patterson Jr. on Wednesday ... just days after he spat on the man in a concourse at Levi's Stadium before the S.F. vs Dallas playoff game.
Barnes' TRO is slated to last until Feb.