From 716263b77b6df6e36c1c6f3bc0b8b8f36b2983bb Mon Sep 17 00:00:00 2001 From: Archy-X <63976867+Archy-X@users.noreply.github.com> Date: Mon, 6 Jan 2025 12:38:03 +0800 Subject: [PATCH] Fix skull profile missing error when opening leaderboard menu --- .../bukkit/menus/LeaderboardMenu.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/LeaderboardMenu.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/LeaderboardMenu.java index d91973924..8a44578f2 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/LeaderboardMenu.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/menus/LeaderboardMenu.java @@ -15,6 +15,7 @@ import java.util.Map; import java.util.UUID; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -59,10 +60,24 @@ public void build(MenuBuilder menu) { if (t.item().getItemMeta() instanceof SkullMeta meta) { if (VersionUtils.isAtLeastVersion(18, 1)) { PlayerProfile profile = Bukkit.createPlayerProfile(value.id()); - meta.setOwnerProfile(profile); + if (profile.isComplete()) { + meta.setOwnerProfile(profile); + } else { + profile.update() + .thenAcceptAsync(updated -> { + if (profile.isComplete()) { + meta.setOwnerProfile(updated); + t.item().setItemMeta(meta); + } else { + setLegacySkullPlayer(meta, value); + t.item().setItemMeta(meta); + } + }, r -> plugin.getScheduler().executeSync(r)) + .orTimeout(4000, TimeUnit.MILLISECONDS) + .exceptionally(e -> null); + } } else { - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(value.id()); - meta.setOwningPlayer(offlinePlayer); + setLegacySkullPlayer(meta, value); } t.item().setItemMeta(meta); } @@ -70,4 +85,9 @@ public void build(MenuBuilder menu) { }); }); } + + private void setLegacySkullPlayer(SkullMeta meta, SkillValue value) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(value.id()); + meta.setOwningPlayer(offlinePlayer); + } } \ No newline at end of file