Skip to content

Commit

Permalink
Added ability for debug logging in classes with EasyRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed Apr 27, 2021
1 parent e6b54fd commit 83b5747
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourcewriters.minecraft</groupId>
<artifactId>vcompat</artifactId>
<version>2.1.6</version>
<version>2.1.7</version>
<name>vCompat</name>
<distributionManagement>
<repository>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@ public class Mojang {

private final PlayerProvider<?> playerProvider = VersionControl.get().getPlayerProvider();

private boolean debug = false;

public Mojang(ILogger logger, MojangProvider provider, SkinStore store) {
this.logger = logger;
this.provider = provider;
this.store = store;
}

public boolean debug() {
return debug;
}

public Mojang debug(boolean state) {
this.debug = state;
return this;
}

/*
* Getter
*/
Expand Down Expand Up @@ -138,6 +149,9 @@ public Skin getSkinFrom(URL url, SkinModel model) {
public Skin getSkinFrom(URL url, SkinModel model, int timeout) {
Profile profile = getUseableProfile();
if (profile == null || url == null || model == null) {
if (debug) {
logger.log(LogTypeId.DEBUG, "Smth is null (" + (profile == null) + "/" + (url == null) + "/" + (model == null) + ") o.0");
}
return null;
}
try {
Expand All @@ -161,6 +175,10 @@ public Skin getSkinFrom(URL url, SkinModel model, int timeout) {
request.data("url", url.toString()).data("model", model.toString());
EasyResponse response = request.run(String.format(URL_SKIN_UPLOAD, profile.getUniqueId()));
if (response.getCode() != ResponseCode.NO_CONTENT) {
if (debug) {
logger.log(LogTypeId.DEBUG, "Code: " + response.getCode() + " / Length: " + response.getData().length);
logger.log(LogTypeId.DEBUG, response.getDataAsJson().toPrettyString().split("\n"));
}
return null;
}
return apply(MojangProfileServer.getSkinShorten(profile.getUniqueId()));
Expand Down Expand Up @@ -195,6 +213,9 @@ public Skin getSkinFrom(String name, URL url, SkinModel model) {
public Skin getSkinFrom(String name, URL url, SkinModel model, int timeout) {
Profile profile = getUseableProfile();
if (profile == null || name != null || url == null || model == null) {
if (debug) {
logger.log(LogTypeId.DEBUG, "Smth is null (" + (profile == null) + "/" + (url == null) + "/" + (model == null) + ") o.0");
}
return null;
}
try {
Expand All @@ -218,6 +239,10 @@ public Skin getSkinFrom(String name, URL url, SkinModel model, int timeout) {
request.data("url", url.toString()).data("model", model.toString());
EasyResponse response = request.run(String.format(URL_SKIN_UPLOAD, profile.getUniqueId()), EasyUrlEncodedContent.URL_ENCODED);
if (response.getCode() != ResponseCode.NO_CONTENT) {
if (debug) {
logger.log(LogTypeId.DEBUG, "Code: " + response.getCode() + " / Length: " + response.getData().length);
logger.log(LogTypeId.DEBUG, response.getDataAsJson().toPrettyString().split("\n"));
}
return null;
}
return apply(MojangProfileServer.getSkinShorten(name, profile.getUniqueId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ public class Profile {

private String authToken;

private boolean debug = false;

public Profile(MojangProvider provider, String user, String pass) {
this.provider = provider;
this.username = user;
this.password = pass;
}

public boolean debug() {
return debug;
}

public Profile debug(boolean state) {
this.debug = state;
return this;
}

/*
*
*/
Expand Down Expand Up @@ -110,6 +121,9 @@ public Profile authenticate() {
object.set("clientToken", provider.getClientIdentifier().toString());
request.data(object);
JsonValue<?> responseRaw = request.run(String.format(AUTH_SERVER, "authenticate")).getDataAsJson();
if (debug) {
System.out.println(responseRaw.toPrettyString());
}
if (!responseRaw.hasType(ValueType.OBJECT)) {
return this;
}
Expand Down

0 comments on commit 83b5747

Please sign in to comment.