Search in sources :

Example 41 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class IncenseEncounter method encounter.

@Override
public EncounterResult encounter() throws RequestFailedException {
    IncenseEncounterMessage message = IncenseEncounterMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setEncounterLocation(pokemon.getSpawnPointId()).build();
    ServerRequest request = new ServerRequest(RequestType.INCENSE_ENCOUNTER, message);
    ByteString responseData = api.getRequestHandler().sendServerRequests(request, true);
    try {
        IncenseEncounterResponse response = IncenseEncounterResponse.parseFrom(responseData);
        encounterResult = EncounterResult.from(response.getResult());
        activeItem = response.getActiveItem();
        captureProbabilities = response.getCaptureProbability();
        encounteredPokemon = response.getPokemonData();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return encounterResult;
}
Also used : IncenseEncounterResponse(POGOProtos.Networking.Responses.IncenseEncounterResponseOuterClass.IncenseEncounterResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IncenseEncounterMessage(POGOProtos.Networking.Requests.Messages.IncenseEncounterMessageOuterClass.IncenseEncounterMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 42 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Settings method updateSettings.

/**
	 * Updates settings latest data.
	 *
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public void updateSettings() throws RequestFailedException {
    DownloadSettingsMessageOuterClass.DownloadSettingsMessage msg = DownloadSettingsMessageOuterClass.DownloadSettingsMessage.newBuilder().build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.DOWNLOAD_SETTINGS, msg);
    //here you marked everything as read
    api.getRequestHandler().sendServerRequests(serverRequest, false);
    DownloadSettingsResponseOuterClass.DownloadSettingsResponse response;
    try {
        response = DownloadSettingsResponseOuterClass.DownloadSettingsResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    updateSettings(response);
}
Also used : DownloadSettingsResponse(POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) DownloadSettingsMessageOuterClass(POGOProtos.Networking.Requests.Messages.DownloadSettingsMessageOuterClass) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DownloadSettingsResponseOuterClass(POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)42 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)35 ByteString (com.google.protobuf.ByteString)13 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 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2 LevelUpRewardsMessage (POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage)2 ReleasePokemonMessage (POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage)2 UseItemEncounterMessage (POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage)2 LevelUpRewardsResponse (POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse)2 UseItemEncounterResponse (POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse)2 EvolutionResult (com.pokegoapi.api.map.pokemon.EvolutionResult)2 BattleAction (POGOProtos.Data.Battle.BattleActionOuterClass.BattleAction)1 PlayerBadge (POGOProtos.Data.PlayerBadgeOuterClass.PlayerBadge)1 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 TutorialState (POGOProtos.Enums.TutorialStateOuterClass.TutorialState)1 Candy (POGOProtos.Inventory.CandyOuterClass.Candy)1