diff --git a/package.json b/package.json index 8a0f994..6c88d5b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Index.ts b/src/Index.ts index f68bef7..8dbdfaa 100644 --- a/src/Index.ts +++ b/src/Index.ts @@ -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'; \ No newline at end of file diff --git a/src/Managers/DamonJsPlayer.ts b/src/Managers/DamonJsPlayer.ts index 6a7a834..c7f4050 100644 --- a/src/Managers/DamonJsPlayer.ts +++ b/src/Managers/DamonJsPlayer.ts @@ -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); @@ -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; } @@ -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; diff --git a/src/Managers/Supports/DamonJsQueue.ts b/src/Managers/Supports/DamonJsQueue.ts index ec440b6..21bb1b7 100644 --- a/src/Managers/Supports/DamonJsQueue.ts +++ b/src/Managers/Supports/DamonJsQueue.ts @@ -37,11 +37,18 @@ export class DamonJsQueue extends Array { * 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