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.empty();
} }
return Optional.of(new TexturesPayloadBuilder() return Optional.of(TexturesPayloadBuilder.createTexuresPayload(profile, map));
.profileId(profile.getId())
.profileName(profile.getName())
.timestamp(System.currentTimeMillis())
.isPublic(true)
.textures(map)
.build());
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View file

@ -17,18 +17,21 @@ public class SkinServerSerializer implements JsonSerializer<SkinServer>, JsonDes
@Override @Override
public JsonElement serialize(SkinServer src, Type typeOfSrc, JsonSerializationContext context) { public JsonElement serialize(SkinServer src, Type typeOfSrc, JsonSerializationContext context) {
ServerType serverType = src.getClass().getAnnotation(ServerType.class); ServerType serverType = src.getClass().getAnnotation(ServerType.class);
if (serverType == null) { if (serverType == null) {
throw new JsonIOException("Skin server class did not have a type: " + typeOfSrc); throw new JsonIOException("Skin server class did not have a type: " + typeOfSrc);
} }
JsonObject obj = context.serialize(src).getAsJsonObject(); JsonObject obj = context.serialize(src).getAsJsonObject();
obj.addProperty("type", serverType.value()); obj.addProperty("type", serverType.value());
return obj; return obj;
} }
@Override @Override
public SkinServer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public SkinServer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String type = json.getAsJsonObject().get("type").getAsString(); 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.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
import com.mojang.util.UUIDTypeAdapter; import com.mojang.util.UUIDTypeAdapter;
@ -20,46 +22,26 @@ public class TexturesPayloadBuilder {
private static Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); 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 long timestamp;
private UUID profileId; private UUID profileId;
private String profileName; private String profileName;
private boolean isPublic; private boolean isPublic;
private Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures;
public TexturesPayloadBuilder timestamp(long time) { private Map<Type, MinecraftProfileTexture> textures;
this.timestamp = time;
return this;
}
public TexturesPayloadBuilder profileId(UUID uuid) { public TexturesPayloadBuilder(GameProfile profile, Map<Type, MinecraftProfileTexture> textures) {
this.profileId = uuid; profileId = profile.getId();
return this; profileName = profile.getName();
} timestamp = System.currentTimeMillis();
public TexturesPayloadBuilder profileName(String name) { isPublic = true;
this.profileName = name;
return this;
}
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; this.textures = textures;
return this;
} }
public MinecraftTexturesPayload build() {
return gson.fromJson(gson.toJson(this), MinecraftTexturesPayload.class);
}
} }