Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
achiragaming committed Dec 25, 2023
1 parent 4bdbe6a commit 0bdb2e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "damonjs",
"version": "1.3.8",
"version": "1.3.9",
"preview": false,
"description": "A modified Shoukaku wrapper with enhanced queue support.",
"main": "dist/Index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export * from './DamonJs';
export { DamonJsTrack, DamonJsQueue, DamonJsPlayer, Plugins };
export * from './Modules/Interfaces';

export const version = '1.3.8';
export const version = '1.3.9';

11 changes: 6 additions & 5 deletions src/Managers/DamonJsPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ export class DamonJsPlayer {
this.player.on('end', (data) => {
if (this.state === PlayerState.DESTROYING || this.state === PlayerState.DESTROYED)
return this.emit(Events.Debug, this, `Player ${this.guildId} destroyed from end event`);
if (!this.queue.current) return this.emit(Events.Debug, this, `No Previous Track to Play ${this.guildId}`);
this.isTrackPlaying = false;

this.emit(Events.PlayerEnd, this, this.queue.current);
this.isTrackPlaying = false;
const lastTrack = this.queue[this.queue.lastId]
lastTrack && this.emit(Events.PlayerEnd, this, lastTrack);

if (data.reason === 'replaced') return this.emit(Events.PlayerEmpty, this);

Expand Down Expand Up @@ -314,6 +314,7 @@ export class DamonJsPlayer {
else playOptions.options = { noReplace: false };
await this.player.playTrack(playOptions);
}
this.queue.setCurrentId(this.queue.currentId)
this.player.paused = false;
return this;
}
Expand Down Expand Up @@ -355,10 +356,10 @@ export class DamonJsPlayer {
if (this.state === PlayerState.DESTROYED) throw new DamonJsError(1, 'Player is already destroyed');
if (!this.queue[trackId]) throw new DamonJsError(2, `${trackId} is an invalid track ID.`);
if (!this.playable) {
if (this.loop !== LoopState.Track) this.queue.currentId = trackId;
if (this.loop !== LoopState.Track) this.queue.setCurrentId(trackId)
await this.play();
} else {
if (this.loop !== LoopState.Track) this.queue.currentId = trackId - 1;
if (this.loop !== LoopState.Track) this.queue.setCurrentId(trackId - 1);
await this.player.stopTrack();
}
return this;
Expand Down
9 changes: 8 additions & 1 deletion src/Managers/Supports/DamonJsQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ export class DamonJsQueue extends Array<DamonJsTrack> {
* Do not do anything to this if you do anything to this player is likely gonna fail
*/
public currentId: number = 0;

/**
* last played track id
*/
public lastId: number = 0
/** Current playing track */
public get current(): DamonJsTrack | undefined {
return this.at(this.currentId);
}
public setCurrentId(trackId: number) {
this.lastId = this.currentId
this.currentId = trackId
}
/**
* Add track(s) to the queue
* @param track DamonJsTrack to add
Expand Down

0 comments on commit 0bdb2e3

Please sign in to comment.