-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/all player tab completions #49
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
Open
TheBjoRedCraft
wants to merge
5
commits into
version/26.2
Choose a base branch
from
feat/all-player-tab-completions
base: version/26.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
44fbf42
feat: implement offline player name caching and loading functionality
TheBjoRedCraft 4ca3a4a
feat: update player name suggestion logic to allow single-character p…
TheBjoRedCraft 7244d75
feat: add error handling and logging to offline player name cache ref…
TheBjoRedCraft 855a3e7
feat: allow zero-character prefixes for player name suggestions
TheBjoRedCraft dd1b7af
feat: remove minimum prefix length check for player name suggestions
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
Some comments aren't visible on the classic Files Changed page.
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=2.4.1 | ||
| version=2.4.2 |
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
58 changes: 58 additions & 0 deletions
58
...-api-common/src/main/kotlin/dev/slne/surf/core/api/common/cache/OfflinePlayerNameCache.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,58 @@ | ||
| package dev.slne.surf.core.api.common.cache | ||
|
|
||
| import dev.slne.surf.api.core.serializer.java.uuid.SerializableUUID | ||
| import dev.slne.surf.api.core.util.logger | ||
| import dev.slne.surf.core.api.common.SurfCoreApi | ||
| import kotlinx.coroutines.* | ||
| import kotlinx.serialization.Serializable | ||
| import kotlin.time.Duration.Companion.minutes | ||
|
|
||
| object OfflinePlayerNameCache { | ||
| private val logger = logger() | ||
|
|
||
| @Volatile | ||
| private var sortedNames: List<String> = emptyList() | ||
| private val CACHE_REFRESH_INTERVAL = 5.minutes | ||
|
|
||
| suspend fun refresh() { | ||
| sortedNames = SurfCoreApi.loadOfflinePlayerNameEntries().map { it.name } | ||
| .sortedWith(String.CASE_INSENSITIVE_ORDER) | ||
| } | ||
|
|
||
| fun findByPrefix(prefix: String): List<String> { | ||
| val lower = prefix.lowercase() | ||
| val snapshot = sortedNames | ||
|
|
||
| var lo = 0 | ||
| var hi = snapshot.size | ||
| while (lo < hi) { | ||
| val mid = (lo + hi) ushr 1 | ||
| if (snapshot[mid].lowercase() < lower) lo = mid + 1 else hi = mid | ||
| } | ||
|
|
||
| return buildList { | ||
| var i = lo | ||
| while (i < snapshot.size && snapshot[i].lowercase().startsWith(lower)) { | ||
| add(snapshot[i]) | ||
| i++ | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun startPulling(instanceScope: CoroutineScope) = instanceScope.launch(Dispatchers.IO) { | ||
| while (isActive) { | ||
| runCatching { | ||
| refresh() | ||
| }.onFailure { | ||
| logger.atFine().log("Failed to refresh offline player name cache: ${it.message}") | ||
| } | ||
| delay(CACHE_REFRESH_INTERVAL) | ||
| } | ||
| } | ||
|
|
||
| @Serializable | ||
| data class Entry( | ||
| val uuid: SerializableUUID, | ||
| val name: String | ||
| ) | ||
| } | ||
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
9 changes: 9 additions & 0 deletions
9
.../surf-core-core-client/src/main/kotlin/dev/slne/surf/core/client/SurfCoreApiClientImpl.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,9 @@ | ||
| package dev.slne.surf.core.client | ||
|
|
||
| import dev.slne.surf.core.core.common.SurfCoreApiImpl | ||
| import dev.slne.surf.core.core.common.rabbit.packet.player.load.LoadOfflinePlayerNameEntriesRequestPacket | ||
|
|
||
| abstract class SurfCoreApiClientImpl : SurfCoreApiImpl() { | ||
| override suspend fun loadOfflinePlayerNameEntries() = | ||
| ClientCoreInstance.rabbitApi.sendRequest(LoadOfflinePlayerNameEntriesRequestPacket()).entries | ||
| } |
10 changes: 10 additions & 0 deletions
10
...v/slne/surf/core/core/common/rabbit/packet/player/ManyOfflinePlayerNamesResponsePacket.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,10 @@ | ||
| package dev.slne.surf.core.core.common.rabbit.packet.player | ||
|
|
||
| import dev.slne.surf.core.api.common.cache.OfflinePlayerNameCache | ||
| import dev.slne.surf.rabbitmq.api.packet.RabbitResponsePacket | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class ManyOfflinePlayerNamesResponsePacket( | ||
| val entries: List<OfflinePlayerNameCache.Entry> | ||
| ) : RabbitResponsePacket() |
9 changes: 9 additions & 0 deletions
9
...f/core/core/common/rabbit/packet/player/load/LoadOfflinePlayerNameEntriesRequestPacket.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,9 @@ | ||
| package dev.slne.surf.core.core.common.rabbit.packet.player.load | ||
|
|
||
| import dev.slne.surf.core.core.common.rabbit.packet.player.ManyOfflinePlayerNamesResponsePacket | ||
| import dev.slne.surf.rabbitmq.api.packet.RabbitRequestPacket | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| class LoadOfflinePlayerNameEntriesRequestPacket : | ||
| RabbitRequestPacket<ManyOfflinePlayerNamesResponsePacket>() |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.