diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/BethlehemSkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/BethlehemSkinServer.java index e9fdb626..22acd615 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/BethlehemSkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/BethlehemSkinServer.java @@ -4,10 +4,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.gson.annotations.Expose; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.exceptions.AuthenticationException; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; -import com.voxelmodpack.hdskins.HDSkinManager; -import com.voxelmodpack.hdskins.util.CallableFutures; import com.voxelmodpack.hdskins.util.IndentedToStringStyle; import com.voxelmodpack.hdskins.util.MoreHttpResponses; import com.voxelmodpack.hdskins.util.NetClient; @@ -16,7 +15,6 @@ import net.minecraft.util.Session; import java.io.IOException; import java.util.Locale; import java.util.Map; -import java.util.concurrent.CompletableFuture; @ServerType("bethlehem") public class BethlehemSkinServer implements SkinServer { @@ -42,26 +40,23 @@ public class BethlehemSkinServer implements SkinServer { } @Override - public CompletableFuture uploadSkin(Session session, SkinUpload upload) { - return CallableFutures.asyncFailableFuture(() -> { - SkinServer.verifyServerConnection(session, SERVER_ID); + public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException { + SkinServer.verifyServerConnection(session, SERVER_ID); - NetClient client = new NetClient("POST", address); + NetClient client = new NetClient("POST", address); - client.putHeaders(createHeaders(session, upload)); + client.putHeaders(createHeaders(session, upload)); - if (upload.getImage() != null) { - client.putFile(upload.getType().toString().toLowerCase(Locale.US), "image/png", upload.getImage()); + if (upload.getImage() != null) { + client.putFile(upload.getType().toString().toLowerCase(Locale.US), "image/png", upload.getImage()); + } + + try (MoreHttpResponses response = client.send()) { + if (!response.ok()) { + throw new IOException(response.text()); } - - try (MoreHttpResponses response = client.send()) { - if (!response.ok()) { - throw new IOException(response.text()); - } - return new SkinUploadResponse(response.text()); - } - - }, HDSkinManager.skinUploadExecutor); + return new SkinUploadResponse(response.text()); + } } protected Map createHeaders(Session session, SkinUpload upload) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java index 438544ef..3a18c9d5 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/LegacySkinServer.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.gson.annotations.Expose; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.exceptions.AuthenticationException; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; @@ -99,7 +100,6 @@ public class LegacySkinServer implements SkinServer { // Add the ETag onto the end of the texture hash. Should properly cache the textures. return new MinecraftProfileTexture(url, null) { - @Override public String getHash() { return super.getHash() + eTag; @@ -109,33 +109,32 @@ public class LegacySkinServer implements SkinServer { } @Override - public CompletableFuture uploadSkin(Session session, SkinUpload upload) { + public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException { if (Strings.isNullOrEmpty(gateway)) { - return CallableFutures.failedFuture(gatewayUnsupported()); + throw gatewayUnsupported(); } - return CallableFutures.asyncFailableFuture(() -> { - SkinServer.verifyServerConnection(session, SERVER_ID); + SkinServer.verifyServerConnection(session, SERVER_ID); - NetClient client = new NetClient("POST", gateway); + NetClient client = new NetClient("POST", gateway); - client.putFormData(createHeaders(session, upload), "image/png"); + client.putFormData(createHeaders(session, upload), "image/png"); - if (upload.getImage() != null) { - client.putFile(upload.getType().toString().toLowerCase(Locale.US), "image/png", upload.getImage()); - } + if (upload.getImage() != null) { + client.putFile(upload.getType().toString().toLowerCase(Locale.US), "image/png", upload.getImage()); + } - String response = client.send().text(); + String response = client.send().text(); - if (response.startsWith("ERROR: ")) { - response = response.substring(7); - } - if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK")) { - throw new IOException(response); - } - return new SkinUploadResponse(response); + if (response.startsWith("ERROR: ")) { + response = response.substring(7); + } - }, HDSkinManager.skinUploadExecutor); + if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK")) { + throw new IOException(response); + } + + return new SkinUploadResponse(response); } private UnsupportedOperationException gatewayUnsupported() { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java index 5804f8b7..1fa6505d 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinServer.java @@ -32,7 +32,11 @@ public interface SkinServer extends Exposable { MinecraftTexturesPayload loadProfileData(GameProfile profile) throws IOException; - CompletableFuture uploadSkin(Session session, SkinUpload upload); + SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException; + + default CompletableFuture uploadSkin(Session session, SkinUpload upload) { + return CallableFutures.asyncFailableFuture(() -> performSkinUpload(session, upload), HDSkinManager.skinUploadExecutor); + } default CompletableFuture getPreviewTextures(GameProfile profile) { return CallableFutures.asyncFailableFuture(() -> loadProfileData(profile), HDSkinManager.skinDownloadExecutor); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinUpload.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinUpload.java index 14dd0b16..9789bc10 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinUpload.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/SkinUpload.java @@ -31,4 +31,8 @@ public class SkinUpload { public MinecraftProfileTexture.Type getType() { return type; } + + public String getSchemaAction() { + return image == null ? "delete" : image.getScheme(); + } } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java index 4841218f..f5a9ece7 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/server/ValhallaSkinServer.java @@ -9,7 +9,6 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; import com.voxelmodpack.hdskins.HDSkinManager; -import com.voxelmodpack.hdskins.util.CallableFutures; import com.voxelmodpack.hdskins.util.IndentedToStringStyle; import com.voxelmodpack.hdskins.util.MoreHttpResponses; import net.minecraft.client.Minecraft; @@ -29,7 +28,6 @@ import java.net.URI; import java.util.Locale; import java.util.Map; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import javax.annotation.Nullable; @@ -58,30 +56,26 @@ public class ValhallaSkinServer implements SkinServer { } @Override - public CompletableFuture uploadSkin(Session session, SkinUpload skin) { - URI image = skin.getImage(); - Map metadata = skin.getMetadata(); - MinecraftProfileTexture.Type type = skin.getType(); + public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException { + URI image = upload.getImage(); + Map metadata = upload.getMetadata(); + MinecraftProfileTexture.Type type = upload.getType(); - return CallableFutures.asyncFailableFuture(() -> { + authorize(session); + + try { + return upload(session, image, type, metadata); + } catch (IOException e) { + if (e.getMessage().equals("Authorization failed")) { + accessToken = null; authorize(session); - - try { - return upload(session, image, type, metadata); - } catch (IOException e) { - if (e.getMessage().equals("Authorization failed")) { - accessToken = null; - authorize(session); - return upload(session, image, type, metadata); - } - throw e; - } - }, HDSkinManager.skinUploadExecutor); + return upload(session, image, type, metadata); + } + throw e; + } } - private SkinUploadResponse upload(Session session, @Nullable URI image, - MinecraftProfileTexture.Type type, Map metadata) - throws IOException { + private SkinUploadResponse upload(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map metadata) throws IOException { GameProfile profile = session.getProfile(); if (image == null) {