Search in sources :

Example 1 with ProfileLookupCallback

use of com.mojang.authlib.ProfileLookupCallback in project Citizens2 by CitizensDev.

the class ProfileFetcher method fetchRequests.

/**
 * Fetch one or more profiles.
 *
 * @param requests
 *            The profile requests.
 */
void fetchRequests(final Collection<ProfileRequest> requests) {
    Preconditions.checkNotNull(requests);
    final GameProfileRepository repo = NMS.getGameProfileRepository();
    String[] playerNames = new String[requests.size()];
    int i = 0;
    for (ProfileRequest request : requests) {
        playerNames[i++] = request.getPlayerName();
    }
    repo.findProfilesByNames(playerNames, Agent.MINECRAFT, new ProfileLookupCallback() {

        @Override
        public void onProfileLookupFailed(GameProfile profile, Exception e) {
            if (Messaging.isDebugging()) {
                Messaging.debug("Profile lookup for player '" + profile.getName() + "' failed2: " + getExceptionMsg(e));
                Messaging.debug(Throwables.getStackTraceAsString(e));
            }
            ProfileRequest request = findRequest(profile.getName(), requests);
            if (request == null)
                return;
            if (isProfileNotFound(e)) {
                request.setResult(null, ProfileFetchResult.NOT_FOUND);
            } else if (isTooManyRequests(e)) {
                request.setResult(null, ProfileFetchResult.TOO_MANY_REQUESTS);
            } else {
                request.setResult(null, ProfileFetchResult.FAILED);
            }
        }

        @Override
        public void onProfileLookupSucceeded(final GameProfile profile) {
            if (Messaging.isDebugging()) {
                Messaging.debug("Fetched profile " + profile.getId() + " for player " + profile.getName());
            }
            ProfileRequest request = findRequest(profile.getName(), requests);
            if (request == null)
                return;
            try {
                request.setResult(NMS.fillProfileProperties(profile, true), ProfileFetchResult.SUCCESS);
            } catch (Exception e) {
                if (Messaging.isDebugging()) {
                    Messaging.debug("Profile lookup for player '" + profile.getName() + "' failed: " + getExceptionMsg(e) + " " + isTooManyRequests(e));
                    Messaging.debug(Throwables.getStackTraceAsString(e));
                }
                if (isTooManyRequests(e)) {
                    request.setResult(null, ProfileFetchResult.TOO_MANY_REQUESTS);
                } else {
                    request.setResult(null, ProfileFetchResult.FAILED);
                }
            }
        }
    });
}
Also used : GameProfile(com.mojang.authlib.GameProfile) GameProfileRepository(com.mojang.authlib.GameProfileRepository) ProfileLookupCallback(com.mojang.authlib.ProfileLookupCallback)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 GameProfileRepository (com.mojang.authlib.GameProfileRepository)1 ProfileLookupCallback (com.mojang.authlib.ProfileLookupCallback)1