移除GameProfile类的TypeAdapter
This commit is contained in:
@@ -17,10 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.auth.yggdrasil;
|
package org.jackhuang.hmcl.auth.yggdrasil;
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
import org.jackhuang.hmcl.util.Immutable;
|
import org.jackhuang.hmcl.util.Immutable;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,34 +61,4 @@ public final class GameProfile {
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Serializer implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile> {
|
|
||||||
|
|
||||||
public static final Serializer INSTANCE = new Serializer();
|
|
||||||
|
|
||||||
private Serializer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonElement serialize(GameProfile src, Type type, JsonSerializationContext context) {
|
|
||||||
JsonObject result = new JsonObject();
|
|
||||||
if (src.getId() != null)
|
|
||||||
result.add("id", context.serialize(src.getId()));
|
|
||||||
if (src.getName() != null)
|
|
||||||
result.addProperty("name", src.getName());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GameProfile deserialize(JsonElement je, Type type, JsonDeserializationContext context) throws JsonParseException {
|
|
||||||
if (!(je instanceof JsonObject))
|
|
||||||
throw new JsonParseException("The json element is not a JsonObject.");
|
|
||||||
|
|
||||||
JsonObject json = (JsonObject) je;
|
|
||||||
|
|
||||||
UUID id = json.has("id") ? context.deserialize(json.get("id"), UUID.class) : null;
|
|
||||||
String name = json.has("name") ? json.getAsJsonPrimitive("name").getAsString() : null;
|
|
||||||
return new GameProfile(id, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,8 +120,7 @@ public class YggdrasilService {
|
|||||||
public Optional<GameProfile> getCompleteGameProfile(UUID uuid) throws AuthenticationException {
|
public Optional<GameProfile> getCompleteGameProfile(UUID uuid) throws AuthenticationException {
|
||||||
Objects.requireNonNull(uuid);
|
Objects.requireNonNull(uuid);
|
||||||
|
|
||||||
return Optional.ofNullable(fromJson(request(provider.getProfilePropertiesURL(uuid), null), ProfileResponse.class))
|
return Optional.ofNullable(fromJson(request(provider.getProfilePropertiesURL(uuid), null), GameProfile.class));
|
||||||
.map(response -> new GameProfile(response.id, response.name, response.properties));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Map<TextureType, Texture>> getTextures(GameProfile profile) throws AuthenticationException {
|
public Optional<Map<TextureType, Texture>> getTextures(GameProfile profile) throws AuthenticationException {
|
||||||
@@ -191,12 +190,6 @@ public class YggdrasilService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProfileResponse {
|
|
||||||
public UUID id;
|
|
||||||
public String name;
|
|
||||||
public PropertyMap properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TextureResponse {
|
private class TextureResponse {
|
||||||
public Map<TextureType, Texture> textures;
|
public Map<TextureType, Texture> textures;
|
||||||
}
|
}
|
||||||
@@ -216,7 +209,6 @@ public class YggdrasilService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Gson GSON = new GsonBuilder()
|
private static final Gson GSON = new GsonBuilder()
|
||||||
.registerTypeAdapter(GameProfile.class, GameProfile.Serializer.INSTANCE)
|
|
||||||
.registerTypeAdapter(PropertyMap.class, PropertyMap.Serializer.INSTANCE)
|
.registerTypeAdapter(PropertyMap.class, PropertyMap.Serializer.INSTANCE)
|
||||||
.registerTypeAdapter(UUID.class, UUIDTypeAdapter.INSTANCE)
|
.registerTypeAdapter(UUID.class, UUIDTypeAdapter.INSTANCE)
|
||||||
.create();
|
.create();
|
||||||
|
|||||||
Reference in New Issue
Block a user