Skip to content

Commit

Permalink
Add player quit event handler to reset action cooldowns
Browse files Browse the repository at this point in the history
This change introduces a handler for the PlayerQuitEvent to ensure player action cooldowns are reset when they leave. This prevents potential memory leaks by cleaning up player-specific data in the character controller.
  • Loading branch information
NonSwag committed Jan 15, 2025
1 parent 29bc13e commit 8dbe62a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jspecify.annotations.NullMarked;

@NullMarked
Expand All @@ -25,6 +26,13 @@ public void onPlayerJoin(PlayerJoinEvent event) {
loadCharacters(event.getPlayer().getWorld(), event.getPlayer());
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
plugin.characterController().getCharacters().forEach(character ->
character.getActions().values().forEach(action ->
action.resetCooldown(event.getPlayer())));
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
loadCharacters(event.getPlayer().getWorld(), event.getPlayer());
Expand Down

0 comments on commit 8dbe62a

Please sign in to comment.