Skip to content

Commit

Permalink
Breaking Changes for playerStateUpdate event
Browse files Browse the repository at this point in the history
  • Loading branch information
SxMAbel committed Jul 26, 2023
1 parent 790917a commit 16c3091
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

**Magmastream** a lavalink wrapper for NodeJs. Magmastream only supports lavalink version 4.

## Documentation
## Useful Links

- [Documentation](https://docs.blackforthosting.com)
- [Example Bot](https://github.com/Blackfort-Hosting/Magmastream_Template_Bot)

## Contributing

Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magmastream",
"version": "2.1.0",
"version": "2.2.0",
"description": "A user-friendly Lavalink client designed for NodeJS.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -15,8 +15,8 @@
},
"devDependencies": {
"@favware/rollup-type-bundler": "^2.0.0",
"@types/lodash": "^4.14.195",
"@types/node": "^20.4.4",
"@types/lodash": "^4.14.196",
"@types/node": "^20.4.5",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
Expand Down Expand Up @@ -84,4 +84,4 @@
"homepage": "https://docs.blackforthosting.com",
"author": "Abel Purnwasy",
"license": "Apache-2.0"
}
}
5 changes: 4 additions & 1 deletion src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export interface Manager {
* https://github.com/Blackfort-Hosting/magmastream/issues/16
* @event Manager#playerStateUpdate
*/
on(event: "playerStateUpdate", listener: (player: Player) => void): this;
on(
event: "playerStateUpdate",
listener: (oldPlayer: Player, newPlayer: Player) => void
): this;

/**
* Emitted when a player is moved to a new voice channel.
Expand Down
16 changes: 12 additions & 4 deletions src/structures/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ export class Player {
if (typeof repeat !== "boolean")
throw new TypeError('Repeat can only be "true" or "false".');

const oldPlayer = { ...this };

if (repeat) {
this.trackRepeat = true;
this.queueRepeat = false;
Expand All @@ -311,7 +313,7 @@ export class Player {
this.dynamicRepeat = false;
}

this.manager.emit("playerStateUpdate", this);
this.manager.emit("playerStateUpdate", oldPlayer, this);
return this;
}

Expand All @@ -323,6 +325,8 @@ export class Player {
if (typeof repeat !== "boolean")
throw new TypeError('Repeat can only be "true" or "false".');

const oldPlayer = { ...this };

if (repeat) {
this.trackRepeat = false;
this.queueRepeat = true;
Expand All @@ -333,7 +337,7 @@ export class Player {
this.dynamicRepeat = false;
}

this.manager.emit("playerStateUpdate", this);
this.manager.emit("playerStateUpdate", oldPlayer, this);
return this;
}

Expand All @@ -351,6 +355,8 @@ export class Player {
throw new RangeError("The queue size must be greater than 1.");
}

const oldPlayer = { ...this };

if (repeat) {
this.trackRepeat = false;
this.queueRepeat = false;
Expand All @@ -371,7 +377,7 @@ export class Player {
this.dynamicRepeat = false;
}

this.manager.emit("playerStateUpdate", this);
this.manager.emit("playerStateUpdate", oldPlayer, this);
return this;
}

Expand Down Expand Up @@ -419,6 +425,8 @@ export class Player {

if (this.paused === pause || !this.queue.totalSize) return this;

const oldPlayer = { ...this };

this.playing = !pause;
this.paused = pause;

Expand All @@ -429,7 +437,7 @@ export class Player {
},
});

this.manager.emit("playerStateUpdate", this);
this.manager.emit("playerStateUpdate", oldPlayer, this);
return this;
}

Expand Down

0 comments on commit 16c3091

Please sign in to comment.