mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 22:38:00 +01:00
Fix and update error handling for bethlehem
This commit is contained in:
parent
6f1837a46f
commit
d19b649d6d
1 changed files with 15 additions and 23 deletions
|
@ -2,11 +2,8 @@ package com.voxelmodpack.hdskins.skins;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||
|
@ -14,13 +11,10 @@ import net.minecraft.util.Session;
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ServerType("bethlehem")
|
||||
public class BethlehemSkinServer implements SkinServer {
|
||||
|
||||
|
@ -37,28 +31,26 @@ public class BethlehemSkinServer implements SkinServer {
|
|||
public MinecraftTexturesPayload loadProfileData(GameProfile profile) throws IOException {
|
||||
try (MoreHttpResponses response = new NetClient("GET", getPath(profile)).send()) {
|
||||
|
||||
JsonObject s = response.json(JsonObject.class);
|
||||
|
||||
if (s.has("success") && s.get("success").getAsBoolean()) {
|
||||
s = s.get("data").getAsJsonObject();
|
||||
return gson.fromJson(s, MinecraftTexturesPayload.class);
|
||||
if (!response.ok()) {
|
||||
throw new IOException(response.getResponse().getStatusLine().getReasonPhrase());
|
||||
}
|
||||
throw new IOException(s.get("error").getAsString());
|
||||
|
||||
return response.json(MinecraftTexturesPayload.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload skin) {
|
||||
URI image = skin.getImage();
|
||||
Map<String, String> metadata = skin.getMetadata();
|
||||
MinecraftProfileTexture.Type type = skin.getType();
|
||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload upload) {
|
||||
return CallableFutures.asyncFailableFuture(() -> {
|
||||
SkinServer.verifyServerConnection(session, SERVER_ID);
|
||||
|
||||
NetClient client = new NetClient("POST", address).putHeaders(createHeaders(session, type, image, metadata));
|
||||
// TODO: Fix this
|
||||
NetClient client = new NetClient("POST", address);
|
||||
|
||||
if (image != null) {
|
||||
client.putFile(type.toString().toLowerCase(Locale.US), "image/png", image);
|
||||
client.putHeaders(createHeaders(session, upload));
|
||||
|
||||
if (upload.getImage() != null) {
|
||||
client.putFile(upload.getType().toString().toLowerCase(Locale.US), "image/png", upload.getImage());
|
||||
}
|
||||
|
||||
try (MoreHttpResponses response = client.send()) {
|
||||
|
@ -71,17 +63,17 @@ public class BethlehemSkinServer implements SkinServer {
|
|||
}, HDSkinManager.skinUploadExecutor);
|
||||
}
|
||||
|
||||
protected Map<String, ?> createHeaders(Session session, Type type, @Nullable URI image, Map<String, String> metadata) {
|
||||
protected Map<String, ?> createHeaders(Session session, SkinUpload upload) {
|
||||
Builder<String, Object> builder = ImmutableMap.<String, Object>builder()
|
||||
.put("accessToken", session.getToken())
|
||||
.put("user", session.getUsername())
|
||||
.put("uuid", UUIDTypeAdapter.fromUUID(session.getProfile().getId()))
|
||||
.put("type", type.toString().toLowerCase(Locale.US));
|
||||
.put("type", upload.getType().toString().toLowerCase(Locale.US));
|
||||
|
||||
if (image == null) {
|
||||
if (upload.getImage() == null) {
|
||||
builder.put("clear", "1");
|
||||
} else {
|
||||
builder.put("model", metadata.getOrDefault("mode", "default"));
|
||||
builder.put("model", upload.getMetadata().getOrDefault("mode", "default"));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
|
Loading…
Reference in a new issue