BANGOR, Maine — The man who fired 70 shots into the walls and out a second-floor apartment window on the Fourth of July in 2013 was sentenced Tuesday in U.S. District Court to five years in prison for being a felon in possession of a firearm.

Perrin Q. Oliver, 45, who is a native of Detroit, Michigan, pleaded guilty in December to the federal charge of being a felon in possession of a firearm and ammunition and was sentenced by U.S. District Judge George Singal at the Margaret Chase Smith Federal Building.

Oliver has a lengthy criminal history, which includes a drug-dealing conviction. He was prohibited from having guns because of a 2008 conviction in Brooklyn, New York, for criminal possession of a weapon, Assistant U.S. Attorney Andrew McCormack, who is prosecuting the case, told the court.

Oliver was found with a Rossi .38-caliber revolver tucked into the waistband of his pants, and a Sig Sauer .380-caliber semiautomatic pistol that was found in a safe with individually wrapped bags of crack cocaine in the apartment where he lived.

“It appears to me to be quite clear that the defendant was continuing to deal drugs,” Singal said before issuing his sentence.

Bangor police received a call at 8:30 a.m. July 4, 2013, reporting a man firing shots out of an apartment window at 47 Park St. The area was cordoned off by police, causing the Fourth of July parade to be rerouted down Water Street. After negotiating for four hours, police used tear gas to get Oliver out of the building and end the standoff.

Oliver has been held in jail, most recently the Somerset County Jail, since his arrest because he has been unable to post $100,000 cash bail. He originally was charged in state court at the Penobscot Judicial Center with felony reckless conduct with a firearm, criminal threatening with a dangerous weapon and possession of a firearm by a prohibited person, but the state dropped those charges last October after he was charged Sept. 20, 2013 in federal court.

Jeffrey Silverstein, Oliver’s defense attorney, fought for a lesser sentence.

“What troubles me with the situation is it was prosecuted as a firearms case for 15 months … until very recently, when it came to sentencing, it’s for a drug case,” Silverstein said, referring to how the judge applied sentencing guidelines. “This cuts both ways.”

Silverstein also said, without getting into specifics about what mental health problems Oliver may face, that his client was not taking his prescribed medications.

“He has accepted his responsibility for his conduct throughout this process,” Silverstein said. “His perspective has been one that he has to repay society [and] he’s ready to get it over with and put this behind him.”

Silverstein also requested that Oliver be assigned to a prison in New York, so he can be closer to a brother who lives in Harlem.

Singal put the New York prison request in Oliver’s sentence, and said he was imposing a lengthy sentence in an attempt to put a stop to his criminal behaviors.

“This defendant has a long criminal history. It’s apparent with or without his issue of mental illness, that he has not been deterred in the slightest by the New York justice system,” the federal judge said. “It starts when he was 16 and goes on and on and on.

“Each time the New York justice system has slapped him on the wrist and given him a break [it was followed by] an ongoing onslaught of criminal activity,” Singal said.

The federal judge also sentenced Oliver to three years of supervised release when he leaves prison and ordered him to undergo 500 hours of alcohol and drug treatment, not to possess firearms, ammunition or other weapons and to take his medications to control his mental health problems.

The last thing to occur during Tuesday’s court appearance was Oliver’s forfeiture of the two weapons police took as evidence.