That’s one way to get into a gentrifying neighborhood.

A Niagara Falls, New York man has been convicted of grand larceny, forgery and related charges for stealing a building in Bedford-Stuyvesant, Brooklyn, prosecutors said.  

Joseph McCray, 54, is accused of forging a judge’s signature on a judicial order and using it to claim possession of the house, which he sold for a $500,0000 profit.

McCray was convicted on Thursday of two counts of second-degree grand larceny and one count each of offering a false instrument for filing, second-degree criminal possession of a forged instrument and first-degree falsifying business records. He faces up to 22 years in prison and is set to be sentenced Oct. 19.

According to the Brooklyn district attorney’s office, McCray was able to get ahold of 119 MacDonough St. — a four-family building in the Historic District of Bedford-Stuyvesant — by filing with the City Register a fraudulent court order allegedly signed by a Brooklyn Civil Supreme Court justice in January 2015. He used that forged order four months later to enter into a contract to sell the building for $500,000, which he closed on in May of that year.

Evidence showed that 119 MacDonough St. was purchased by a woman in March 2000 from the New York City Department of Housing Preservation and Development, according to the DA’s office. McCray was a holdover tenant, but never paid rent, and was evicted in September 2002, but continued to live in the building.

Starting in 2001, the McCray started a series of legal actions in Civil Court, claiming ownership of the building. In 2003 and 2004 he also claimed to be the landlord and illegally collected rent , which led to a criminal conviction in 2006. In June, 2004, paperwork shows, he filed a fraudulent deed with the City Register, transferring ownership of the building to his name.

When the building went into foreclosure, naming McCray, along with the rightful owner and her daughter as the owners, he tried to legally assert his ownership, prosecutors said. Though two different judges barred him from taking further claims of ownership, he continued to do so.

“The forged court order McCray had filed in January 2015 nullified the 2006 deed of the rightful owner and her daughter and ended the foreclosure action, purportedly giving the defendant sole ownership of the building,” according to the DA’s office.

McCray was arrested in July 2015 following the sale of the property when he went to pick up an additional $16,000 escrow check at a lawyer’s office.