From 995313a18abde56acd0c03a70111a64a9cfc7d3e Mon Sep 17 00:00:00 2001 From: Stud Date: Sun, 24 Jul 2016 09:27:50 +0200 Subject: [PATCH] Use a reset instead of using another instance --- .../java/com/pokegoapi/api/inventory/CandyJar.java | 4 ++++ .../java/com/pokegoapi/api/inventory/Hatchery.java | 8 ++++++-- .../java/com/pokegoapi/api/inventory/Inventories.java | 10 +++++----- src/main/java/com/pokegoapi/api/inventory/ItemBag.java | 4 ++++ .../java/com/pokegoapi/api/inventory/PokeBank.java | 8 ++++++-- src/main/java/com/pokegoapi/api/inventory/Pokedex.java | 10 +++++++--- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/inventory/CandyJar.java b/src/main/java/com/pokegoapi/api/inventory/CandyJar.java index beabe355..d18d600e 100644 --- a/src/main/java/com/pokegoapi/api/inventory/CandyJar.java +++ b/src/main/java/com/pokegoapi/api/inventory/CandyJar.java @@ -28,6 +28,10 @@ public class CandyJar { private HashMap candies; public CandyJar(PokemonGo pgo) { + reset(pgo); + } + + public void reset(PokemonGo pgo) { this.pgo = pgo; candies = new HashMap<>(); } diff --git a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java index 22b3cd89..eb36db13 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java +++ b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java @@ -31,8 +31,12 @@ public class Hatchery { @Getter PokemonGo instance; - public Hatchery(PokemonGo instance) { - this.instance = instance; + public Hatchery(PokemonGo pgo) { + reset(pgo); + } + + public void reset(PokemonGo pgo) { + this.instance = pgo; } public void addEgg(EggPokemon egg) { diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index 2918dee2..5929fe11 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -94,12 +94,12 @@ public void updateInventories() throws LoginFailedException, RemoteServerExcepti public void updateInventories(boolean forceUpdate) throws LoginFailedException, RemoteServerException { if (forceUpdate) { lastInventoryUpdate = 0; - itemBag = new ItemBag(api); - pokebank = new PokeBank(api); - candyjar = new CandyJar(api); - pokedex = new Pokedex(api); + itemBag.reset(api); + pokebank.reset(api); + candyjar.reset(api); + pokedex.reset(api); incubators = new ArrayList<>(); - hatchery = new Hatchery(api); + hatchery.reset(api); } GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder() .setLastTimestampMs(lastInventoryUpdate) diff --git a/src/main/java/com/pokegoapi/api/inventory/ItemBag.java b/src/main/java/com/pokegoapi/api/inventory/ItemBag.java index e36e3a25..bcfb1d6b 100644 --- a/src/main/java/com/pokegoapi/api/inventory/ItemBag.java +++ b/src/main/java/com/pokegoapi/api/inventory/ItemBag.java @@ -40,6 +40,10 @@ public class ItemBag { private HashMap items; public ItemBag(PokemonGo pgo) { + reset(pgo); + } + + public void reset(PokemonGo pgo) { this.pgo = pgo; items = new HashMap<>(); } diff --git a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java index 9f6989cb..2343b89c 100644 --- a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java +++ b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java @@ -33,8 +33,12 @@ public class PokeBank { @Getter PokemonGo instance; - public PokeBank(PokemonGo instance) { - this.instance = instance; + public PokeBank(PokemonGo pgo) { + reset(pgo); + } + + public void reset(PokemonGo pgo) { + this.instance = pgo; } /** diff --git a/src/main/java/com/pokegoapi/api/inventory/Pokedex.java b/src/main/java/com/pokegoapi/api/inventory/Pokedex.java index 8f342942..ca9c8320 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Pokedex.java +++ b/src/main/java/com/pokegoapi/api/inventory/Pokedex.java @@ -24,11 +24,15 @@ public class Pokedex { - private final PokemonGo api; + private PokemonGo api; private Map pokedexMap = new HashMap(); - public Pokedex(PokemonGo api) { - this.api = api; + public Pokedex(PokemonGo pgo) { + reset(pgo); + } + + public void reset(PokemonGo pgo) { + this.api = pgo; } /**