Skip to content

Commit 83f031c

Browse files
committed
[EntityCulling] Fix not synchronized on updateChanges, optimize loop
1 parent c5caaf7 commit 83f031c

File tree

1 file changed

+7
-4
lines changed
  • bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling

1 file changed

+7
-4
lines changed

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling/UserCullData.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,19 @@ class UserCullData(
106106

107107
private fun updateChanges() {
108108
if (terminated) return
109-
if (pendingChanges.isEmpty()) return
110109

111-
val list = pendingChanges.toList()
112-
pendingChanges.clear()
110+
val changes = synchronized(hiddenEntities) {
111+
if (pendingChanges.isEmpty()) return
112+
val temp = pendingChanges.toTypedArray()
113+
pendingChanges.clear()
114+
temp
115+
}
113116
if (plugin.isEnabled) {
114117
if (!player.connected)
115118
Bukkit.getPlayer(player.uniqueId)?.let { player = it }
116119
Scheduler.schedule(player) {
117120
val raytraceHandler = raytraceHandler
118-
for (change in list) {
121+
for (change in changes) {
119122
if (!raytraceHandler.isValid(change.entity)) continue
120123
if (!change.entity.checkTickThread()) {
121124
// Not on tick thread, we can only reflect to make changes,

0 commit comments

Comments
 (0)