Search in sources :

Example 1 with HttpAuthenticationService

use of com.mojang.authlib.HttpAuthenticationService in project DirtMultiversion by DirtPowered.

the class GameProfileFetcher method fetchBlocking.

private static GameProfile fetchBlocking(String username) throws ExecutionException, InterruptedException {
    HttpAuthenticationService authenticationService = new YggdrasilAuthenticationService(Proxy.NO_PROXY);
    MinecraftSessionService sessionService = authenticationService.createMinecraftSessionService();
    GameProfileRepository service = authenticationService.createProfileRepository();
    CompletableFuture<GameProfile> completableFuture = new CompletableFuture<>();
    service.findProfilesByNames(new String[] { username }, Agent.MINECRAFT, new ProfileLookupCallback() {

        @Override
        public void onProfileLookupSucceeded(GameProfile gameProfile) {
            sessionService.fillProfileProperties(gameProfile, true);
            completableFuture.complete(gameProfile);
        }

        @Override
        public void onProfileLookupFailed(GameProfile gameProfile, Exception e) {
            Logger.warn("unable to fetch profile for {}, e: {}", username, e.getMessage());
            GameProfile offlineProfile = createOfflineProfile(username);
            completableFuture.complete(offlineProfile);
        }
    });
    return completableFuture.get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HttpAuthenticationService(com.mojang.authlib.HttpAuthenticationService) GameProfile(com.mojang.authlib.GameProfile) GameProfileRepository(com.mojang.authlib.GameProfileRepository) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) ProfileLookupCallback(com.mojang.authlib.ProfileLookupCallback) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 GameProfileRepository (com.mojang.authlib.GameProfileRepository)1 HttpAuthenticationService (com.mojang.authlib.HttpAuthenticationService)1 ProfileLookupCallback (com.mojang.authlib.ProfileLookupCallback)1 MinecraftSessionService (com.mojang.authlib.minecraft.MinecraftSessionService)1 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1