Skip to content

Commit

Permalink
fix base64 apply
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Sep 18, 2024
1 parent 048b080 commit 4574128
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/me/hsgamer/bettergui/modifier/SkullModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private static void setSkull(SkullMeta meta, String skull) {
}

if (BASE64_PATTERN.matcher(skull).matches()) {
Optional<byte[]> base64 = Validate.getBase64(skull);
base64.ifPresent(bytes -> skullHandler.setSkullByBase64(meta, bytes));
skullHandler.setSkullByBase64(meta, skull);
return;
}

Expand Down Expand Up @@ -149,7 +148,7 @@ default void setSkullByURL(SkullMeta meta, String url) {
}
}

void setSkullByBase64(SkullMeta meta, byte[] base64);
void setSkullByBase64(SkullMeta meta, String base64);

String getSkullValue(SkullMeta meta);
}
Expand Down Expand Up @@ -211,9 +210,12 @@ public void setSkullByURL(SkullMeta meta, URL url) {
}

@Override
public void setSkullByBase64(SkullMeta meta, byte[] base64) {
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
gameProfile.getProperties().put("textures", new Property("textures", new String(base64, StandardCharsets.UTF_8)));
public void setSkullByBase64(SkullMeta meta, String base64) {
GameProfile gameProfile = cache.computeIfAbsent(base64, b -> {
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
profile.getProperties().put("textures", new Property("textures", b));
return profile;
});
setSkullByGameProfile(meta, gameProfile);
}

Expand Down Expand Up @@ -269,9 +271,9 @@ public void setSkullByURL(SkullMeta meta, URL url) {
}

@Override
public void setSkullByBase64(SkullMeta meta, byte[] base64) {
public void setSkullByBase64(SkullMeta meta, String base64) {
try {
String decoded = new String(base64, StandardCharsets.UTF_8);
String decoded = new String(Base64.getDecoder().decode(base64), StandardCharsets.UTF_8);
JsonObject json = new Gson().fromJson(decoded, JsonObject.class);
String url = json.getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString();
setSkullByURL(meta, url);
Expand Down

0 comments on commit 4574128

Please sign in to comment.