Skip to content

Commit aafca1b

Browse files
committed
cache skull profile
1 parent 54388da commit aafca1b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/me/hsgamer/bettergui/modifier/SkullModifier.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class SkullModifier implements ItemMetaModifier, ItemMetaComparator {
3434
private static final Pattern MOJANG_SHA256_APPROX = Pattern.compile("[0-9a-z]{55,70}");
3535
private static final SkullMeta delegateSkullMeta;
3636
private static final SkullHandler skullHandler = new SkullHandler();
37+
private static final Map<String, GameProfile> cache = new HashMap<>();
3738

3839
static {
3940
ItemStack itemStack;
@@ -159,8 +160,11 @@ public void setSkullByPlayer(SkullMeta meta, OfflinePlayer player) {
159160
}
160161

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

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

0 commit comments

Comments
 (0)