Coby Stanisclaus, 18, North Carr, Dalton, Huddersfield, appeared at Leeds Crown Court charged with four drug offences on Friday, January 28.
The court heard that police officers were called to Stanisclaus' house at 10.30pm on September 15, 2021.
The defendants mum had contacted police after a window was smashed.
Witnesses on the street told officers that a car had driven to the property and four men had gotten out and approached the house, before quickly driving away.
Stanisclaus ran out and tried to get in the car but the defendant continued to drive off, the court heard.
Jessica Strange, prosecuting, told the court that another man then appeared and what appeared to be a gun was fired at the house.
When officers searched the house to find evidence of a gunshot, they found weapons, drugs and mobile phones linked drug dealing.
The drugs found were heroin, MDMA, cocaine and cannabis.
Ms Strange said that police also found knives, two BB guns and an imitation firearm, as well as mobile phones and sim cards.
Messages on the phone were read out to the court and included texts such as "Live till late", "Two fat ones for £100" and other messages that the prosecution said showed he was selling heroin and cocaine for usage.
Stanisclaus returned to his house on September 16 and was arrested by police.
He pleaded guilty at his first appearance at Leeds Magistrates' Court.
Aubrey Sampson, defending, said Stanisclaus had been dealing drugs in order to pay off his own drug debts to dealers and that he has mental health difficulties including ADHD and he is on the autism spectrum.
Mr Sampson said: "This young man is only just 18.
"The defendant was a cannabis user who get into debt and owned £7000. He was told to repay the debut by selling drugs.
"He later told his suppliers that he was no longer going to sell the drugs.
"As a result of this refusal, people came to the house with machetes and smashed up the house and that's when his mum called the police.
"The defend has no previous convictions for drug offences.
"He entered a guilty plea at the earliest opportunity.
"He is a naïve young man."
A mental health report and a letter from a parent was read by Judge K. It was not read in open court.
Judge Mushtaq Khokhar sentenced Stanisclaus to three years in a young offenders institute for possession for possession with intent to supply heroin and possession with intent to supply cocaine.
He was sentence to one month for possession with intent to supply MDMA and possession with intent to supply a controlled class B drug.
The charges are to run concurrently.
The total sentence is three years in a young offenders institute.
Judge Khokar said: "It may be, and I am prepared to accept given your age, that you got into debt in relation to your cannabis use and in order to pay off that drug debt you agreed to sell drugs on behalf of others.
"To be fair to you, you frankly admitted that.
"You were selling Class A drugs. Notwithstanding your age, I am sure you understand that those who become addicted to Class A drugs then are unable to sustain that habit for long without resorting to commit crime. We see that in these courts all the time.
"I am prepared to accept that you did not want to do it anymore.
"There was an incident when young men arrived in a car to use seemingly what was a discharge of a firearm.
"What is clear is that you were trying to get into the car as they tried to leave.
"It has to be custody.
"I would like to think that the time you spend in custody means that you come out and do not make the same mistakes that you have in the past."
DI Simon Reddington of the Kirklees Programme Precision Team, said: “We welcome the sentencing of Coby Stanisclaus who has been an active participant in serious and organised crime in Dalton for some time now.
“His sentencing has been good news for communities there and the weight of evidence gathered against him meant had had little option other than to plead guilty.”
He added: “The Programme Precision Team has a number of active investigations ongoing targeting organised criminal gangs in Kirklees and we continue to appeal for residents who may have information about serious organised crime in their communities to come forwards.
“All information is assessed and help from the public can be vital in helping us bring Offenders to justice. Anyone who has information can report it to the police via 101 or anonymously to the independent Crimestoppers charity on 0800 555 111.”
Support the YEP and become a subscriber today. Enjoy unlimited access to local news and the latest on Leeds United. With a digital subscription, you see fewer ads, enjoy faster load times, and get access to exclusive newsletters and content. Click here to subscribe.