mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 22:07: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.common.collect.ImmutableMap.Builder;
|
||||||
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.exceptions.AuthenticationException;
|
||||||
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.util.CallableFutures;
|
|
||||||
import com.voxelmodpack.hdskins.util.IndentedToStringStyle;
|
import com.voxelmodpack.hdskins.util.IndentedToStringStyle;
|
||||||
import com.voxelmodpack.hdskins.util.MoreHttpResponses;
|
import com.voxelmodpack.hdskins.util.MoreHttpResponses;
|
||||||
import com.voxelmodpack.hdskins.util.NetClient;
|
import com.voxelmodpack.hdskins.util.NetClient;
|
||||||
|
@ -16,7 +15,6 @@ import net.minecraft.util.Session;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@ServerType("bethlehem")
|
@ServerType("bethlehem")
|
||||||
public class BethlehemSkinServer implements SkinServer {
|
public class BethlehemSkinServer implements SkinServer {
|
||||||
|
@ -42,8 +40,7 @@ public class BethlehemSkinServer implements SkinServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload upload) {
|
public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException {
|
||||||
return CallableFutures.asyncFailableFuture(() -> {
|
|
||||||
SkinServer.verifyServerConnection(session, SERVER_ID);
|
SkinServer.verifyServerConnection(session, SERVER_ID);
|
||||||
|
|
||||||
NetClient client = new NetClient("POST", address);
|
NetClient client = new NetClient("POST", address);
|
||||||
|
@ -60,8 +57,6 @@ public class BethlehemSkinServer implements SkinServer {
|
||||||
}
|
}
|
||||||
return new SkinUploadResponse(response.text());
|
return new SkinUploadResponse(response.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
}, HDSkinManager.skinUploadExecutor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, ?> createHeaders(Session session, SkinUpload upload) {
|
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.common.collect.ImmutableMap.Builder;
|
||||||
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.exceptions.AuthenticationException;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||||
import com.mojang.util.UUIDTypeAdapter;
|
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.
|
// Add the ETag onto the end of the texture hash. Should properly cache the textures.
|
||||||
return new MinecraftProfileTexture(url, null) {
|
return new MinecraftProfileTexture(url, null) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHash() {
|
public String getHash() {
|
||||||
return super.getHash() + eTag;
|
return super.getHash() + eTag;
|
||||||
|
@ -109,12 +109,11 @@ public class LegacySkinServer implements SkinServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload upload) {
|
public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException {
|
||||||
if (Strings.isNullOrEmpty(gateway)) {
|
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);
|
||||||
|
@ -130,12 +129,12 @@ public class LegacySkinServer implements SkinServer {
|
||||||
if (response.startsWith("ERROR: ")) {
|
if (response.startsWith("ERROR: ")) {
|
||||||
response = response.substring(7);
|
response = response.substring(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK")) {
|
if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK")) {
|
||||||
throw new IOException(response);
|
throw new IOException(response);
|
||||||
}
|
}
|
||||||
return new SkinUploadResponse(response);
|
|
||||||
|
|
||||||
}, HDSkinManager.skinUploadExecutor);
|
return new SkinUploadResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnsupportedOperationException gatewayUnsupported() {
|
private UnsupportedOperationException gatewayUnsupported() {
|
||||||
|
|
|
@ -32,7 +32,11 @@ public interface SkinServer extends Exposable {
|
||||||
|
|
||||||
MinecraftTexturesPayload loadProfileData(GameProfile profile) throws IOException;
|
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) {
|
default CompletableFuture<MinecraftTexturesPayload> getPreviewTextures(GameProfile profile) {
|
||||||
return CallableFutures.asyncFailableFuture(() -> loadProfileData(profile), HDSkinManager.skinDownloadExecutor);
|
return CallableFutures.asyncFailableFuture(() -> loadProfileData(profile), HDSkinManager.skinDownloadExecutor);
|
||||||
|
|
|
@ -31,4 +31,8 @@ public class SkinUpload {
|
||||||
public MinecraftProfileTexture.Type getType() {
|
public MinecraftProfileTexture.Type getType() {
|
||||||
return type;
|
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.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||||
import com.mojang.util.UUIDTypeAdapter;
|
import com.mojang.util.UUIDTypeAdapter;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
import com.voxelmodpack.hdskins.util.CallableFutures;
|
|
||||||
import com.voxelmodpack.hdskins.util.IndentedToStringStyle;
|
import com.voxelmodpack.hdskins.util.IndentedToStringStyle;
|
||||||
import com.voxelmodpack.hdskins.util.MoreHttpResponses;
|
import com.voxelmodpack.hdskins.util.MoreHttpResponses;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -29,7 +28,6 @@ import java.net.URI;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -58,12 +56,11 @@ public class ValhallaSkinServer implements SkinServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, SkinUpload skin) {
|
public SkinUploadResponse performSkinUpload(Session session, SkinUpload upload) throws IOException, AuthenticationException {
|
||||||
URI image = skin.getImage();
|
URI image = upload.getImage();
|
||||||
Map<String, String> metadata = skin.getMetadata();
|
Map<String, String> metadata = upload.getMetadata();
|
||||||
MinecraftProfileTexture.Type type = skin.getType();
|
MinecraftProfileTexture.Type type = upload.getType();
|
||||||
|
|
||||||
return CallableFutures.asyncFailableFuture(() -> {
|
|
||||||
authorize(session);
|
authorize(session);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -76,12 +73,9 @@ public class ValhallaSkinServer implements SkinServer {
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}, HDSkinManager.skinUploadExecutor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SkinUploadResponse upload(Session session, @Nullable URI image,
|
private SkinUploadResponse upload(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata) throws IOException {
|
||||||
MinecraftProfileTexture.Type type, Map<String, String> metadata)
|
|
||||||
throws IOException {
|
|
||||||
GameProfile profile = session.getProfile();
|
GameProfile profile = session.getProfile();
|
||||||
|
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
|
|
Loading…
Reference in a new issue