Skip to content

Commit f81d61c

Browse files
committed
♻️ refactor(service): improve requirement caching for connected players
- check player connection status before caching requirement - store requirement result in cache only if player is connected
1 parent a2e2a4e commit f81d61c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

surf-api-paper/surf-api-paper-server/src/main/kotlin/dev/slne/surf/api/paper/server/command/SuspendRequirementServiceImpl.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ class SuspendRequirementServiceImpl : SuspendRequirementService {
151151
suspend fun refreshForSender(sender: Player) {
152152
withContext(scope().coroutineContext.minusKey(Job)) {
153153
try {
154-
cached.put(sender.uniqueId, requirement(sender))
154+
val isRequirementMet = requirement(sender)
155+
if (sender.isConnected) { // check if this player instance is still connected
156+
cached.put(sender.uniqueId, isRequirementMet)
157+
}
155158
} catch (e: Throwable) {
156159
if (e is CancellationException) throw e
157160
log.atWarning()

0 commit comments

Comments
 (0)