Search in sources :

Example 36 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Pokemon method powerUpAsync.

/**
	 * Powers up a pokemon with candy and stardust.
	 * After powering up this pokemon object will reflect the new changes.
	 *
	 * @return The result
	 */
public Observable<UpgradePokemonResponse.Result> powerUpAsync() {
    UpgradePokemonMessage reqMsg = UpgradePokemonMessage.newBuilder().setPokemonId(getId()).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.UPGRADE_POKEMON, reqMsg);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, UpgradePokemonResponse.Result>() {

        @Override
        public UpgradePokemonResponse.Result call(ByteString result) {
            UpgradePokemonResponse response;
            try {
                response = UpgradePokemonResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            //set new pokemon details
            applyProto(response.getUpgradedPokemon());
            return response.getResult();
        }
    });
}
Also used : UpgradePokemonMessage(POGOProtos.Networking.Requests.Messages.UpgradePokemonMessageOuterClass.UpgradePokemonMessage) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) UpgradePokemonResponse(POGOProtos.Networking.Responses.UpgradePokemonResponseOuterClass.UpgradePokemonResponse) EvolutionResult(com.pokegoapi.api.map.pokemon.EvolutionResult) Result(POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result)

Example 37 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Gym method deployPokemon.

/**
	 * Deploy pokemon
	 *
	 * @param pokemon The pokemon to deploy
	 * @return Result of attempt to deploy pokemon
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public FortDeployPokemonResponse.Result deployPokemon(Pokemon pokemon) throws RequestFailedException {
    FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage.newBuilder().setFortId(getId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).setPokemonId(pokemon.getId()).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.FORT_DEPLOY_POKEMON, reqMsg);
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    try {
        return FortDeployPokemonResponse.parseFrom(serverRequest.getData()).getResult();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException();
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) FortDeployPokemonMessage(POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 38 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class EggIncubator method hatchEgg.

/**
	 * Hatch an egg.
	 *
	 * @param egg the egg
	 * @return status of putting egg in incubator
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg) throws RequestFailedException {
    UseItemEggIncubatorMessage reqMsg = UseItemEggIncubatorMessage.newBuilder().setItemId(proto.getId()).setPokemonId(egg.getId()).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.USE_ITEM_EGG_INCUBATOR, reqMsg);
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    UseItemEggIncubatorResponse response;
    try {
        response = UseItemEggIncubatorResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.getInventories().updateInventories(true);
    return response.getResult();
}
Also used : UseItemEggIncubatorResponse(POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) UseItemEggIncubatorMessage(POGOProtos.Networking.Requests.Messages.UseItemEggIncubatorMessageOuterClass.UseItemEggIncubatorMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 39 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Hatchery method queryHatchedEggs.

/**
	 * Get if eggs has hatched.
	 *
	 * @return list of hatched eggs
	 * @throws RequestFailedException if an exception occurred while sending requests
	 * @deprecated Use getHatchedEggs()
	 */
@Deprecated
public List<HatchedEgg> queryHatchedEggs() throws RequestFailedException {
    GetHatchedEggsMessage msg = GetHatchedEggsMessage.newBuilder().build();
    ServerRequest serverRequest = new ServerRequest(RequestType.GET_HATCHED_EGGS, msg);
    api.getRequestHandler().sendServerRequests(serverRequest);
    GetHatchedEggsResponse response;
    try {
        response = GetHatchedEggsResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.getInventories().updateInventories();
    return updateHatchedEggs(response);
}
Also used : GetHatchedEggsResponse(POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse) GetHatchedEggsMessage(POGOProtos.Networking.Requests.Messages.GetHatchedEggsMessageOuterClass.GetHatchedEggsMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 40 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Inventories method updateInventories.

/**
	 * Updates the inventories with the latest data.
	 *
	 * @param forceUpdate For a full update if true
	 * @return the response to the update message
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public GetInventoryResponse updateInventories(boolean forceUpdate) throws RequestFailedException {
    if (forceUpdate) {
        lastInventoryUpdate = 0;
        itemBag.reset();
        pokebank.reset();
        candyjar.reset();
        pokedex.reset();
        synchronized (this.lock) {
            incubators.clear();
        }
        hatchery.reset();
    }
    GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder().setLastTimestampMs(lastInventoryUpdate).build();
    ServerRequest inventoryRequest = new ServerRequest(RequestTypeOuterClass.RequestType.GET_INVENTORY, invReqMsg);
    api.getRequestHandler().sendServerRequests(inventoryRequest);
    GetInventoryResponse response;
    try {
        response = GetInventoryResponse.parseFrom(inventoryRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return response;
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) GetInventoryMessage(POGOProtos.Networking.Requests.Messages.GetInventoryMessageOuterClass.GetInventoryMessage) ServerRequest(com.pokegoapi.main.ServerRequest) GetInventoryResponse(POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)104 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)37 ByteString (com.google.protobuf.ByteString)21 IOException (java.io.IOException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CodedInputStream (com.google.protobuf.CodedInputStream)4 List (java.util.List)4 TypicalData (protos.TypicalData)4 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3 Text (org.apache.hadoop.io.Text)3 YamcsClient (org.yamcs.studio.core.client.YamcsClient)3 ArchiveCatalogue (org.yamcs.studio.core.model.ArchiveCatalogue)3 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2