-
Notifications
You must be signed in to change notification settings - Fork 0
Fix SurfPlayerSyncTask for multiproxy: scope stale eviction to current proxy only and sync current server #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ammodev
merged 10 commits into
version/1.21.11
from
copilot/sync-players-across-servers
Mar 15, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ee45cb
Initial plan
Copilot 3714ead
Add SurfPlayerSyncTask to sync players via Redis every minute
Copilot 1fdde55
Fix SurfPlayerSyncTask for multiproxy: only invalidate stale entries …
Copilot 5068f84
feat: update currentServer from Velocity player during sync task
Copilot bde736f
feat: update server retrieval methods and improve player sync task
TheBjoRedCraft e5978f5
feat: bump version to 1.21.11-1.2.6-SNAPSHOT
TheBjoRedCraft 2113dbc
feat: update server import to use SurfServer in ConnectionListener
TheBjoRedCraft edd6f3f
feat: fallback to load/create player during sync if not cached
Copilot c72d546
feat: enhance player synchronization with logging for invalid players
TheBjoRedCraft 4241cd3
feat: update logging level for invalid player synchronization
TheBjoRedCraft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| kotlin.code.style=official | ||
| kotlin.stdlib.default.dependency=false | ||
| org.gradle.parallel=true | ||
| version=1.21.11-1.2.5-SNAPSHOT | ||
| version=1.21.11-1.2.6-SNAPSHOT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
surf-core-velocity/src/main/kotlin/dev/slne/surf/core/velocity/task/SurfPlayerSyncTask.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package dev.slne.surf.core.velocity.task | ||
|
|
||
| import com.github.shynixn.mccoroutine.velocity.launch | ||
| import com.velocitypowered.api.scheduler.ScheduledTask | ||
| import dev.slne.surf.core.api.common.server.SurfProxyServer | ||
| import dev.slne.surf.core.api.common.server.SurfServer | ||
| import dev.slne.surf.core.core.common.player.surfPlayerService | ||
| import dev.slne.surf.core.velocity.plugin | ||
| import dev.slne.surf.core.velocity.proxy | ||
| import java.util.concurrent.TimeUnit | ||
| import kotlin.jvm.optionals.getOrNull | ||
|
|
||
| val surfPlayerSyncTask = SurfPlayerSyncTask() | ||
|
|
||
| class SurfPlayerSyncTask { | ||
| private var task: ScheduledTask? = null | ||
|
|
||
| fun start() { | ||
| task = proxy.scheduler | ||
| .buildTask(plugin, Runnable { syncPlayers() }) | ||
| .delay(1L, TimeUnit.MINUTES) | ||
| .repeat(1L, TimeUnit.MINUTES) | ||
| .schedule() | ||
| } | ||
|
|
||
| fun stop() { | ||
| task?.cancel() | ||
| task = null | ||
| } | ||
|
|
||
| private fun syncPlayers() { | ||
| plugin.pluginContainer.launch { | ||
| val onlinePlayers = proxy.allPlayers.map { velocityPlayer -> | ||
|
Comment on lines
+18
to
+33
Comment on lines
+26
to
+33
|
||
| val surfPlayer = surfPlayerService.findPlayerByUuid(velocityPlayer.uniqueId) | ||
| ?: surfPlayerService.getOrLoadOrCreatePlayerByUuid(velocityPlayer.uniqueId) | ||
| .also { | ||
| it.currentProxy = SurfProxyServer.current() | ||
| } | ||
| val currentServerName = velocityPlayer.currentServer.getOrNull()?.serverInfo?.name | ||
| val currentServer = currentServerName?.let { SurfServer[it] } | ||
| surfPlayer.copy(currentServer = currentServer) | ||
| } | ||
|
Comment on lines
+34
to
+42
|
||
|
|
||
| val onlineUuids = onlinePlayers.map { it.uuid }.toHashSet() | ||
|
|
||
| SurfProxyServer.current().getPlayers() | ||
| .filter { it.uuid !in onlineUuids } | ||
| .forEach { | ||
| surfPlayerService.invalidatePlayer(it.uuid) | ||
| plugin.logger.info("Found invalid player ${it.uuid} (${it.username}), invalidating cache") | ||
| } | ||
|
|
||
| onlinePlayers.forEach { surfPlayerService.cachePlayer(it) } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing
CommonSurfServer[name]to callgetCommonServerByNamewidens the operator’s return type fromSurfServer?toCommonSurfServer?. There are existing call sites that relied on the old type inference (e.g.surf-core-velocity/.../ConnectionListener.ktusesCommonSurfServer[toServer]and passes it intoSurfPlayer.copy(currentServer = ...), wherecurrentServeris aSurfServer?). After this change that code will no longer type-check. Consider updating those call sites to useSurfServer[name]when a backend server is required, or otherwise explicitly narrow/cast the result before assigning tocurrentServer.