Skip to content

Commit

Permalink
cache skull profile
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jun 29, 2024
1 parent 54388da commit aafca1b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SkullModifier implements ItemMetaModifier, ItemMetaComparator {
private static final Pattern MOJANG_SHA256_APPROX = Pattern.compile("[0-9a-z]{55,70}");
private static final SkullMeta delegateSkullMeta;
private static final SkullHandler skullHandler = new SkullHandler();
private static final Map<String, GameProfile> cache = new HashMap<>();

static {
ItemStack itemStack;
Expand Down Expand Up @@ -159,8 +160,11 @@ public void setSkullByPlayer(SkullMeta meta, OfflinePlayer player) {
}

public void setSkullByURL(SkullMeta meta, URL url) {
GameProfile profile = new GameProfile(UUID.randomUUID(), "");
profile.getProperties().put("textures", new Property("textures", Base64.getEncoder().encodeToString(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes())));
GameProfile profile = cache.computeIfAbsent(url.toString(), s -> {
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
gameProfile.getProperties().put("textures", new Property("textures", Base64.getEncoder().encodeToString(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes())));
return gameProfile;
});

try {
Method setProfile = meta.getClass().getMethod("setProfile", GameProfile.class);
Expand Down

0 comments on commit aafca1b

Please sign in to comment.