use of POGOProtos.Inventory.AppliedItemOuterClass.AppliedItem in project PokeGOAPI-Java by Grover-c13.
the class Inventories method updateInventories.
/**
* Updates the inventories with the latest data.
*
* @param response the get inventory response
*/
public void updateInventories(GetInventoryResponse response) {
lastInventoryUpdate = api.currentTimeMillis();
for (InventoryItemOuterClass.InventoryItem inventoryItem : response.getInventoryDelta().getInventoryItemsList()) {
InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData();
// hatchery
PokemonData pokemonData = itemData.getPokemonData();
if (pokemonData.getPokemonId() == PokemonId.MISSINGNO && pokemonData.getIsEgg()) {
hatchery.addEgg(new EggPokemon(pokemonData));
}
// pokebank
if (pokemonData.getPokemonId() != PokemonId.MISSINGNO) {
pokebank.addPokemon(new Pokemon(api, inventoryItem.getInventoryItemData().getPokemonData()));
}
// items
if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) {
ItemData item = itemData.getItem();
if (item.getCount() > 0) {
itemBag.addItem(new Item(api, item, itemBag));
}
}
// candyjar
if (itemData.getCandy().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED && itemData.getCandy().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) {
candyjar.setCandy(itemData.getCandy().getFamilyId(), itemData.getCandy().getCandy());
}
// player stats
if (itemData.hasPlayerStats()) {
api.getPlayerProfile().setStats(new Stats(itemData.getPlayerStats()));
}
// pokedex
if (itemData.hasPokedexEntry()) {
pokedex.add(itemData.getPokedexEntry());
}
if (itemData.hasEggIncubators()) {
EggIncubators eggIncubators = itemData.getEggIncubators();
for (EggIncubatorOuterClass.EggIncubator incubator : eggIncubators.getEggIncubatorList()) {
EggIncubator eggIncubator = new EggIncubator(api, incubator);
synchronized (this.lock) {
incubators.remove(eggIncubator);
incubators.add(eggIncubator);
}
}
}
if (itemData.hasAppliedItems()) {
AppliedItems appliedItems = itemData.getAppliedItems();
for (AppliedItem appliedItem : appliedItems.getItemList()) {
this.appliedItems.put(appliedItem.getItemId(), appliedItem);
}
}
Set<ItemId> stale = new HashSet<>();
for (Map.Entry<ItemId, AppliedItem> entry : appliedItems.entrySet()) {
ItemId itemId = entry.getKey();
AppliedItem applied = entry.getValue();
if (api.currentTimeMillis() >= applied.getExpireMs()) {
stale.add(itemId);
} else {
Item item = itemBag.getItem(itemId);
item.setApplied(applied);
itemBag.addItem(item);
}
}
for (ItemId item : stale) {
appliedItems.remove(item);
itemBag.getItem(item).removeApplied();
}
}
}
Aggregations