use of com.pokegoapi.api.pokemon.Buddy in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method updateProfile.
/**
* Update the profile with the given player data
*
* @param playerData the data for update
*/
public void updateProfile(PlayerData playerData) {
this.playerData = playerData;
avatar = new PlayerAvatar(playerData.getAvatar());
dailyBonus = new DailyBonus(playerData.getDailyBonus());
contactSettings = new ContactSettings(playerData.getContactSettings());
// maybe something more graceful?
for (CurrencyOuterClass.Currency currency : playerData.getCurrenciesList()) {
try {
addCurrency(currency.getName(), currency.getAmount());
} catch (InvalidCurrencyException e) {
Log.w(TAG, "Error adding currency. You can probably ignore this.", e);
}
}
// Tutorial state
tutorialState = new TutorialState(playerData.getTutorialStateList());
if (playerData.hasBuddyPokemon() && playerData.getBuddyPokemon().getId() != 0) {
buddy = new Buddy(api, playerData.getBuddyPokemon());
} else {
buddy = null;
}
}
use of com.pokegoapi.api.pokemon.Buddy in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method setBuddy.
/**
* Sets the current buddy
*
* @param pokemon the pokemon to set as your buddy
* @return if this task was successfull
* @throws RequestFailedException if an exception occurred while sending requests
*/
public boolean setBuddy(Pokemon pokemon) throws RequestFailedException {
SetBuddyPokemonMessageOuterClass.SetBuddyPokemonMessage message = SetBuddyPokemonMessageOuterClass.SetBuddyPokemonMessage.newBuilder().setPokemonId(pokemon.getId()).build();
ServerRequest request = new ServerRequest(RequestType.SET_BUDDY_POKEMON, message);
api.getRequestHandler().sendServerRequests(request);
try {
SetBuddyPokemonResponse response = SetBuddyPokemonResponse.parseFrom(request.getData());
buddy = new Buddy(api, response.getUpdatedBuddy());
return response.hasUpdatedBuddy();
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations