Search in sources :

Example 1 with PokemonListener

use of com.pokegoapi.api.listener.PokemonListener in project PokeGOAPI-Java by Grover-c13.

the class Hatchery method addHatchedEgg.

/**
 * Adds the given hatched egg to the hatchedEggs set.
 *
 * @param egg the egg to add
 */
public void addHatchedEgg(HatchedEgg egg) {
    synchronized (this.lock) {
        hatchedEggs.add(egg);
    }
    boolean remove = false;
    List<PokemonListener> listeners = api.getListeners(PokemonListener.class);
    for (PokemonListener listener : listeners) {
        remove |= listener.onEggHatch(api, egg);
    }
    if (remove) {
        removeHatchedEgg(egg);
    }
}
Also used : PokemonListener(com.pokegoapi.api.listener.PokemonListener)

Example 2 with PokemonListener

use of com.pokegoapi.api.listener.PokemonListener in project PokeGOAPI-Java by Grover-c13.

the class CommonRequests method handleCommons.

/**
 * Handles all commons in a ServerResponse
 * @param api the current api
 * @param response the response to handle
 * @throws InvalidProtocolBufferException if an invalid response is parsed
 * @throws RequestFailedException if a request fails while sending a request
 */
public static void handleCommons(PokemonGo api, ServerResponse response) throws InvalidProtocolBufferException, RequestFailedException {
    if (response.has(RequestType.DOWNLOAD_SETTINGS)) {
        ByteString data = response.get(RequestType.DOWNLOAD_SETTINGS);
        DownloadSettingsResponse settings = DownloadSettingsResponse.parseFrom(data);
        api.settings.updateSettings(settings);
    }
    if (response.has(RequestType.CHECK_CHALLENGE)) {
        ByteString data = response.get(RequestType.CHECK_CHALLENGE);
        CheckChallengeResponse checkChallenge = CheckChallengeResponse.parseFrom(data);
        api.updateChallenge(checkChallenge.getChallengeUrl(), checkChallenge.getShowChallenge());
    }
    if (response.has(RequestType.GET_HOLOHOLO_INVENTORY)) {
        ByteString data = response.get(RequestType.GET_HOLOHOLO_INVENTORY);
        GetHoloInventoryResponse inventory = GetHoloInventoryResponse.parseFrom(data);
        api.inventories.updateInventories(inventory);
    }
    if (response.has(RequestType.CHECK_AWARDED_BADGES)) {
        ByteString data = response.get(RequestType.CHECK_AWARDED_BADGES);
        CheckAwardedBadgesResponse awardedBadges = CheckAwardedBadgesResponse.parseFrom(data);
        api.playerProfile.updateAwardedMedals(awardedBadges);
    }
    if (response.has(RequestType.GET_HATCHED_EGGS)) {
        ByteString data = response.get(RequestType.GET_HATCHED_EGGS);
        GetHatchedEggsResponse hatchedEggs = GetHatchedEggsResponse.parseFrom(data);
        api.inventories.hatchery.updateHatchedEggs(hatchedEggs);
    }
    if (response.has(RequestType.GET_BUDDY_WALKED)) {
        ByteString data = response.get(RequestType.GET_BUDDY_WALKED);
        GetBuddyWalkedResponse buddyWalked = GetBuddyWalkedResponse.parseFrom(data);
        int candies = buddyWalked.getCandyEarnedCount();
        if (buddyWalked.getSuccess() && candies > 0) {
            List<PokemonListener> listeners = api.getListeners(PokemonListener.class);
            for (PokemonListener listener : listeners) {
                listener.onBuddyFindCandy(api, buddyWalked.getFamilyCandyId(), candies);
            }
        }
    }
    if (response.has(RequestType.GET_INCENSE_POKEMON)) {
        ByteString data = response.get(RequestType.GET_INCENSE_POKEMON);
        GetIncensePokemonResponse incense = GetIncensePokemonResponse.parseFrom(data);
        api.getMap().mapObjects.addIncensePokemon(incense);
    }
}
Also used : DownloadSettingsResponse(POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse) GetHatchedEggsResponse(POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse) GetBuddyWalkedResponse(POGOProtos.Networking.Responses.GetBuddyWalkedResponseOuterClass.GetBuddyWalkedResponse) ByteString(com.google.protobuf.ByteString) GetIncensePokemonResponse(POGOProtos.Networking.Responses.GetIncensePokemonResponseOuterClass.GetIncensePokemonResponse) CheckChallengeResponse(POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse) PokemonListener(com.pokegoapi.api.listener.PokemonListener) CheckAwardedBadgesResponse(POGOProtos.Networking.Responses.CheckAwardedBadgesResponseOuterClass.CheckAwardedBadgesResponse) GetHoloInventoryResponse(POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse)

Aggregations

PokemonListener (com.pokegoapi.api.listener.PokemonListener)2 CheckAwardedBadgesResponse (POGOProtos.Networking.Responses.CheckAwardedBadgesResponseOuterClass.CheckAwardedBadgesResponse)1 CheckChallengeResponse (POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse)1 DownloadSettingsResponse (POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse)1 GetBuddyWalkedResponse (POGOProtos.Networking.Responses.GetBuddyWalkedResponseOuterClass.GetBuddyWalkedResponse)1 GetHatchedEggsResponse (POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse)1 GetHoloInventoryResponse (POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse)1 GetIncensePokemonResponse (POGOProtos.Networking.Responses.GetIncensePokemonResponseOuterClass.GetIncensePokemonResponse)1 ByteString (com.google.protobuf.ByteString)1