Skip to content

Commit 60f23e0

Browse files
finreinhardclaude
andcommitted
Fix player challenge state persistence on disconnect
- Remove players from playerChallengeMap when they disconnect - Add removePlayerFromChallenge method to ChallengeManager - Ensure players start in the lobby when reconnecting without auto-joining their previous challenge 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent fc17054 commit 60f23e0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
15
# ChallengePlugin Development Guide
26

37
## Build & Test Commands

src/main/kotlin/li/angu/challengeplugin/listeners/PlayerConnectionListener.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ class PlayerConnectionListener(private val plugin: ChallengePluginPlugin) : List
4646
// Remove the player from the challenge to pause timer if needed
4747
challenge.removePlayer(player)
4848

49-
// But keep the player in the challenge map for reconnection
50-
// The player data is saved and we'll restore it when they reconnect
49+
// Remove the player from the playerChallengeMap
50+
// This ensures they'll start in the lobby when reconnecting
51+
plugin.challengeManager.removePlayerFromChallenge(player.uniqueId)
5152
}
5253
}
5354

src/main/kotlin/li/angu/challengeplugin/managers/ChallengeManager.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ class ChallengeManager(private val plugin: ChallengePluginPlugin) {
389389

390390
return false
391391
}
392+
393+
/**
394+
* Removes a player from the challenge map without affecting the player object.
395+
* Used when a player disconnects to ensure they start fresh in the lobby next time.
396+
*/
397+
fun removePlayerFromChallenge(playerId: UUID) {
398+
playerChallengeMap.remove(playerId)
399+
}
392400

393401
fun completeChallenge(challengeId: UUID) {
394402
val challenge = activeChallenges[challengeId] ?: return

0 commit comments

Comments
 (0)