Platform: ProfileResolver - Dani-error/velar GitHub Wiki

๐Ÿ‘ค ProfileResolver

Source Code


๐Ÿ“˜ What is ProfileResolver?

ProfileResolver is a functional interface responsible for asynchronously resolving a Profile into a fully resolved profile (Profile.Resolved), typically including data like UUID, name, and skin properties.


๐Ÿ”ง Interface Overview

Method Description
resolveProfile(profile: Profile): CompletableFuture<Profile.Resolved> Asynchronously resolves the given profile to a fully resolved profile.

๐Ÿ› ๏ธ Companion Object Helpers


๐Ÿ—๏ธ Caching Interface

ProfileResolver.Cached extends ProfileResolver and adds methods to query cached results:

Method Description
fromCache(name: String): Profile.Resolved? Returns cached profile by name, or null if not cached.
fromCache(uniqueId: UUID): Profile.Resolved? Returns cached profile by UUID, or null if not cached.
fromCache(profile: Profile): Profile.Resolved? Returns cached profile by profile instance, or null.

You can also implement ProfileResolver.Cached yourself by overriding these methods:

override fun fromCache(name: String): Profile.Resolved? {
    // Return cached profile by name or null
}

override fun fromCache(uniqueId: UUID): Profile.Resolved? {
    // Return cached profile by UUID or null
}

override fun fromCache(profile: Profile): Profile.Resolved? {
    // Return cached profile by Profile or null
}

๐Ÿ’ก Usage Example

val resolver = ProfileResolver.mojang()

resolver.resolveProfile(profile).thenAccept { resolvedProfile ->
    println("Resolved profile UUID: ${resolvedProfile.uniqueId}")
}

Or with caching:

val cachedResolver = ProfileResolver.caching(resolver)

cachedResolver.resolveProfile(profile).thenAccept { resolved ->
    println("Cached or resolved profile: $resolved")
}

You can create your own custom resolver by implementing the interface:

class ProfileResolverCustom : ProfileResolver {
    override fun resolveProfile(profile: Profile): CompletableFuture<Profile.Resolved> {
        // Your async resolution logic here
    }
}