Search in sources :

Example 1 with GetPlayerMessage

use of POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method claimCodeName.

/**
 * Setup an user name for our account
 *
 * @param lastFailure the last name used that was already taken; null for first try.
 * @return the claimed codename
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public String claimCodeName(String lastFailure) throws RequestFailedException {
    if (getPlayerData().getRemainingCodenameClaims() <= 0) {
        throw new RuntimeException("You have no remaining codename claims!");
    }
    String name = randomCodenameGenerator();
    List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
    for (TutorialListener listener : listeners) {
        String listenerName = listener.claimName(api, lastFailure);
        if (listenerName != null) {
            name = listenerName;
            break;
        }
    }
    ClaimCodenameMessage claimCodenameMessage = ClaimCodenameMessage.newBuilder().setCodename(name).build();
    ServerRequest request = new ServerRequest(RequestType.CLAIM_CODENAME, claimCodenameMessage);
    api.requestHandler.sendServerRequests(request, true);
    String updatedCodename;
    try {
        ClaimCodenameResponse claimCodenameResponse = ClaimCodenameResponse.parseFrom(request.getData());
        if (claimCodenameResponse.getStatus() != ClaimCodenameResponse.Status.SUCCESS) {
            return claimCodeName(name);
        }
        updatedCodename = claimCodenameResponse.getCodename();
        if (claimCodenameResponse.hasUpdatedPlayer()) {
            updateProfile(claimCodenameResponse.getUpdatedPlayer());
        }
        if (updatedCodename != null) {
            markTutorial(TutorialStateOuterClass.TutorialState.NAME_SELECTION);
            final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
            request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
            api.requestHandler.sendServerRequests(request, true);
            updateProfile(GetPlayerResponse.parseFrom(request.getData()));
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return updatedCodename;
}
Also used : GetPlayerMessage(POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage) TutorialListener(com.pokegoapi.api.listener.TutorialListener) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ClaimCodenameResponse(POGOProtos.Networking.Responses.ClaimCodenameResponseOuterClass.ClaimCodenameResponse) ServerRequest(com.pokegoapi.main.ServerRequest) ClaimCodenameMessage(POGOProtos.Networking.Requests.Messages.ClaimCodenameMessageOuterClass.ClaimCodenameMessage)

Example 2 with GetPlayerMessage

use of POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method encounterTutorialComplete.

/**
 * Encounter tutorial complete. In other words, catch the first Pokémon
 *
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public void encounterTutorialComplete() throws RequestFailedException {
    StarterPokemon starter = StarterPokemon.random();
    List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
    for (TutorialListener listener : listeners) {
        StarterPokemon pokemon = listener.selectStarter(api);
        if (pokemon != null) {
            starter = pokemon;
            break;
        }
    }
    final EncounterTutorialCompleteMessage.Builder builder = EncounterTutorialCompleteMessage.newBuilder().setPokemonId(starter.pokemon);
    ServerRequest request = new ServerRequest(RequestType.ENCOUNTER_TUTORIAL_COMPLETE, builder.build());
    api.requestHandler.sendServerRequests(request, true);
    final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
    request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
    api.requestHandler.sendServerRequests(request, true);
    try {
        updateProfile(GetPlayerResponse.parseFrom(request.getData()));
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : GetPlayerMessage(POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage) EncounterTutorialCompleteMessage(POGOProtos.Networking.Requests.Messages.EncounterTutorialCompleteMessageOuterClass.EncounterTutorialCompleteMessage) TutorialListener(com.pokegoapi.api.listener.TutorialListener) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) StarterPokemon(com.pokegoapi.api.pokemon.StarterPokemon)

Example 3 with GetPlayerMessage

use of POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method updateProfile.

/**
 * Updates the player profile with the latest data.
 *
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public void updateProfile() throws RequestFailedException {
    GetPlayerMessage message = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
    ServerRequest request = new ServerRequest(RequestType.GET_PLAYER, message);
    api.requestHandler.sendServerRequests(request, false);
    try {
        updateProfile(GetPlayerResponse.parseFrom(request.getData()));
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : GetPlayerMessage(POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)3 ServerRequest (com.pokegoapi.main.ServerRequest)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)2 ClaimCodenameMessage (POGOProtos.Networking.Requests.Messages.ClaimCodenameMessageOuterClass.ClaimCodenameMessage)1 EncounterTutorialCompleteMessage (POGOProtos.Networking.Requests.Messages.EncounterTutorialCompleteMessageOuterClass.EncounterTutorialCompleteMessage)1 ClaimCodenameResponse (POGOProtos.Networking.Responses.ClaimCodenameResponseOuterClass.ClaimCodenameResponse)1 StarterPokemon (com.pokegoapi.api.pokemon.StarterPokemon)1