Search in sources :

Example 1 with NicknamePokemonMessage

use of POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage in project PokeGOAPI-Java by Grover-c13.

the class Pokemon method renamePokemon.

/**
 * Rename pokemon nickname pokemon response . result.
 *
 * @param nickname the nickname
 * @return the nickname pokemon response . result
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public NicknamePokemonResponse.Result renamePokemon(String nickname) throws RequestFailedException {
    NicknamePokemonMessage reqMsg = NicknamePokemonMessage.newBuilder().setPokemonId(getId()).setNickname(nickname).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.NICKNAME_POKEMON, reqMsg);
    api.requestHandler.sendServerRequests(serverRequest, true);
    NicknamePokemonResponse response;
    try {
        response = NicknamePokemonResponse.parseFrom(serverRequest.getData());
        if (response.getResult() == NicknamePokemonResponse.Result.SUCCESS) {
            this.nickname = nickname;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.inventories.pokebank.removePokemon(this);
    return response.getResult();
}
Also used : NicknamePokemonMessage(POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage) NicknamePokemonResponse(POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

NicknamePokemonMessage (POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage)1 NicknamePokemonResponse (POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1