mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 07:27:59 +01:00
Handle the futures stuff in one place
This commit is contained in:
parent
dec6ad249f
commit
10eda59bed
5 changed files with 57 additions and 61 deletions
|
@ -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,8 +40,7 @@ public class BethlehemSkinServer implements SkinServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload upload) {
|
||||
return CallableFutures.asyncFailableFuture(() -> {
|
||||
public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException {
|
||||
SkinServer.verifyServerConnection(session, SERVER_ID);
|
||||
|
||||
NetClient client = new NetClient("POST", address);
|
||||
|
@ -60,8 +57,6 @@ public class BethlehemSkinServer implements SkinServer {
|
|||
}
|
||||
return new SkinUploadResponse(response.text());
|
||||
}
|
||||
|
||||
}, HDSkinManager.skinUploadExecutor);
|
||||
}
|
||||
|
||||
protected Map<String, ?> createHeaders(Session session, SkinUpload upload) {
|
||||
|
|
|
@ -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,12 +109,11 @@ public class LegacySkinServer implements SkinServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SkinUploadResponse> 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);
|
||||
|
||||
NetClient client = new NetClient("POST", gateway);
|
||||
|
@ -130,12 +129,12 @@ public class LegacySkinServer implements SkinServer {
|
|||
if (response.startsWith("ERROR: ")) {
|
||||
response = response.substring(7);
|
||||
}
|
||||
|
||||
if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK")) {
|
||||
throw new IOException(response);
|
||||
}
|
||||
return new SkinUploadResponse(response);
|
||||
|
||||
}, HDSkinManager.skinUploadExecutor);
|
||||
return new SkinUploadResponse(response);
|
||||
}
|
||||
|
||||
private UnsupportedOperationException gatewayUnsupported() {
|
||||
|
|
|
@ -32,7 +32,11 @@ public interface SkinServer extends Exposable {
|
|||
|
||||
MinecraftTexturesPayload loadProfileData(GameProfile profile) throws IOException;
|
||||
|
||||
CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload upload);
|
||||
SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException;
|
||||
|
||||
default CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload upload) {
|
||||
return CallableFutures.asyncFailableFuture(() -> performSkinUpload(session, upload), HDSkinManager.skinUploadExecutor);
|
||||
}
|
||||
|
||||
default CompletableFuture<MinecraftTexturesPayload> getPreviewTextures(GameProfile profile) {
|
||||
return CallableFutures.asyncFailableFuture(() -> loadProfileData(profile), HDSkinManager.skinDownloadExecutor);
|
||||
|
|
|
@ -31,4 +31,8 @@ public class SkinUpload {
|
|||
public MinecraftProfileTexture.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getSchemaAction() {
|
||||
return image == null ? "delete" : image.getScheme();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,12 +56,11 @@ public class ValhallaSkinServer implements SkinServer {
|
|||
}
|
||||
|
||||
@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 SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException {
|
||||
URI image = upload.getImage();
|
||||
Map<String, String> metadata = upload.getMetadata();
|
||||
MinecraftProfileTexture.Type type = upload.getType();
|
||||
|
||||
return CallableFutures.asyncFailableFuture(() -> {
|
||||
authorize(session);
|
||||
|
||||
try {
|
||||
|
@ -76,12 +73,9 @@ public class ValhallaSkinServer implements SkinServer {
|
|||
}
|
||||
throw e;
|
||||
}
|
||||
}, HDSkinManager.skinUploadExecutor);
|
||||
}
|
||||
|
||||
private SkinUploadResponse upload(Session session, @Nullable URI image,
|
||||
MinecraftProfileTexture.Type type, Map<String, String> metadata)
|
||||
throws IOException {
|
||||
private SkinUploadResponse upload(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata) throws IOException {
|
||||
GameProfile profile = session.getProfile();
|
||||
|
||||
if (image == null) {
|
||||
|
|
Loading…
Reference in a new issue