serenity
serenity copied to clipboard
Old listeners aren't unregistered when a plugin is loaded.
Description
I noticed this behavior specifically with the onPlayerLeave event listener, I don't know if any others are affected at this time.
When the plugin is reloaded, the onPlayerLeave listener is still registered, and thus leads to multiple versions of the listener firing when a player leaves.
Steps to Replicate
- Clone a new serenity server or download the executable binaries.
- Clone a sample plugin.
- Copy and paste the following code to add a new
onPlayerLeavelistener into your plugin:
public onPlayerLeave({ player }: PlayerLeaveSignal): void {
console.log("Player is leaving.")
}
- Start your server and join it with your client.
- Reload the server a few times, then leave the server.
Expected Behavior
The log statement should only be printed once, as the player only left once, and old versions of the listener should be unregistered when the plugin is reloaded.
Current Behavior
The log statement is printed multiple times, indicating the listener executed the callback multiple times.
Player is leaving.
Player is leaving.
Player is leaving.
Player is leaving.
Player is leaving.
<09-06-2025 14:17:32> [default] [Info] [The Palm Healer] Event: Player left the server.