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();
}
});
}
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();
}
}
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();
}
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);
}
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;
}
Aggregations