use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Pokemon method renamePokemon.
/**
* Rename pokemon nickname pokemon response . result.
*
* @param nickname the nickname
* @return the nickname pokemon response . result
* @throws RequestFailedException if an exception occurred while sending requests
*/
public NicknamePokemonResponse.Result renamePokemon(String nickname) throws RequestFailedException {
NicknamePokemonMessage reqMsg = NicknamePokemonMessage.newBuilder().setPokemonId(getId()).setNickname(nickname).build();
ServerRequest serverRequest = new ServerRequest(RequestType.NICKNAME_POKEMON, reqMsg);
api.getRequestHandler().sendServerRequests(serverRequest, true);
NicknamePokemonResponse response;
try {
response = NicknamePokemonResponse.parseFrom(serverRequest.getData());
if (response.getResult() == NicknamePokemonResponse.Result.SUCCESS) {
this.nickname = nickname;
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
api.getInventories().getPokebank().removePokemon(this);
return response.getResult();
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Map method requestMapObjects.
/**
* Requests and returns MapObjects from the server.
*
* @return the returned MapObjects
* @throws RequestFailedException if an exception occurred while sending requests
*/
protected MapObjects requestMapObjects() throws RequestFailedException {
List<Long> cells = getDefaultCells();
GetMapObjectsMessage.Builder builder = GetMapObjectsMessage.newBuilder();
builder.setLatitude(api.getLatitude());
builder.setLongitude(api.getLongitude());
for (Long cell : cells) {
builder.addCellId(cell);
builder.addSinceTimestampMs(0);
}
ServerRequest request = new ServerRequest(RequestType.GET_MAP_OBJECTS, builder.build());
api.getRequestHandler().sendServerRequests(request, true);
try {
GetMapObjectsResponse response = GetMapObjectsResponse.parseFrom(request.getData());
MapObjects mapObjects = new MapObjects(api);
for (MapCell cell : response.getMapCellsList()) {
mapObjects.addCell(cell);
}
return mapObjects;
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Pokestop method getDetailsAsync.
/**
* Get more detailed information about a pokestop.
*
* @return FortDetails
*/
public Observable<FortDetails> getDetailsAsync() {
FortDetailsMessage reqMsg = FortDetailsMessage.newBuilder().setFortId(getId()).setLatitude(getLatitude()).setLongitude(getLongitude()).build();
ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_DETAILS, reqMsg);
return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, FortDetails>() {
@Override
public FortDetails call(ByteString result) {
FortDetailsResponseOuterClass.FortDetailsResponse response = null;
try {
response = FortDetailsResponseOuterClass.FortDetailsResponse.parseFrom(result);
} catch (InvalidProtocolBufferException e) {
throw Exceptions.propagate(e);
}
return new FortDetails(response);
}
});
}
use of com.pokegoapi.main.ServerRequest 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;
}
});
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Pokestop method addModifierAsync.
/**
* Adds a modifier to this pokestop. (i.e. add a lure module)
*
* @param item the modifier to add to this pokestop
* @return true if success
*/
public Observable<Boolean> addModifierAsync(ItemId item) {
AddFortModifierMessage msg = AddFortModifierMessage.newBuilder().setModifierType(item).setFortId(getId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ADD_FORT_MODIFIER, msg);
return api.getRequestHandler().sendAsyncServerRequests(serverRequest).map(new Func1<ByteString, Boolean>() {
@Override
public Boolean call(ByteString result) {
try {
//sadly the server response does not contain any information to verify if the request was
// successful
AddFortModifierResponseOuterClass.AddFortModifierResponse.parseFrom(result);
} catch (InvalidProtocolBufferException e) {
throw Exceptions.propagate(e);
}
return Boolean.TRUE;
}
});
}
Aggregations