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