[FEATURE] JsonTexture convertMap

This commit is contained in:
Gravita 2023-10-22 15:27:54 +07:00
parent cebeb55c00
commit b5e10e8f9d

View file

@ -42,24 +42,8 @@ public Texture getSkinTexture(UUID uuid, String username, String client) {
public Map<String, Texture> getAssets(UUID uuid, String username, String client) { public Map<String, Texture> getAssets(UUID uuid, String username, String client) {
try { try {
var result = HTTPRequest.jsonRequest(null, "GET", new URL(RequestTextureProvider.getTextureURL(url, uuid, username, client))); var result = HTTPRequest.jsonRequest(null, "GET", new URL(RequestTextureProvider.getTextureURL(url, uuid, username, client)));
Map<String, JsonTexture> map = Launcher.gsonManager.gson.fromJson(result, MAP_TYPE); Map<String, JsonTexture> map = Launcher.gsonManager.gson.fromJson(result, MAP_TYPE);
if (map == null) { return JsonTexture.convertMap(map);
return new HashMap<>();
}
if (map.get("skin") != null) { // Legacy script
map.put("SKIN", map.get("skin"));
map.remove("skin");
}
if (map.get("cloak") != null) {
map.put("CAPE", map.get("cloak"));
map.remove("cloak");
}
Map<String, Texture> res = new HashMap<>();
for(var e : map.entrySet()) {
res.put(e.getKey(), e.getValue().toTexture());
}
return res;
} catch (IOException e) { } catch (IOException e) {
logger.error("JsonTextureProvider", e); logger.error("JsonTextureProvider", e);
return new HashMap<>(); return new HashMap<>();
@ -70,5 +54,16 @@ public record JsonTexture(String url, String hash, Map<String, String> metadata)
public Texture toTexture() { public Texture toTexture() {
return new Texture(url, hash == null ? null : SecurityHelper.fromHex(hash), metadata); return new Texture(url, hash == null ? null : SecurityHelper.fromHex(hash), metadata);
} }
public static Map<String, Texture> convertMap(Map<String, JsonTexture> map) {
if (map == null) {
return new HashMap<>();
}
Map<String, Texture> res = new HashMap<>();
for(var e : map.entrySet()) {
res.put(e.getKey(), e.getValue().toTexture());
}
return res;
}
} }
} }