Search in sources :

Example 1 with SetFavoritePokemonMessage

use of POGOProtos.Networking.Requests.Messages.SetFavoritePokemonMessageOuterClass.SetFavoritePokemonMessage in project PokeGOAPI-Java by Grover-c13.

the class Pokemon method setFavoritePokemon.

/**
 * Function to mark the pokemon as favorite or not.
 *
 * @param markFavorite Mark Pokemon as Favorite?
 * @return the SetFavoritePokemonResponse.Result
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public SetFavoritePokemonResponse.Result setFavoritePokemon(boolean markFavorite) throws RequestFailedException {
    SetFavoritePokemonMessage reqMsg = SetFavoritePokemonMessage.newBuilder().setPokemonId(getId()).setIsFavorite(markFavorite).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.SET_FAVORITE_POKEMON, reqMsg);
    api.requestHandler.sendServerRequests(serverRequest, true);
    SetFavoritePokemonResponse response;
    try {
        response = SetFavoritePokemonResponse.parseFrom(serverRequest.getData());
        if (response.getResult() == SetFavoritePokemonResponse.Result.SUCCESS) {
            favorite = markFavorite ? 1 : 0;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.inventories.pokebank.removePokemon(this);
    return response.getResult();
}
Also used : SetFavoritePokemonResponse(POGOProtos.Networking.Responses.SetFavoritePokemonResponseOuterClass.SetFavoritePokemonResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) SetFavoritePokemonMessage(POGOProtos.Networking.Requests.Messages.SetFavoritePokemonMessageOuterClass.SetFavoritePokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

SetFavoritePokemonMessage (POGOProtos.Networking.Requests.Messages.SetFavoritePokemonMessageOuterClass.SetFavoritePokemonMessage)1 SetFavoritePokemonResponse (POGOProtos.Networking.Responses.SetFavoritePokemonResponseOuterClass.SetFavoritePokemonResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1