From dc2aab1d22b7d29bca9d03b244e67e5932fad728 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Wed, 15 Oct 2025 12:10:20 +1100 Subject: [PATCH] some more head code fixes --- .../inventory/items/utils/CustomHeads.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/builder/inventory/items/utils/CustomHeads.java b/src/me/rockyhawk/commandpanels/builder/inventory/items/utils/CustomHeads.java index 9f8606c..ecda3e7 100644 --- a/src/me/rockyhawk/commandpanels/builder/inventory/items/utils/CustomHeads.java +++ b/src/me/rockyhawk/commandpanels/builder/inventory/items/utils/CustomHeads.java @@ -6,7 +6,7 @@ import com.google.gson.JsonParser; import me.rockyhawk.commandpanels.Context; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.profile.PlayerTextures; @@ -104,15 +104,17 @@ public class CustomHeads { // Try to get a profile from cache first PlayerProfile profile = profileCache.get(key); - if (profile == null) { - // Fallback to offline player profile to show textures when players are already online - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName); - profile = offlinePlayer.getPlayerProfile(); - - // Enqueue async task to fill cache for next time - enqueuePlayerHead(key); + if(profile == null){ + // Use local texture if player is currently online + Player onlinePlayer = Bukkit.getPlayerExact(playerName); + if(onlinePlayer != null){ + profile = onlinePlayer.getPlayerProfile(); + profileCache.put(key, profile); + } } + if (!profileCache.containsKey(key)) enqueuePlayerHead(key); + // Put profile on the head skullMeta.setPlayerProfile(profile); skull.setItemMeta(skullMeta); @@ -128,17 +130,16 @@ public class CustomHeads { */ private void cachePlayerHeadAsync(String playerName) { String key = playerName.toLowerCase(); - if (profileCache.containsKey(key)) return; // already cached Bukkit.getAsyncScheduler().runNow(ctx.plugin, (t) -> { - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName); - PlayerProfile p = offlinePlayer.getPlayerProfile(); - if (p == null) { - UUID offlineUuid = UUID.nameUUIDFromBytes(playerName.getBytes(StandardCharsets.UTF_8)); - p = Bukkit.createProfile(offlineUuid, playerName); + PlayerProfile p = Bukkit.createProfile(playerName); + p.complete(true); // network calls + if(p.isComplete()){ + profileCache.put(key, p); + }else{ + profileCache.put(key, null); + enqueuePlayerHead(key); // allow a second try } - p.complete(true); // network call - profileCache.put(key, p); }); } @@ -168,6 +169,6 @@ public class CustomHeads { // Run the async fetch for this key Bukkit.getAsyncScheduler().runNow(ctx.plugin, t -> cachePlayerHeadAsync(next)); } - }, 1, 15); // tick interval per head api lookup + }, 1, 20); // tick interval per head api lookup } }