Skip to content

Commit d635044

Browse files
authored
Fix import.*, fix other checkstyle stuff, fix NPE when getting stats (#401)
1 parent 3ace44a commit d635044

File tree

11 files changed

+1512
-1660
lines changed

11 files changed

+1512
-1660
lines changed

src/main/java/com/pokegoapi/api/inventory/EggIncubator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public double getKmWalked() {
123123
*
124124
* @return currently used or not
125125
*/
126-
public boolean isInUse() {
126+
public boolean isInUse() throws LoginFailedException, RemoteServerException {
127127
return getKmTarget() > pgo.getPlayerProfile().getStats().getKmWalked();
128128
}
129129
}

src/main/java/com/pokegoapi/api/inventory/Inventories.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException,
145145
}
146146
// player stats
147147
if (itemData.hasPlayerStats()) {
148-
api.getPlayerProfile().setStats(itemData.getPlayerStats());
148+
api.getPlayerProfile().setStats(new Stats(itemData.getPlayerStats()));
149149
}
150150

151151
// pokedex

src/main/java/com/pokegoapi/api/inventory/ItemBag.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public Collection<Item> getItems() {
121121
* Get used space inside of player inventory.
122122
*
123123
* @return used space
124+
* @throws RemoteServerException
125+
* the remote server exception
126+
* @throws LoginFailedException
127+
* the login failed exception
124128
*/
125129
public int getItemsCount() {
126130
int ct = 0;
@@ -130,6 +134,14 @@ public int getItemsCount() {
130134
return ct;
131135
}
132136

137+
/**
138+
* use an item with itemID
139+
* @param type type of item
140+
* @throws RemoteServerException
141+
* the remote server exception
142+
* @throws LoginFailedException
143+
* the login failed exception
144+
*/
133145
public void useItem(ItemId type) throws RemoteServerException, LoginFailedException {
134146
if (type == ItemId.UNRECOGNIZED) {
135147
throw new IllegalArgumentException("You cannot use item for UNRECOGNIZED");
@@ -147,6 +159,10 @@ public void useItem(ItemId type) throws RemoteServerException, LoginFailedExcept
147159
}
148160
}
149161

162+
/**
163+
* use an incense
164+
* @param type type of item
165+
*/
150166
public void useIncense(ItemId type) throws RemoteServerException, LoginFailedException {
151167
UseIncenseMessage useIncenseMessage =
152168
UseIncenseMessage.newBuilder()
@@ -166,7 +182,10 @@ public void useIncense(ItemId type) throws RemoteServerException, LoginFailedExc
166182
throw new RemoteServerException(e);
167183
}
168184
}
169-
185+
186+
/**
187+
* use an item with itemID
188+
*/
170189
public void useIncense() throws RemoteServerException, LoginFailedException {
171190
useIncense(ItemId.ITEM_INCENSE_ORDINARY);
172191
}

src/main/java/com/pokegoapi/api/inventory/Stats.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,102 @@
1515

1616
package com.pokegoapi.api.inventory;
1717

18+
import POGOProtos.Data.Player.PlayerStatsOuterClass;
19+
import lombok.Getter;
20+
1821
public class Stats {
22+
@Getter
23+
private PlayerStatsOuterClass.PlayerStats proto;
24+
25+
public Stats(PlayerStatsOuterClass.PlayerStats proto) {
26+
this.proto = proto;
27+
}
28+
29+
public int getLevel() {
30+
return proto.getLevel();
31+
}
32+
33+
public long getExperience() {
34+
return proto.getExperience();
35+
}
36+
37+
public long getPrevLevelXp() {
38+
return proto.getPrevLevelXp();
39+
}
40+
41+
public long getNextLevelXp() {
42+
return proto.getNextLevelXp();
43+
}
44+
45+
public float getKmWalked() {
46+
return proto.getKmWalked();
47+
}
48+
49+
public int getPokemonsEncountered() {
50+
return proto.getPokemonsEncountered();
51+
}
52+
53+
public int getUniquePokedexEntries() {
54+
return proto.getUniquePokedexEntries();
55+
}
56+
57+
public int getPokemonsCaptured() {
58+
return proto.getPokemonsCaptured();
59+
}
60+
61+
public int getEvolutions() {
62+
return proto.getEvolutions();
63+
}
64+
65+
public int getPokeStopVisits() {
66+
return proto.getPokeStopVisits();
67+
}
68+
69+
public int getPokeballsThrown() {
70+
return proto.getPokeballsThrown();
71+
}
72+
73+
public int getEggsHatched() {
74+
return proto.getEggsHatched();
75+
}
76+
77+
public int getBigMagikarpCaught() {
78+
return proto.getBigMagikarpCaught();
79+
}
80+
81+
public int getBattleAttackWon() {
82+
return proto.getBattleAttackWon();
83+
}
84+
85+
public int getBattleAttackTotal() {
86+
return proto.getBattleAttackTotal();
87+
}
88+
89+
public int getBattleDefendedWon() {
90+
return proto.getBattleDefendedWon();
91+
}
92+
93+
public int getBattleTrainingWon() {
94+
return proto.getBattleTrainingWon();
95+
}
96+
97+
public int getBattleTrainingTotal() {
98+
return proto.getBattleTrainingTotal();
99+
}
100+
101+
public int getPrestigeRaisedTotal() {
102+
return proto.getPrestigeRaisedTotal();
103+
}
104+
105+
public int getPrestigeDroppedTotal() {
106+
return proto.getPrestigeDroppedTotal();
107+
}
108+
109+
public int getPokemonDeployed() {
110+
return proto.getPokemonDeployed();
111+
}
19112

113+
public int getSmallRattataCaught() {
114+
return proto.getSmallRattataCaught();
115+
}
20116
}

src/main/java/com/pokegoapi/api/player/PlayerProfile.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
import com.pokegoapi.api.PokemonGo;
3434
import com.pokegoapi.api.inventory.Item;
3535
import com.pokegoapi.api.inventory.ItemBag;
36+
import com.pokegoapi.api.inventory.Stats;
3637
import com.pokegoapi.exceptions.InvalidCurrencyException;
3738
import com.pokegoapi.exceptions.LoginFailedException;
3839
import com.pokegoapi.exceptions.RemoteServerException;
3940
import com.pokegoapi.main.ServerRequest;
4041
import com.pokegoapi.util.Log;
41-
import lombok.Getter;
4242
import lombok.Setter;
4343

4444
import java.util.HashMap;
@@ -54,9 +54,9 @@ public class PlayerProfile {
5454
private DailyBonus dailyBonus;
5555
private ContactSettings contactSettings;
5656
private Map<Currency, Integer> currencies = new HashMap<Currency, Integer>();
57-
@Getter
5857
@Setter
59-
private PlayerStatsOuterClass.PlayerStats stats;
58+
private Stats stats;
59+
6060
private boolean init;
6161

6262
public PlayerProfile(PokemonGo api) throws LoginFailedException, RemoteServerException {
@@ -288,4 +288,21 @@ public Map<Currency, Integer> getCurrencies()
288288
}
289289
return currencies;
290290
}
291+
292+
293+
294+
/**
295+
* Gets player stats
296+
*
297+
* @return stats API objet
298+
* @throws LoginFailedException when the auth is invalid
299+
* @throws RemoteServerException when the server is down/having issues
300+
*/
301+
public Stats getStats()
302+
throws LoginFailedException, RemoteServerException {
303+
if (stats == null) {
304+
api.getInventories().updateInventories();
305+
}
306+
return stats;
307+
}
291308
}

0 commit comments

Comments
 (0)