mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] JsonTexture convertMap
This commit is contained in:
parent
cebeb55c00
commit
b5e10e8f9d
1 changed files with 12 additions and 17 deletions
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue