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) {
Map<Type, MinecraftProfileTexture> textures = Maps.newEnumMap(Type.class);
skinServers.forEach(server -> server
.loadProfileData(profile)
.map(MinecraftTexturesPayload::getTextures)
.ifPresent(a -> a.forEach(textures::putIfAbsent)));
for (SkinServer server : skinServers) {
MinecraftTexturesPayload payload = server.getProfileData(profile);
if (payload != null) {
payload.getTextures().forEach(textures::putIfAbsent);
}
}
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;
@Override

View file

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

View file

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

View file

@ -34,8 +34,11 @@ public interface SkinServer extends Exposable {
"http://skins.voxelmodpack.com",
"http://skinmanager.voxelmodpack.com"));
@Deprecated
Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile);
MinecraftTexturesPayload getProfileData(GameProfile profile);
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getPreviewTextures(GameProfile profile);
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
protected MinecraftTexturesPayload getProfileData(GameProfile profile) {
try (CloseableHttpClient client = HttpClients.createSystem();
CloseableHttpResponse response = client.execute(new HttpGet(getTexturesURI(profile)))) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return readJson(response, MinecraftTexturesPayload.class);
public MinecraftTexturesPayload getProfileData(GameProfile profile) {
try (CloseableHttpClient client = HttpClients.createSystem()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(getTexturesURI(profile)))) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return readJson(response, MinecraftTexturesPayload.class);
}
}
} catch (IOException e) {