The man accused of shooting an Atlanta police officer from the roof of a Little Five Points pub pleaded guilty to multiple charges Tuesday and will serve 30 years in prison, prosecutors said.

Cameron Christian Maddox agreed to a deal that will allow him to serve 30 years of a 50-year prison sentence for one count of attempted murder and four counts of aggravated assault, prosecutors said..

Prosecutors say Maddox, 21, shot Atlanta police Officer Dexter Toomer on the night of March 22, 2012, as Toomer left the Zesto restaurant on Moreland Avenue, where he'd gone to buy a drink before his shift ended. Maddox also shot at four others, authorities said.

Then 19, Maddox was arrested the next night and charged with attempted murder and multiple counts of aggravated assault of a police officer, aggravated battery, theft by taking and gun charges.

Toomer, who had worked with the Atlanta Police Department for more than two years after 18 years with the Atlanta jail, was shot in the leg and quickly recovered and returned to work.

Police said Maddox was perched atop the roof of the Brewhouse Café, across from Zesto, when he allegedly fired on Toomer.

Maddox had been ruled incompetent to stand trial last year after a DeKalb County Superior Court judge reviewed his mental evaluation.

It is unclear what circumstances led to that ruling being changed to allow Maddox to make a plea.