mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-12-02 00:37:59 +01:00
Merge with Killjoy's changes
This commit is contained in:
parent
6db67772b9
commit
38fa6c2484
4 changed files with 17 additions and 40 deletions
|
@ -4,17 +4,16 @@ import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -22,8 +21,6 @@ import org.apache.logging.log4j.Logger;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.util.concurrent.Futures;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
@ -54,7 +51,8 @@ public class BethlehemSkinServer implements SkinServer {
|
||||||
|
|
||||||
private static final Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
private static final Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||||
|
|
||||||
public MinecraftTexturesPayload getProfileData(GameProfile profile) {
|
@Override
|
||||||
|
public Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile) {
|
||||||
|
|
||||||
String url = getPath(profile);
|
String url = getPath(profile);
|
||||||
|
|
||||||
|
@ -89,7 +87,7 @@ public class BethlehemSkinServer implements SkinServer {
|
||||||
if (s.has("success") && s.get("success").getAsBoolean()) {
|
if (s.has("success") && s.get("success").getAsBoolean()) {
|
||||||
s = s.get("data").getAsJsonObject();
|
s = s.get("data").getAsJsonObject();
|
||||||
|
|
||||||
return gson.fromJson(s, MinecraftTexturesPayload.class);
|
return Optional.ofNullable(gson.fromJson(s, MinecraftTexturesPayload.class));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.trace("Couldn't reach skin server for {} at {}", profile.getName(), url, e);
|
logger.trace("Couldn't reach skin server for {} at {}", profile.getName(), url, e);
|
||||||
|
@ -101,46 +99,27 @@ public class BethlehemSkinServer implements SkinServer {
|
||||||
IOUtils.closeQuietly(reader);
|
IOUtils.closeQuietly(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftProfileTexture getPreview(Type type, GameProfile profile) {
|
@Override
|
||||||
MinecraftTexturesPayload payload = getProfileData(profile);
|
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, URI image, Type type, Map<String, String> metadata) {
|
||||||
|
|
||||||
if (payload != null && payload.getTextures().containsKey(type)) {
|
if (Strings.isNullOrEmpty(gateway)) {
|
||||||
return payload.getTextures().get(type);
|
return CallableFutures.failedFuture(new NullPointerException("gateway url is blank"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return CallableFutures.asyncFailableFuture(() -> {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile) {
|
|
||||||
return Optional.ofNullable(getProfileData(profile));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Optional<MinecraftProfileTexture> getPreviewTexture(Type type, GameProfile profile) {
|
|
||||||
return Optional.ofNullable(getPreview(type, profile));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable Path image, MinecraftProfileTexture.Type type, boolean thinSkinType) {
|
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(gateway))
|
|
||||||
return Futures.immediateFailedFuture(new NullPointerException("gateway url is blank"));
|
|
||||||
|
|
||||||
return HDSkinManager.skinUploadExecutor.submit(() -> {
|
|
||||||
verifyServerConnection(session, SERVER_ID);
|
verifyServerConnection(session, SERVER_ID);
|
||||||
|
|
||||||
Map<String, ?> data = image == null ? getClearData(session, type) : getUploadData(session, type, (thinSkinType ? "slim" : "default"), image);
|
Map<String, ?> data = image == null ? getClearData(session, type) : getUploadData(session, type, metadata.getOrDefault("mode", "default"), image);
|
||||||
|
|
||||||
ThreadMultipartPostUpload upload = new ThreadMultipartPostUpload(gateway, data);
|
ThreadMultipartPostUpload upload = new ThreadMultipartPostUpload(gateway, data);
|
||||||
|
|
||||||
String response = upload.uploadMultipart();
|
String response = upload.uploadMultipart();
|
||||||
|
|
||||||
return new SkinUploadResponse(response.equalsIgnoreCase("OK"), response);
|
return new SkinUploadResponse(response.equalsIgnoreCase("OK"), response);
|
||||||
});
|
}, HDSkinManager.skinUploadExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static ImmutableMap.Builder<String, Object> getData(Session session, MinecraftProfileTexture.Type type) {
|
protected static ImmutableMap.Builder<String, Object> getData(Session session, MinecraftProfileTexture.Type type) {
|
||||||
|
@ -157,7 +136,7 @@ public class BethlehemSkinServer implements SkinServer {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Map<String, ?> getUploadData(Session session, MinecraftProfileTexture.Type type, String model, Path skinFile) {
|
protected static Map<String, ?> getUploadData(Session session, MinecraftProfileTexture.Type type, String model, URI skinFile) {
|
||||||
return getData(session, type)
|
return getData(session, type)
|
||||||
.put("model", model)
|
.put("model", model)
|
||||||
.put(type.toString().toLowerCase(Locale.US), skinFile)
|
.put(type.toString().toLowerCase(Locale.US), skinFile)
|
||||||
|
|
|
@ -93,9 +93,7 @@ public class LegacySkinServer implements SkinServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image,
|
public CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata) {
|
||||||
MinecraftProfileTexture.Type type, Map<String, String> metadata) {
|
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(this.gateway)) {
|
if (Strings.isNullOrEmpty(this.gateway)) {
|
||||||
return CallableFutures.failedFuture(new NullPointerException("gateway url is blank"));
|
return CallableFutures.failedFuture(new NullPointerException("gateway url is blank"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ public interface SkinServer {
|
||||||
return loadProfileData(profile).map(MinecraftTexturesPayload::getTextures).orElse(Collections.emptyMap());
|
return loadProfileData(profile).map(MinecraftTexturesPayload::getTextures).orElse(Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image,
|
CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata);
|
||||||
MinecraftProfileTexture.Type type, Map<String, String> metadata);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class ValhallaSkinServer implements SkinServer {
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private final String address;
|
private final String address;
|
||||||
|
|
||||||
private final Gson gson = new GsonBuilder()
|
private final Gson gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||||
.create();
|
.create();
|
||||||
|
|
Loading…
Reference in a new issue