Search in sources :

Example 1 with PokestopListener

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

the class Pokestop method lootAsync.

/**
	 * Loots a pokestop for pokeballs and other items.
	 *
	 * @return PokestopLootResult
	 */
public Observable<PokestopLootResult> lootAsync() {
    FortSearchMessage searchMessage = FortSearchMessage.newBuilder().setFortId(getId()).setFortLatitude(getLatitude()).setFortLongitude(getLongitude()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_SEARCH, searchMessage);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, PokestopLootResult>() {

        @Override
        public PokestopLootResult call(ByteString result) {
            FortSearchResponseOuterClass.FortSearchResponse response;
            try {
                response = FortSearchResponseOuterClass.FortSearchResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            cooldownCompleteTimestampMs = response.getCooldownCompleteTimestampMs();
            PokestopLootResult lootResult = new PokestopLootResult(response);
            List<PokestopListener> listeners = api.getListeners(PokestopListener.class);
            for (PokestopListener listener : listeners) {
                // listener.onLoot(lootResult);
                // return the pokestop, also change in listener
                listener.onLoot(lootResult, Pokestop.this);
            }
            return lootResult;
        }
    });
}
Also used : PokestopListener(com.pokegoapi.api.listener.PokestopListener) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) List(java.util.List) FortSearchMessage(POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 2 with PokestopListener

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

the class Fort method lootAsync.

/**
 * Loots a pokestop for pokeballs and other items.
 *
 * @return PokestopLootResult
 */
public Observable<PokestopLootResult> lootAsync() {
    FortSearchMessage searchMessage = FortSearchMessage.newBuilder().setFortId(getId()).setFortLatitude(getLatitude()).setFortLongitude(getLongitude()).setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_SEARCH, searchMessage);
    return api.requestHandler.sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, PokestopLootResult>() {

        @Override
        public PokestopLootResult call(ByteString result) {
            FortSearchResponseOuterClass.FortSearchResponse response;
            try {
                response = FortSearchResponseOuterClass.FortSearchResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            cooldownCompleteTimestampMs = response.getCooldownCompleteTimestampMs();
            PokestopLootResult lootResult = new PokestopLootResult(response);
            List<PokestopListener> listeners = api.getListeners(PokestopListener.class);
            for (PokestopListener listener : listeners) {
                // listener.onLoot(lootResult);
                // return the pokestop, also change in listener
                listener.onLoot(lootResult, Fort.this);
            }
            return lootResult;
        }
    });
}
Also used : PokestopListener(com.pokegoapi.api.listener.PokestopListener) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ProtocolStringList(com.google.protobuf.ProtocolStringList) List(java.util.List) FortSearchMessage(POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

FortSearchMessage (POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage)2 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 PokestopListener (com.pokegoapi.api.listener.PokestopListener)2 ServerRequest (com.pokegoapi.main.ServerRequest)2 List (java.util.List)2 ProtocolStringList (com.google.protobuf.ProtocolStringList)1