Sick and tired of these optionals

This commit is contained in:
Sollace 2018-07-31 09:45:34 +02:00
parent 92209cbf1f
commit f32611a1eb
6 changed files with 17 additions and 13 deletions

View file

@ -205,10 +205,12 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
private Map<Type, MinecraftProfileTexture> loadProfileData(GameProfile profile) { private Map<Type, MinecraftProfileTexture> loadProfileData(GameProfile profile) {
Map<Type, MinecraftProfileTexture> textures = Maps.newEnumMap(Type.class); Map<Type, MinecraftProfileTexture> textures = Maps.newEnumMap(Type.class);
skinServers.forEach(server -> server for (SkinServer server : skinServers) {
.loadProfileData(profile) MinecraftTexturesPayload payload = server.getProfileData(profile);
.map(MinecraftTexturesPayload::getTextures) if (payload != null) {
.ifPresent(a -> a.forEach(textures::putIfAbsent))); payload.getTextures().forEach(textures::putIfAbsent);
}
}
return textures; return textures;
} }

View file

@ -57,8 +57,6 @@ public abstract class AbstractSkinServer implements SkinServer {
} }
} }
protected abstract MinecraftTexturesPayload getProfileData(GameProfile profile);
protected abstract SkinUploadResponse doUpload(Session session, URI image, Type type, Map<String, String> metadata) throws AuthenticationException, IOException; protected abstract SkinUploadResponse doUpload(Session session, URI image, Type type, Map<String, String> metadata) throws AuthenticationException, IOException;
@Override @Override

View file

@ -26,7 +26,7 @@ public class BethlehemSkinServer extends AbstractSkinServer {
} }
@Override @Override
protected MinecraftTexturesPayload getProfileData(GameProfile profile) { public MinecraftTexturesPayload getProfileData(GameProfile profile) {
try (NetClient client = new NetClient("GET", getPath(profile))) { try (NetClient client = new NetClient("GET", getPath(profile))) {
if (client.getResponseCode() == HttpStatus.SC_OK) { if (client.getResponseCode() == HttpStatus.SC_OK) {
return gson.fromJson(client.getResponseText(), MinecraftTexturesPayload.class); return gson.fromJson(client.getResponseText(), MinecraftTexturesPayload.class);

View file

@ -51,7 +51,7 @@ public class LegacySkinServer extends AbstractSkinServer {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
protected MinecraftTexturesPayload getProfileData(GameProfile profile) { public MinecraftTexturesPayload getProfileData(GameProfile profile) {
ImmutableMap.Builder<Type, MinecraftProfileTexture> builder = ImmutableMap.builder(); ImmutableMap.Builder<Type, MinecraftProfileTexture> builder = ImmutableMap.builder();
for (Type type : Type.values()) { for (Type type : Type.values()) {

View file

@ -34,8 +34,11 @@ public interface SkinServer extends Exposable {
"http://skins.voxelmodpack.com", "http://skins.voxelmodpack.com",
"http://skinmanager.voxelmodpack.com")); "http://skinmanager.voxelmodpack.com"));
@Deprecated
Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile); Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile);
MinecraftTexturesPayload getProfileData(GameProfile profile);
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getPreviewTextures(GameProfile profile); Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getPreviewTextures(GameProfile profile);
CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata); CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata);

View file

@ -47,11 +47,12 @@ public class ValhallaSkinServer extends AbstractSkinServer {
} }
@Override @Override
protected MinecraftTexturesPayload getProfileData(GameProfile profile) { public MinecraftTexturesPayload getProfileData(GameProfile profile) {
try (CloseableHttpClient client = HttpClients.createSystem(); try (CloseableHttpClient client = HttpClients.createSystem()) {
CloseableHttpResponse response = client.execute(new HttpGet(getTexturesURI(profile)))) { try (CloseableHttpResponse response = client.execute(new HttpGet(getTexturesURI(profile)))) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return readJson(response, MinecraftTexturesPayload.class); return readJson(response, MinecraftTexturesPayload.class);
}
} }
} catch (IOException e) { } catch (IOException e) {