Skip to content

Commit 8b10484

Browse files
committed
fix clonflict with master
2 parents dd5d90c + 1075334 commit 8b10484

File tree

11 files changed

+267
-15
lines changed

11 files changed

+267
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ EG:
4545
OkHttpClient httpClient = new OkHttpClient();
4646
AuthInfo auth = new GoogleLogin(httpClient).login("token");
4747
PokemonGo go = new PokemonGo(auth,httpClient);
48-
System.out.println(go.getPlayerProfile());
48+
Log.v(go.getPlayerProfile());
4949
```
5050

5151
## Contributing

src/main/java/com/pokegoapi/api/PokemonGo.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
import com.pokegoapi.exceptions.RemoteServerException;
2828
import com.pokegoapi.main.RequestHandler;
2929
import com.pokegoapi.main.ServerRequest;
30+
import com.pokegoapi.util.Log;
3031
import lombok.Getter;
3132
import lombok.Setter;
3233
import okhttp3.OkHttpClient;
3334

3435
public class PokemonGo {
3536

37+
private static final java.lang.String TAG = PokemonGo.class.getSimpleName();
3638
@Getter
3739
RequestHandler requestHandler;
3840
@Getter
@@ -136,7 +138,7 @@ public PlayerProfile getPlayerProfile(boolean forceUpdate) {
136138
try {
137139
localPlayer = getPlayerAndUpdateInventory(tempProfile);
138140
} catch (LoginFailedException | RemoteServerException e) {
139-
e.printStackTrace();
141+
Log.e(TAG, "Failed to get profile data and update inventory", e);
140142
}
141143

142144
if (localPlayer == null) {
@@ -159,7 +161,9 @@ public PlayerProfile getPlayerProfile(boolean forceUpdate) {
159161
for (CurrencyOuterClass.Currency currency : localPlayer.getCurrenciesList()) {
160162
try {
161163
playerProfile.addCurrency(currency.getName(), currency.getAmount());
162-
} catch (InvalidCurrencyException e) { }
164+
} catch (InvalidCurrencyException e) {
165+
Log.w(TAG, "Error adding currency. You can probably ignore this.", e);
166+
}
163167
}
164168

165169
avatarAPI.setGender(localPlayer.getAvatar().getGender());

src/main/java/com/pokegoapi/api/map/Pokemon/CatchablePokemon.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import com.pokegoapi.api.map.Map;
1010
import com.pokegoapi.exceptions.LoginFailedException;
1111
import com.pokegoapi.exceptions.RemoteServerException;
12+
import com.pokegoapi.util.Log;
1213
import lombok.ToString;
1314

1415
@ToString
1516
public class CatchablePokemon {
17+
private static final String TAG = CatchablePokemon.class.getSimpleName();
1618
private MapPokemon proto;
1719
private Map map;
1820

@@ -54,7 +56,7 @@ public CatchResult catchPokemon(Pokeball balltype) throws LoginFailedException,
5456

5557
// encounter
5658
EncounterResponse encounterResponse = map.encounterPokemon(proto);
57-
System.out.println(encounterResponse);
59+
Log.i(TAG, "Encounter Response: " + encounterResponse.toString());
5860
CatchResult cresult;
5961
if (encounterResponse.getStatus() == EncounterResponse.Status.ENCOUNTER_SUCCESS)
6062
{

src/main/java/com/pokegoapi/api/pokemon/Pokemon.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import com.pokegoapi.exceptions.LoginFailedException;
1717
import com.pokegoapi.exceptions.RemoteServerException;
1818
import com.pokegoapi.main.ServerRequest;
19+
import com.pokegoapi.util.Log;
1920
import lombok.Setter;
2021

2122
public class Pokemon {
2223

24+
private static final String TAG = Pokemon.class.getSimpleName();
2325
@Setter
2426
PokemonGo pgo;
2527
private PokemonData proto;
@@ -202,6 +204,6 @@ public boolean getFromFort() {
202204
}
203205

204206
public void debug() {
205-
System.out.println(proto);
207+
Log.d(TAG, proto.toString());
206208
}
207209
}

src/main/java/com/pokegoapi/auth/GoogleLogin.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.gson.Gson;
55
import com.google.gson.GsonBuilder;
66
import com.pokegoapi.exceptions.LoginFailedException;
7+
import com.pokegoapi.util.Log;
78
import okhttp3.*;
89

910
import java.io.IOException;
@@ -14,6 +15,7 @@ public class GoogleLogin extends Login {
1415
public static final String CLIENT_ID = "848232511240-73ri3t7plvk96pj4f85uj8otdat2alem.apps.googleusercontent.com";
1516
public static final String OAUTH_ENDPOINT = "https://accounts.google.com/o/oauth2/device/code";
1617
public static final String OAUTH_TOKEN_ENDPOINT = "https://www.googleapis.com/oauth2/v4/token";
18+
private static final String TAG = GoogleLogin.class.getSimpleName();
1719

1820
private final OkHttpClient client;
1921

@@ -62,14 +64,15 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept
6264
Gson gson = new GsonBuilder().create();
6365

6466
GoogleAuthJson googleAuth = gson.fromJson(response.body().string(), GoogleAuthJson.class);
65-
System.out.println("Get user to go to:" + googleAuth.getVerification_url() + " and enter code:" + googleAuth.getUser_code());
67+
Log.d(TAG, "Get user to go to:" + googleAuth.getVerification_url() + " and enter code:" + googleAuth.getUser_code());
6668

6769
GoogleAuthTokenJson token;
6870
while ((token = poll(googleAuth)) == null) {
6971
Thread.sleep(googleAuth.getInterval() * 1000);
7072
}
7173

72-
System.out.println("Got token:" + token.getId_token());
74+
75+
Log.d(TAG, "Got token: " + token.getId_token());
7376

7477
AuthInfo.Builder authbuilder = AuthInfo.newBuilder();
7578
authbuilder.setProvider("google");

src/main/java/com/pokegoapi/examples/TransferOnePidgeyExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.pokegoapi.auth.GoogleLogin;
99
import com.pokegoapi.exceptions.LoginFailedException;
1010
import com.pokegoapi.exceptions.RemoteServerException;
11+
import com.pokegoapi.util.Log;
1112
import okhttp3.OkHttpClient;
1213

1314
import java.util.List;
@@ -30,15 +31,15 @@ public static void main(String[] args) {
3031
pest.debug();
3132
ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result result = pest.transferPokemon();
3233

33-
System.out.println("Transfered Pidgey result:" + result);
34+
Log.i("Main", "Transfered Pidgey result:" + result);
3435
} else {
35-
System.out.println("You have no pidgeys :O");
36+
Log.i("Main", "You have no pidgeys :O");
3637
}
3738

3839

3940
} catch (LoginFailedException | RemoteServerException e) {
4041
// failed to login, invalid credentials, auth issue or server issue.
41-
e.printStackTrace();
42+
Log.e("Main", "Failed to login. Invalid credentials or server issue: ", e);
4243
}
4344
}
4445
}

src/main/java/com/pokegoapi/google/common/geometry/S2Polyline.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919

2020

21+
import com.pokegoapi.util.Log;
22+
2123
import java.util.Arrays;
2224
import java.util.List;
23-
import java.util.logging.Logger;
2425

2526
/**
2627
* An S2Polyline represents a sequence of zero or more vertices connected by
@@ -33,7 +34,7 @@
3334
*
3435
*/
3536
public final strictfp class S2Polyline implements S2Region {
36-
private static final Logger log = Logger.getLogger(S2Polyline.class.getCanonicalName());
37+
public static final String TAG = S2Polyline.class.getSimpleName();
3738

3839
private final int numVertices;
3940
private final S2Point[] vertices;
@@ -67,7 +68,7 @@ public boolean isValid(List<S2Point> vertices) {
6768
int n = vertices.size();
6869
for (int i = 0; i < n; ++i) {
6970
if (!S2.isUnitLength(vertices.get(i))) {
70-
log.info("Vertex " + i + " is not unit length");
71+
Log.i(TAG, "Vertex " + i + " is not unit length");
7172
return false;
7273
}
7374
}
@@ -76,7 +77,7 @@ public boolean isValid(List<S2Point> vertices) {
7677
for (int i = 1; i < n; ++i) {
7778
if (vertices.get(i - 1).equals(vertices.get(i))
7879
|| vertices.get(i - 1).equals(S2Point.neg(vertices.get(i)))) {
79-
log.info("Vertices " + (i - 1) + " and " + i + " are identical or antipodal");
80+
Log.i(TAG, "Vertices " + (i - 1) + " and " + i + " are identical or antipodal");
8081
return false;
8182
}
8283
}

src/main/java/com/pokegoapi/main/RequestHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.pokegoapi.api.PokemonGo;
88
import com.pokegoapi.exceptions.LoginFailedException;
99
import com.pokegoapi.exceptions.RemoteServerException;
10+
import com.pokegoapi.util.Log;
1011
import okhttp3.OkHttpClient;
1112
import okhttp3.RequestBody;
1213
import okhttp3.Response;
@@ -18,6 +19,7 @@
1819
import java.util.List;
1920

2021
public class RequestHandler {
22+
private static final String TAG = RequestHandler.class.getSimpleName();
2123
private final PokemonGo api;
2224
private RequestEnvelopeOuterClass.RequestEnvelope.Builder builder;
2325
private boolean hasRequests;
@@ -53,7 +55,7 @@ public void sendServerRequests() throws RemoteServerException, LoginFailedExcept
5355
try {
5456
request.writeTo(stream);
5557
} catch (IOException e) {
56-
System.err.println("Should never happen");
58+
Log.wtf(TAG, "Failed to write request to bytearray ouput stream. This should never happen", e);
5759
}
5860

5961
RequestBody body = RequestBody.create(null, stream.toByteArray());
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.pokegoapi.util;
2+
3+
import com.pokegoapi.util.Log.Level;
4+
5+
import static com.pokegoapi.util.Log.Level.*;
6+
7+
/**
8+
* Created by Will on 7/20/16.
9+
*/
10+
public abstract class BaseLogger implements Logger{
11+
12+
@Override
13+
public void v(String tag, String msg) {
14+
log(VERBOSE, tag, msg, null);
15+
}
16+
17+
@Override
18+
public void v(String tag, String msg, Throwable t) {
19+
log(VERBOSE, tag, msg, t);
20+
}
21+
22+
@Override
23+
public void d(String tag, String msg) {
24+
log(DEBUG, tag, msg, null);
25+
}
26+
27+
@Override
28+
public void d(String tag, String msg, Throwable tr) {
29+
log(DEBUG, tag, msg, tr);
30+
}
31+
32+
@Override
33+
public void i(String tag, String msg) {
34+
log(INFO, tag, msg, null);
35+
}
36+
37+
@Override
38+
public void i(String tag, String msg, Throwable tr) {
39+
log(INFO, tag, msg, tr);
40+
}
41+
42+
@Override
43+
public void w(String tag, String msg) {
44+
log(WARN, tag, msg, null);
45+
}
46+
47+
@Override
48+
public void w(String tag, String msg, Throwable tr) {
49+
log(WARN, tag, msg, tr);
50+
}
51+
52+
@Override
53+
public void w(String tag, Throwable tr) {
54+
log(WARN, tag, null, tr);
55+
}
56+
57+
@Override
58+
public void e(String tag, String msg) {
59+
log(ERROR, tag, msg, null);
60+
}
61+
62+
@Override
63+
public void e(String tag, String msg, Throwable tr) {
64+
log(ERROR, tag, msg, tr);
65+
}
66+
67+
@Override
68+
public void wtf(String tag, String msg) {
69+
log(ASSERT, tag, msg, null);
70+
}
71+
72+
@Override
73+
public void wtf(String tag, Throwable tr) {
74+
log(ASSERT, tag, null, tr);
75+
}
76+
77+
@Override
78+
public void wtf(String tag, String msg, Throwable tr) {
79+
log(ASSERT, tag, msg, tr);
80+
}
81+
82+
public abstract void log(Level level, String tag, String msg, Throwable tr);
83+
}

0 commit comments

Comments
 (0)