Skip to content

Commit aa94d1b

Browse files
committed
feat: add utility functions for asynchronous player profile retrieval
1 parent 7aee363 commit aa94d1b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.slne.surf.surfapi.bukkit.api.command.util
2+
3+
import com.destroystokyo.paper.profile.PlayerProfile
4+
import dev.jorel.commandapi.executors.CommandArguments
5+
import kotlinx.coroutines.future.await
6+
import java.util.*
7+
import java.util.concurrent.CompletableFuture
8+
9+
suspend fun CommandArguments.awaitAsyncPlayerProfileOptional(
10+
nodeName: String,
11+
): PlayerProfile? {
12+
val future = getUnchecked<CompletableFuture<List<PlayerProfile>>>(nodeName) ?: return null
13+
14+
try {
15+
val profiles = future.await()
16+
return profiles.first()
17+
} catch (e: RuntimeException) {
18+
throw e.cause ?: e
19+
}
20+
}
21+
22+
suspend fun CommandArguments.awaitAsyncPlayerProfile(nodeName: String): PlayerProfile =
23+
awaitAsyncPlayerProfileOptional(nodeName) ?: error("Argument '$nodeName' not found")
24+
25+
fun PlayerProfile.idOrThrow(): UUID = id ?: error("PlayerProfile does not provide a uuid")

0 commit comments

Comments
 (0)