|
18 | 18 |
|
19 | 19 | package me.despical.commons.item; |
20 | 20 |
|
| 21 | +import com.destroystokyo.paper.profile.PlayerProfile; |
| 22 | +import com.destroystokyo.paper.profile.ProfileProperty; |
21 | 23 | import com.mojang.authlib.GameProfile; |
22 | 24 | import com.mojang.authlib.properties.Property; |
23 | | - |
24 | | -import java.lang.reflect.Field; |
25 | | -import java.lang.reflect.Method; |
26 | | -import java.util.UUID; |
27 | | - |
28 | 25 | import me.despical.commons.compat.XMaterial; |
29 | 26 | import me.despical.commons.reflection.XReflection; |
30 | 27 | import org.bukkit.Bukkit; |
31 | 28 | import org.bukkit.entity.Player; |
32 | 29 | import org.bukkit.inventory.ItemStack; |
33 | 30 | import org.bukkit.inventory.meta.SkullMeta; |
34 | 31 |
|
| 32 | +import java.lang.reflect.Field; |
| 33 | +import java.lang.reflect.Method; |
| 34 | +import java.util.UUID; |
| 35 | + |
35 | 36 | /** |
36 | 37 | * @author Despical |
37 | 38 | * <p> |
@@ -59,26 +60,33 @@ public static ItemStack getSkull(String url) { |
59 | 60 | return head; |
60 | 61 | } |
61 | 62 |
|
62 | | - SkullMeta headMeta = (SkullMeta) head.getItemMeta(); |
| 63 | + SkullMeta skullMeta = (SkullMeta) head.getItemMeta(); |
63 | 64 | GameProfile profile = new GameProfile(UUID.randomUUID(), XReflection.supports(20) ? "" : null); |
64 | | - |
65 | 65 | profile.getProperties().put("textures", new Property("textures", url)); |
66 | 66 |
|
67 | | - if (XReflection.supports(15)) { |
| 67 | + if (XReflection.supports(21, 1)) { |
| 68 | + UUID uuid = UUID.randomUUID(); |
| 69 | + PlayerProfile playerProfile = Bukkit.getServer().createProfile(UUID.randomUUID(), uuid.toString().substring(0, 16)); |
| 70 | + playerProfile.setProperty(new ProfileProperty("textures", url)); |
| 71 | + |
| 72 | + skullMeta.setPlayerProfile(playerProfile); |
| 73 | + } else if (XReflection.supports(15)) { |
68 | 74 | try { |
69 | | - Method method = headMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class); |
| 75 | + Method method = skullMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class); |
70 | 76 | method.setAccessible(true); |
71 | | - method.invoke(headMeta, profile); |
72 | | - } catch(Exception ignored) {} |
| 77 | + method.invoke(skullMeta, profile); |
| 78 | + } catch (Exception ignored) { |
| 79 | + } |
73 | 80 | } else { |
74 | 81 | try { |
75 | | - Field profileField = headMeta.getClass().getDeclaredField("profile"); |
| 82 | + Field profileField = skullMeta.getClass().getDeclaredField("profile"); |
76 | 83 | profileField.setAccessible(true); |
77 | | - profileField.set(headMeta, profile); |
78 | | - } catch(Exception ignored) {} |
| 84 | + profileField.set(skullMeta, profile); |
| 85 | + } catch (Exception ignored) { |
| 86 | + } |
79 | 87 | } |
80 | 88 |
|
81 | | - head.setItemMeta(headMeta); |
| 89 | + head.setItemMeta(skullMeta); |
82 | 90 | return head; |
83 | 91 | } |
84 | 92 |
|
|
0 commit comments