use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method markTutorial.
private void markTutorial(TutorialStateOuterClass.TutorialState state) throws RequestFailedException {
final MarkTutorialCompleteMessage tutorialMessage = MarkTutorialCompleteMessage.newBuilder().addTutorialsCompleted(state).setSendMarketingEmails(false).setSendPushNotifications(false).build();
ServerRequest request = new ServerRequest(RequestType.MARK_TUTORIAL_COMPLETE, tutorialMessage);
api.getRequestHandler().sendServerRequests(request);
try {
playerData = MarkTutorialCompleteResponse.parseFrom(request.getData()).getPlayerData();
updateProfile(playerData);
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method getProfile.
/**
* Performs a GET_PLAYER_PROFILE request.
*
* @throws RequestFailedException if an exception occurred while sending requests
*/
public void getProfile() throws RequestFailedException {
GetPlayerProfileMessage profileMessage = GetPlayerProfileMessage.newBuilder().setPlayerName("").build();
ServerRequest profileRequest = new ServerRequest(RequestType.GET_PLAYER_PROFILE, profileMessage);
api.getRequestHandler().sendServerRequests(profileRequest, true);
try {
GetPlayerProfileResponse response = GetPlayerProfileResponse.parseFrom(profileRequest.getData());
if (response.getResult() == GetPlayerProfileResponse.Result.SUCCESS) {
medals.clear();
List<PlayerBadge> badges = response.getBadgesList();
for (PlayerBadge badge : badges) {
medals.put(badge.getBadgeType(), new Medal(badge));
}
this.startTime = response.getStartTime();
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method checkAndEquipBadges.
/**
* Check and equip badges.
*
* @throws RequestFailedException if an exception occurred while sending requests
* @deprecated use getMedals, which uses common requests to check for badges
*/
@Deprecated
public void checkAndEquipBadges() throws RequestFailedException {
CheckAwardedBadgesMessage msg = CheckAwardedBadgesMessage.newBuilder().build();
ServerRequest serverRequest = new ServerRequest(RequestType.CHECK_AWARDED_BADGES, msg);
api.getRequestHandler().sendServerRequests(serverRequest);
CheckAwardedBadgesResponse response;
try {
response = CheckAwardedBadgesResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
this.updateAwardedMedals(response);
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Pokemon method setFavoritePokemon.
/**
* Function to mark the pokemon as favorite or not.
*
* @param markFavorite Mark Pokemon as Favorite?
* @return the SetFavoritePokemonResponse.Result
* @throws RequestFailedException if an exception occurred while sending requests
*/
public SetFavoritePokemonResponse.Result setFavoritePokemon(boolean markFavorite) throws RequestFailedException {
SetFavoritePokemonMessage reqMsg = SetFavoritePokemonMessage.newBuilder().setPokemonId(getId()).setIsFavorite(markFavorite).build();
ServerRequest serverRequest = new ServerRequest(RequestType.SET_FAVORITE_POKEMON, reqMsg);
api.getRequestHandler().sendServerRequests(serverRequest, true);
SetFavoritePokemonResponse response;
try {
response = SetFavoritePokemonResponse.parseFrom(serverRequest.getData());
if (response.getResult() == SetFavoritePokemonResponse.Result.SUCCESS) {
favorite = markFavorite ? 1 : 0;
}
} 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 Pokemon method useRevive.
/**
* Use a revive item on the pokemon. Will check if there is enough revive & if the pokemon need
* to be revived.
*
* @param itemId {@link ItemId} of the Revive to use.
* @return Result, ERROR_CANNOT_USE if the requirements aren't met
* @throws RequestFailedException if an exception occurred while sending requests
*/
public UseItemReviveResponse.Result useRevive(ItemId itemId) throws RequestFailedException {
Item item = api.getInventories().getItemBag().getItem(itemId);
if (!item.isRevive() || item.getCount() < 1 || !isFainted())
return UseItemReviveResponse.Result.ERROR_CANNOT_USE;
UseItemReviveMessage reqMsg = UseItemReviveMessage.newBuilder().setItemId(itemId).setPokemonId(getId()).build();
ServerRequest serverRequest = new ServerRequest(RequestType.USE_ITEM_REVIVE, reqMsg);
api.getRequestHandler().sendServerRequests(serverRequest, true);
UseItemReviveResponse response;
try {
response = UseItemReviveResponse.parseFrom(serverRequest.getData());
if (response.getResult() == UseItemReviveResponse.Result.SUCCESS) {
item.setCount(item.getCount() - 1);
setStamina(response.getStamina());
}
return response.getResult();
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations