Skip to content

Commit

Permalink
Fix edge-case where Texture#toString has a NullPointer, fix join requ…
Browse files Browse the repository at this point in the history
…ests (#838)

* Fix edge-case where Texture#toString has a NullPointer because gson set a null metadata

Also changes NORMAL name to WIDE since that's the accurate name.

* Fix join requests

Fixes #837
  • Loading branch information
AlexProgrammerDE authored Jul 18, 2024
1 parent 86903ec commit 05a699d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -371,7 +370,7 @@ public enum TextureType {
* The model used for a profile texture.
*/
public enum TextureModel {
NORMAL,
WIDE,
SLIM;
}

Expand All @@ -390,7 +389,7 @@ public static class Texture {
*/
public Texture(String url, Map<String, String> metadata) {
this.url = url;
this.metadata = new HashMap<>(metadata);
this.metadata = metadata;
}

/**
Expand All @@ -408,6 +407,10 @@ public String getURL() {
* @return The metadata value corresponding to the given key.
*/
public String getMetadata(String key) {
if (this.metadata == null) {
return null;
}

return this.metadata.get(key);
}

Expand All @@ -418,7 +421,7 @@ public String getMetadata(String key) {
*/
public TextureModel getModel() {
String model = this.getMetadata("model");
return model != null && model.equals("slim") ? TextureModel.SLIM : TextureModel.NORMAL;
return model != null && model.equals("slim") ? TextureModel.SLIM : TextureModel.WIDE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public static <T> T makeRequest(@Nullable ProxyInfo proxy, URI uri, Object input
throw new IllegalArgumentException("URI cannot be null.");
}

HttpResponse response = createHttpClient(proxy).execute(input == null ? new HttpRequest("GET", uri.toURL()) :
new HttpContentRequest("POST", uri.toURL()).setContent(HttpContent.string(GSON.toJson(input))));
HttpResponse response = createHttpClient(proxy)
.execute(input == null ? new HttpRequest("GET", uri.toURL()) :
new HttpContentRequest("POST", uri.toURL())
.setContent(HttpContent.string(GSON.toJson(input)))
.setHeader(Headers.CONTENT_TYPE, ContentTypes.APPLICATION_JSON.toString()));

if (responseType == null) {
return null;
Expand Down

0 comments on commit 05a699d

Please sign in to comment.