Skip to content

Commit 3a6a406

Browse files
authored
Merge pull request #814 from pylonmc/human/scope-error-fix
Scope Cancel Fix
2 parents 2648603 + cd68eff commit 3a6a406

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

rebar/src/main/kotlin/io/github/pylonmc/rebar/async/ChunkScope.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.common.collect.HashMultimap
44
import io.github.pylonmc.rebar.util.position.ChunkPosition
55
import io.github.pylonmc.rebar.util.position.position
66
import kotlinx.coroutines.CoroutineScope
7+
import kotlinx.coroutines.Job
78
import kotlinx.coroutines.cancel
89
import org.bukkit.event.EventHandler
910
import org.bukkit.event.EventPriority
@@ -26,7 +27,11 @@ class ChunkScope(override val coroutineContext: CoroutineContext, chunk: ChunkPo
2627

2728
@EventHandler(priority = EventPriority.MONITOR)
2829
private fun onChunkUnload(event: ChunkUnloadEvent) {
29-
chunkScopes.removeAll(event.chunk.position).forEach { it.cancel() }
30+
chunkScopes.removeAll(event.chunk.position).forEach {
31+
if (it.coroutineContext[Job] != null) {
32+
it.cancel()
33+
}
34+
}
3035
}
3136
}
3237
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/async/PlayerScope.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package io.github.pylonmc.rebar.async
22

33
import com.google.common.collect.HashMultimap
44
import kotlinx.coroutines.CoroutineScope
5+
import kotlinx.coroutines.Job
56
import kotlinx.coroutines.cancel
7+
import kotlinx.coroutines.currentCoroutineContext
8+
import kotlinx.coroutines.job
69
import org.bukkit.Bukkit
710
import org.bukkit.entity.Player
811
import org.bukkit.event.EventHandler
@@ -29,7 +32,11 @@ class PlayerScope(override val coroutineContext: CoroutineContext, playerId: UUI
2932

3033
@EventHandler(priority = EventPriority.MONITOR)
3134
private fun onPlayerQuit(event: PlayerQuitEvent) {
32-
playerScopes.removeAll(event.player.uniqueId).forEach { it.cancel() }
35+
playerScopes.removeAll(event.player.uniqueId).forEach {
36+
if (it.coroutineContext[Job] != null) {
37+
it.cancel()
38+
}
39+
}
3340
}
3441
}
3542
}

0 commit comments

Comments
 (0)