Don't need a factory for this either since everyone else does it correctly

This commit is contained in:
Sollace 2018-07-14 23:55:22 +02:00
parent 6debbc49da
commit fc0920ce15
3 changed files with 20 additions and 41 deletions

View file

@ -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")

View file

@ -17,18 +17,21 @@ public class SkinServerSerializer implements JsonSerializer<SkinServer>, 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<? extends SkinServer> clas = HDSkinManager.INSTANCE.getSkinServerClass(type);
return context.deserialize(json, clas);
return context.deserialize(json, HDSkinManager.INSTANCE.getSkinServerClass(type));
}
}

View file

@ -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<Type, MinecraftProfileTexture> 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<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures;
public TexturesPayloadBuilder timestamp(long time) {
this.timestamp = time;
return this;
}
private Map<Type, MinecraftProfileTexture> textures;
public TexturesPayloadBuilder profileId(UUID uuid) {
this.profileId = uuid;
return this;
}
public TexturesPayloadBuilder(GameProfile profile, Map<Type, MinecraftProfileTexture> 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<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures) {
this.textures = textures;
return this;
}
public MinecraftTexturesPayload build() {
return gson.fromJson(gson.toJson(this), MinecraftTexturesPayload.class);
}
}