Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 102d728

Browse files
committed
feat: add companion object operator functions for centralized entity retrieval
- Introduced `operator fun get(...)` methods in `CloudServer`, `CommonCloudServer`, `ProxyCloudServer`, `CloudPlayer`, and `OfflineCloudPlayer` for streamlined access to entities via `CloudManager` instances. - Enhanced API consistency and usability with unified retrieval patterns.
1 parent 6006738 commit 102d728

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/player/CloudPlayer.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ interface CloudPlayer : Audience, OfflineCloudPlayer { // TODO: conversation but
189189
fun playSound(sound: Sound, emitter: Sound.Emitter, permission: String)
190190

191191
suspend fun hasPermission(permission: String): Boolean
192+
193+
companion object {
194+
operator fun get(uuid: UUID) = CloudPlayerManager.getPlayer(uuid)
195+
operator fun get(name: String) = CloudPlayerManager.getPlayer(name)
196+
fun all() = CloudPlayerManager.getOnlinePlayers()
197+
}
192198
}
193199

194200
/**

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/player/OfflineCloudPlayer.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ interface OfflineCloudPlayer {
6363
*/
6464
suspend fun getLuckpermsMetaData(key: String): String?
6565

66+
companion object {
67+
operator fun get(uuid: UUID, createIfNotExists: Boolean = true) =
68+
CloudPlayerManager.getOfflinePlayer(uuid, createIfNotExists)
69+
}
6670
}

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/server/CloudServer.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ interface CloudServer : CommonCloudServer {
2929
suspend fun pullPlayers(players: Collection<CloudPlayer>): @Unmodifiable ObjectList<Pair<CloudPlayer, ConnectionResultEnum>>
3030

3131
companion object {
32+
operator fun get(uid: Long) = CloudServerManager.retrieveServerById(uid) as? CloudServer
33+
operator fun get(category: String, name: String) =
34+
CloudServerManager.retrieveServerByCategoryAndName(category, name) as? CloudServer
35+
36+
operator fun get(name: String) =
37+
CloudServerManager.retrieveServerByName(name) as? CloudServer
38+
3239
fun all() = CloudServerManager.retrieveServers()
3340
}
3441
}

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/server/CommonCloudServer.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ interface CommonCloudServer : ForwardingAudience {
121121
fun shutdown()
122122

123123
companion object {
124+
operator fun get(uid: Long) = CloudServerManager.retrieveServerById(uid)
125+
operator fun get(category: String, name: String) =
126+
CloudServerManager.retrieveServerByCategoryAndName(category, name)
127+
128+
operator fun get(name: String) = CloudServerManager.retrieveServerByName(name)
124129
fun all() = CloudServerManager.retrieveAllServers()
130+
131+
125132
}
126133
}

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/server/ProxyCloudServer.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import org.jetbrains.annotations.ApiStatus
1515
@ApiStatus.NonExtendable
1616
interface ProxyCloudServer : CommonCloudServer {
1717
companion object {
18+
operator fun get(uid: Long) = CloudServerManager.retrieveServerById(uid) as? ProxyCloudServer
19+
operator fun get(category: String, name: String) =
20+
CloudServerManager.retrieveServerByCategoryAndName(category, name) as? ProxyCloudServer
21+
22+
operator fun get(name: String) = CloudServerManager.retrieveServerByName(name) as? ProxyCloudServer
23+
1824
fun all() = CloudServerManager.retrieveProxies()
1925
}
2026
}

0 commit comments

Comments
 (0)