diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/skins/LegacySkinServer.java b/src/hdskins/java/com/voxelmodpack/hdskins/skins/LegacySkinServer.java index 80c22d5c..afbdfcf1 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/skins/LegacySkinServer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/skins/LegacySkinServer.java @@ -80,13 +80,7 @@ public class LegacySkinServer implements SkinServer { return Optional.empty(); } - return Optional.of(new TexturesPayloadBuilder() - .profileId(profile.getId()) - .profileName(profile.getName()) - .timestamp(System.currentTimeMillis()) - .isPublic(true) - .textures(map) - .build()); + return Optional.of(TexturesPayloadBuilder.createTexuresPayload(profile, map)); } @SuppressWarnings("deprecation") diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/skins/SkinServerSerializer.java b/src/hdskins/java/com/voxelmodpack/hdskins/skins/SkinServerSerializer.java index 42f9139e..f4992bed 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/skins/SkinServerSerializer.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/skins/SkinServerSerializer.java @@ -17,18 +17,21 @@ public class SkinServerSerializer implements JsonSerializer, JsonDes @Override public JsonElement serialize(SkinServer src, Type typeOfSrc, JsonSerializationContext context) { ServerType serverType = src.getClass().getAnnotation(ServerType.class); + if (serverType == null) { throw new JsonIOException("Skin server class did not have a type: " + typeOfSrc); } + JsonObject obj = context.serialize(src).getAsJsonObject(); obj.addProperty("type", serverType.value()); + return obj; } @Override public SkinServer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String type = json.getAsJsonObject().get("type").getAsString(); - Class clas = HDSkinManager.INSTANCE.getSkinServerClass(type); - return context.deserialize(json, clas); + + return context.deserialize(json, HDSkinManager.INSTANCE.getSkinServerClass(type)); } } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/skins/TexturesPayloadBuilder.java b/src/hdskins/java/com/voxelmodpack/hdskins/skins/TexturesPayloadBuilder.java index 9bbb49b6..0e284663 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/skins/TexturesPayloadBuilder.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/skins/TexturesPayloadBuilder.java @@ -3,7 +3,9 @@ package com.voxelmodpack.hdskins.skins; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; @@ -20,46 +22,26 @@ public class TexturesPayloadBuilder { private static Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); + public static MinecraftTexturesPayload createTexuresPayload(GameProfile profile, Map textures) { + return gson.fromJson(gson.toJson(new TexturesPayloadBuilder(profile, textures)), MinecraftTexturesPayload.class); + } + private long timestamp; + private UUID profileId; private String profileName; + private boolean isPublic; - private Map textures; - public TexturesPayloadBuilder timestamp(long time) { - this.timestamp = time; - return this; - } + private Map textures; - public TexturesPayloadBuilder profileId(UUID uuid) { - this.profileId = uuid; - return this; - } + public TexturesPayloadBuilder(GameProfile profile, Map textures) { + profileId = profile.getId(); + profileName = profile.getName(); + timestamp = System.currentTimeMillis(); - public TexturesPayloadBuilder profileName(String name) { - this.profileName = name; - return this; - } + isPublic = true; - public TexturesPayloadBuilder isPublic(boolean pub) { - this.isPublic = pub; - return this; - } - - public TexturesPayloadBuilder texture(MinecraftProfileTexture.Type type, MinecraftProfileTexture texture) { - if (textures == null) textures = Maps.newEnumMap(MinecraftProfileTexture.Type.class); - this.textures.put(type, texture); - return this; - } - - public TexturesPayloadBuilder textures(Map textures) { this.textures = textures; - return this; } - - public MinecraftTexturesPayload build() { - return gson.fromJson(gson.toJson(this), MinecraftTexturesPayload.class); - } - - }