Skip to content

Commit acfd75a

Browse files
committed
fix samples
1 parent 13f9dc5 commit acfd75a

15 files changed

+62
-62
lines changed

library/src/main/java/com/pokegoapi/api/gym/Battle.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class Battle {
5454
private final PokemonGo api;
5555

5656
@Getter
57-
private final Gym gym;
57+
public final Gym gym;
5858

5959
@Getter
6060
private Pokemon[] team;
@@ -70,7 +70,7 @@ public class Battle {
7070
private BattleState battleState;
7171

7272
@Getter
73-
private boolean active;
73+
public boolean active;
7474

7575
@Getter
7676
private long serverTimeOffset;
@@ -97,7 +97,7 @@ public int compare(ServerAction o1, ServerAction o2) {
9797
@Getter
9898
private BattlePokemon activeDefender;
9999
@Getter
100-
private BattlePokemon activeAttacker;
100+
public BattlePokemon activeAttacker;
101101

102102
@Getter
103103
private long startTime;
@@ -771,7 +771,7 @@ public long getTimeLeft() {
771771

772772
public class ServerAction {
773773
@Getter
774-
private final BattleActionType type;
774+
public final BattleActionType type;
775775
@Getter
776776
private final long start;
777777
@Getter
@@ -781,7 +781,7 @@ public class ServerAction {
781781
@Getter
782782
private final int energyDelta;
783783
@Getter
784-
private final int attackerIndex;
784+
public final int attackerIndex;
785785
@Getter
786786
private final int targetIndex;
787787
@Getter
@@ -864,15 +864,15 @@ public void setDamageWindow(int start, int end) {
864864

865865
public class BattlePokemon {
866866
@Getter
867-
private final PokemonData pokemon;
867+
public final PokemonData pokemon;
868868
@Setter
869869
@Getter
870870
private int health;
871871
@Getter
872872
private int maxHealth;
873873
@Setter
874874
@Getter
875-
private int energy;
875+
public int energy;
876876

877877
BattlePokemon(BattlePokemonInfo activePokemon) {
878878
this.health = activePokemon.getCurrentHealth();

library/src/main/java/com/pokegoapi/api/inventory/PokeBank.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
public class PokeBank {
4949
@Getter
50-
private final List<Pokemon> pokemons = Collections.synchronizedList(new ArrayList<Pokemon>());
50+
public final List<Pokemon> pokemons = Collections.synchronizedList(new ArrayList<Pokemon>());
5151
@Getter
5252
private final Object lock = new Object();
5353
@Getter

library/src/main/java/com/pokegoapi/api/map/MapObjects.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ public MapObjects(PokemonGo api) {
4848
}
4949

5050
@Getter
51-
private Set<NearbyPokemon> nearby = new HashSet<>();
51+
public Set<NearbyPokemon> nearby = new HashSet<>();
5252
private Set<CatchablePokemon> pokemon = new HashSet<>();
5353
@Getter
5454
private Set<Point> spawnpoints = new HashSet<>();
5555
@Getter
5656
private Set<Point> decimatedSpawnPoints = new HashSet<>();
5757
@Getter
58-
private Set<Pokestop> pokestops = new HashSet<>();
58+
public Set<Pokestop> pokestops = new HashSet<>();
5959
@Getter
60-
private Set<Gym> gyms = new HashSet<>();
60+
public Set<Gym> gyms = new HashSet<>();
6161
@Getter
6262
private Set<Raid> raids = new HashSet<>();
6363

library/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class CatchablePokemon implements MapPoint {
3939
@Getter
4040
public final long encounterId;
4141
@Getter
42-
private final PokemonId pokemonId;
42+
public final PokemonId pokemonId;
4343
@Getter
4444
private final int pokemonIdValue;
4545
@Getter

library/src/main/java/com/pokegoapi/api/map/pokemon/Encounter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public class Encounter {
3636
protected final CatchablePokemon pokemon;
3737

3838
@Getter
39-
protected CatchPokemonResponse.CatchStatus status = CatchStatus.UNRECOGNIZED;
39+
public CatchPokemonResponse.CatchStatus status = CatchStatus.UNRECOGNIZED;
4040

4141
@Getter
42-
protected EncounterResult encounterResult;
42+
public EncounterResult encounterResult;
4343

4444
protected ItemId activeItem;
4545

@@ -53,7 +53,7 @@ public class Encounter {
5353
protected CaptureReason captureReason;
5454

5555
@Getter
56-
protected long capturedPokemon;
56+
public long capturedPokemon;
5757

5858
@Getter
5959
protected PokemonData encounteredPokemon;

library/src/main/java/com/pokegoapi/auth/GoogleUserCredentialProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class GoogleUserCredentialProvider extends CredentialProvider {
5656
protected String tokenId;
5757

5858
@Getter
59-
protected String refreshToken;
59+
public String refreshToken;
6060

6161
protected AuthInfo.Builder authbuilder;
6262

library/src/main/java/com/pokegoapi/util/path/Path.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Path {
3030
@Getter
3131
private long totalTime;
3232
@Getter
33-
private boolean complete;
33+
public boolean complete;
3434

3535
/**
3636
* Creates a Path with the given positions

sample/src/main/java/com/pokegoapi/examples/CatchPokemonAtAreaExample.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public static void main(String[] args) {
8282
// Catch all pokemon in the current area
8383
catchArea(api);
8484

85-
MapObjects mapObjects = api.getMap().getMapObjects();
85+
MapObjects mapObjects = api.getMap().mapObjects;
8686
//Find all pokestops with pokemon nearby
8787
List<Pokestop> travelPokestops = new ArrayList<>();
88-
Set<NearbyPokemon> nearby = mapObjects.getNearby();
88+
Set<NearbyPokemon> nearby = mapObjects.nearby;
8989
for (NearbyPokemon nearbyPokemon : nearby) {
9090
String fortId = nearbyPokemon.getFortId();
9191
//Check if nearby pokemon is near a pokestop
@@ -102,8 +102,8 @@ public static void main(String[] args) {
102102
Collections.sort(travelPokestops, new Comparator<Pokestop>() {
103103
@Override
104104
public int compare(Pokestop primary, Pokestop secondary) {
105-
double lat = api.getLatitude();
106-
double lng = api.getLongitude();
105+
double lat = api.latitude;
106+
double lng = api.longitude;
107107
double distance1 = MapUtil.distFrom(primary.getLatitude(), primary.getLongitude(), lat, lng);
108108
double distance2 = MapUtil.distFrom(secondary.getLatitude(), secondary.getLongitude(), lat, lng);
109109
return Double.compare(distance1, distance2);
@@ -118,7 +118,7 @@ public int compare(Pokestop primary, Pokestop secondary) {
118118
System.out.println("Traveling to " + destination + " at 20KMPH!");
119119
path.start(api);
120120
try {
121-
while (!path.isComplete()) {
121+
while (!path.complete) {
122122
//Calculate the desired intermediate point for the current time
123123
Point point = path.calculateIntermediate(api);
124124
//Set the API location to that point
@@ -139,32 +139,32 @@ public int compare(Pokestop primary, Pokestop secondary) {
139139
}
140140

141141
private static void catchArea(PokemonGo api) throws RequestFailedException, NoSuchItemException {
142-
ItemBag bag = api.getInventories().getItemBag();
142+
ItemBag bag = api.inventories.itemBag;
143143
try {
144144
//Wait until map is updated for the current location
145145
api.getMap().awaitUpdate();
146146

147-
Set<CatchablePokemon> catchablePokemon = api.getMap().getMapObjects().getPokemon();
147+
Set<CatchablePokemon> catchablePokemon = api.getMap().mapObjects.getPokemon();
148148
System.out.println("Pokemon in area: " + catchablePokemon.size());
149149

150150
Random random = new Random();
151-
PokeBank pokebank = api.getInventories().getPokebank();
151+
PokeBank pokebank = api.inventories.pokebank;
152152

153153
for (CatchablePokemon cp : catchablePokemon) {
154154
// Encounter this pokemon
155155
Encounter encounter = cp.encounter();
156156

157157
// If the encounter was successful, attempt to catch this pokemon
158158
if (encounter.isSuccessful()) {
159-
System.out.println("Encountered: " + cp.getPokemonId());
159+
System.out.println("Encountered: " + cp.pokemonId);
160160

161161
List<Pokeball> usablePokeballs = bag.getUsablePokeballs();
162162

163163
if (usablePokeballs.size() > 0) {
164164
//Select pokeball with smart selector to print what pokeball is used
165165
double probability = encounter.getCaptureProbability();
166166
Pokeball pokeball = PokeballSelector.SMART.select(usablePokeballs, probability);
167-
System.out.println("Attempting to catch: " + cp.getPokemonId() + " with " + pokeball
167+
System.out.println("Attempting to catch: " + cp.pokemonId + " with " + pokeball
168168
+ " (" + probability + ")");
169169

170170
// Throw pokeballs until capture or flee
@@ -173,17 +173,17 @@ private static void catchArea(PokemonGo api) throws RequestFailedException, NoSu
173173
Thread.sleep(500 + random.nextInt(1000));
174174

175175
// If no item is active, use a razzberry
176-
int razzberryCount = bag.getItem(ItemId.ITEM_RAZZ_BERRY).getCount();
176+
int razzberryCount = bag.getItem(POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId.ITEM_RAZZ_BERRY).count;
177177
if (encounter.getActiveItem() == null && razzberryCount > 0) {
178178
encounter.useItem(ItemId.ITEM_RAZZ_BERRY);
179179
}
180180

181181
// Throw pokeball with random properties
182182
encounter.throwPokeball(PokeballSelector.SMART, ThrowProperties.random());
183183

184-
if (encounter.getStatus() == CatchStatus.CATCH_SUCCESS) {
184+
if (encounter.status == CatchStatus.CATCH_SUCCESS) {
185185
// Print pokemon stats
186-
Pokemon pokemon = pokebank.getPokemonById(encounter.getCapturedPokemon());
186+
Pokemon pokemon = pokebank.getPokemonById(encounter.capturedPokemon);
187187
if (pokemon != null) {
188188
double iv = pokemon.getIvInPercentage();
189189
int number = pokemon.getPokemonId().getNumber();
@@ -211,7 +211,7 @@ private static void catchArea(PokemonGo api) throws RequestFailedException, NoSu
211211
// Wait for animation before catching next pokemon
212212
Thread.sleep(3000 + random.nextInt(1000));
213213
} else {
214-
System.out.println("Failed to encounter pokemon: " + encounter.getEncounterResult());
214+
System.out.println("Failed to encounter pokemon: " + encounter.encounterResult);
215215
}
216216
}
217217
} catch (InterruptedException e) {

sample/src/main/java/com/pokegoapi/examples/CheckEvolutionExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void main(String[] args) {
4343
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
4444

4545
//Get the evolution meta from the item templates received from the game server
46-
Evolutions evolutionMeta = api.getItemTemplates().getEvolutions();
46+
Evolutions evolutionMeta = api.itemTemplates.evolutions;
4747

4848
System.out.println("Evolutions: ");
4949
for (PokemonId pokemon : PokemonId.values()) {

sample/src/main/java/com/pokegoapi/examples/FightGymExample.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void main(String[] args) {
7171
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
7272
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
7373

74-
List<Pokemon> pokemons = api.getInventories().getPokebank().getPokemons();
74+
List<Pokemon> pokemons = api.inventories.pokebank.pokemons;
7575

7676
//List to put all pokemon that can be used in a gym battle
7777
List<Pokemon> possiblePokemon = new ArrayList<>();
@@ -109,13 +109,13 @@ public int compare(Pokemon primary, Pokemon secondary) {
109109
}
110110

111111
//Sort from closest to farthest
112-
MapObjects mapObjects = api.getMap().getMapObjects();
113-
List<Gym> gyms = new ArrayList<>(mapObjects.getGyms());
112+
MapObjects mapObjects = api.getMap().mapObjects;
113+
List<Gym> gyms = new ArrayList<>(mapObjects.gyms);
114114
Collections.sort(gyms, new Comparator<Gym>() {
115115
@Override
116116
public int compare(Gym primary, Gym secondary) {
117-
double lat = api.getLatitude();
118-
double lng = api.getLongitude();
117+
double lat = api.latitude;
118+
double lng = api.longitude;
119119
double distance1 = MapUtil.distFrom(primary.getLatitude(), primary.getLongitude(), lat, lng);
120120
double distance2 = MapUtil.distFrom(secondary.getLatitude(), secondary.getLongitude(), lat, lng);
121121
return Double.compare(distance1, distance2);
@@ -124,14 +124,14 @@ public int compare(Gym primary, Gym secondary) {
124124

125125
for (Gym gym : gyms) {
126126
//Check if gym is attackable, and check if it is not owned by your team
127-
if (gym.isAttackable() && gym.getOwnedByTeam() != api.getPlayerProfile().getPlayerData().getTeam()) {
127+
if (gym.isAttackable() && gym.getOwnedByTeam() != api.playerProfile.getPlayerData().getTeam()) {
128128
//Walk to gym; Documented pathing in TravelToPokestopExample
129129
Point destination = new Point(gym.getLatitude(), gym.getLongitude());
130130
Path path = new Path(api.getPoint(), destination, 50.0);
131131
System.out.println("Traveling to " + destination + " at 50KMPH!");
132132
path.start(api);
133133
try {
134-
while (!path.isComplete()) {
134+
while (!path.complete) {
135135
Point point = path.calculateIntermediate(api);
136136
api.setLatitude(point.getLatitude());
137137
api.setLongitude(point.getLongitude());
@@ -149,7 +149,7 @@ public int compare(Gym primary, Gym secondary) {
149149

150150
//Start battle
151151
battle.start(new FightHandler(attackers));
152-
while (battle.isActive()) {
152+
while (battle.active) {
153153
handleAttack(api, battle);
154154
}
155155

@@ -162,10 +162,10 @@ public int compare(Gym primary, Gym secondary) {
162162
}
163163

164164
//If prestige reaches 0, deploy your pokemon
165-
if (battle.getGym().getPoints() <= 0) {
165+
if (battle.gym.getPoints() <= 0) {
166166
Pokemon best = possiblePokemon.get(0);
167167
System.out.println("Deploying " + best.getPokemonId() + " to gym.");
168-
battle.getGym().deployPokemon(best);
168+
battle.gym.deployPokemon(best);
169169
}
170170
}
171171
}
@@ -177,10 +177,10 @@ public int compare(Gym primary, Gym secondary) {
177177

178178
private static void handleAttack(PokemonGo api, Battle battle) throws InterruptedException {
179179
int duration;
180-
PokemonMove specialMove = battle.getActiveAttacker().getPokemon().getMove2();
181-
MoveSettings moveSettings = api.getItemTemplates().getMoveSettings(specialMove);
180+
PokemonMove specialMove = battle.activeAttacker.pokemon.getMove2();
181+
MoveSettings moveSettings = api.itemTemplates.getMoveSettings(specialMove);
182182
//Check if we have sufficient energy to perform a special attack
183-
int energy = battle.getActiveAttacker().getEnergy();
183+
int energy = battle.activeAttacker.energy;
184184
int desiredEnergy = -moveSettings.getEnergyDelta();
185185
if (energy <= desiredEnergy) {
186186
duration = battle.attack();
@@ -225,7 +225,7 @@ public Pokemon[] createTeam(PokemonGo api, Battle battle) {
225225
public void onStart(PokemonGo api, Battle battle, Result result) {
226226
System.out.println("Battle started with result: " + result);
227227
try {
228-
System.out.println("Defender count: " + battle.getGym().getDefendingPokemon().size());
228+
System.out.println("Defender count: " + battle.gym.getDefendingPokemon().size());
229229
} catch (Exception e) {
230230
e.printStackTrace();
231231
}
@@ -250,11 +250,11 @@ public void onTimedOut(PokemonGo api, Battle battle) {
250250
@Override
251251
public void onActionStart(PokemonGo api, Battle battle, Battle.ServerAction action) {
252252
//Dodge all special attacks
253-
if (action.getType() == BattleActionType.ACTION_SPECIAL_ATTACK) {
253+
if (action.type == BattleActionType.ACTION_SPECIAL_ATTACK) {
254254
System.out.println("Dodging special attack!");
255255
battle.dodge();
256256
}
257-
System.out.println(toIndexName(action) + " performed " + action.getType());
257+
System.out.println(toIndexName(action) + " performed " + action.type);
258258
}
259259

260260
@Override
@@ -283,17 +283,17 @@ public void onPlayerLeave(PokemonGo api, Battle battle, BattleParticipant left,
283283
public void onAttacked(PokemonGo api, Battle battle, Battle.BattlePokemon attacked,
284284
Battle.BattlePokemon attacker, int duration,
285285
long damageWindowStart, long damageWindowEnd, Battle.ServerAction action) {
286-
PokemonId attackedPokemon = attacked.getPokemon().getPokemonId();
287-
PokemonId attackerPokemon = attacker.getPokemon().getPokemonId();
286+
PokemonId attackedPokemon = attacked.pokemon.getPokemonId();
287+
PokemonId attackerPokemon = attacker.pokemon.getPokemonId();
288288
System.out.println(attackedPokemon + " attacked by " + attackerPokemon + " (" + toIndexName(action) + ")");
289289
}
290290

291291
@Override
292292
public void onAttackedSpecial(PokemonGo api, Battle battle, Battle.BattlePokemon attacked,
293293
Battle.BattlePokemon attacker, int duration,
294294
long damageWindowStart, long damageWindowEnd, Battle.ServerAction action) {
295-
PokemonId attackedPokemon = attacked.getPokemon().getPokemonId();
296-
PokemonId attackerPokemon = attacker.getPokemon().getPokemonId();
295+
PokemonId attackedPokemon = attacked.pokemon.getPokemonId();
296+
PokemonId attackerPokemon = attacker.pokemon.getPokemonId();
297297
System.out.println(attackedPokemon
298298
+ " attacked with special attack by " + attackerPokemon + " (" + toIndexName(action) + ")");
299299
}
@@ -321,12 +321,12 @@ public void onDefenderHealthUpdate(PokemonGo api, Battle battle, int lastHealth,
321321

322322
@Override
323323
public void onAttackerSwap(PokemonGo api, Battle battle, Battle.BattlePokemon newAttacker) {
324-
System.out.println("Attacker change: " + newAttacker.getPokemon().getPokemonId());
324+
System.out.println("Attacker change: " + newAttacker.pokemon.getPokemonId());
325325
}
326326

327327
@Override
328328
public void onDefenderSwap(PokemonGo api, Battle battle, Battle.BattlePokemon newDefender) {
329-
System.out.println("Defender change: " + newDefender.getPokemon().getPokemonId());
329+
System.out.println("Defender change: " + newDefender.pokemon.getPokemonId());
330330
}
331331

332332
@Override
@@ -349,7 +349,7 @@ public void onDodge(PokemonGo api, Battle battle, Battle.BattlePokemon pokemon,
349349
*/
350350
private String toIndexName(Battle.ServerAction action) {
351351
String name = "Attacker";
352-
if (action.getAttackerIndex() == -1) {
352+
if (action.attackerIndex == -1) {
353353
name = "Defender";
354354
}
355355
return name;

0 commit comments

Comments
 (0)