File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
surf-api-bukkit/surf-api-bukkit-api/src/main/kotlin/dev/slne/surf/surfapi/bukkit/api/command/util Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 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" )
You can’t perform that action at this time.
0 commit comments