Skip to content

Commit 63258b9

Browse files
committed
Fixed skull textures are not showing up in Minecraft 1.21.1
1 parent d35a35f commit 63258b9

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/main/java/me/despical/commons/item/ItemUtils.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@
1818

1919
package me.despical.commons.item;
2020

21+
import com.destroystokyo.paper.profile.PlayerProfile;
22+
import com.destroystokyo.paper.profile.ProfileProperty;
2123
import com.mojang.authlib.GameProfile;
2224
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-
2825
import me.despical.commons.compat.XMaterial;
2926
import me.despical.commons.reflection.XReflection;
3027
import org.bukkit.Bukkit;
3128
import org.bukkit.entity.Player;
3229
import org.bukkit.inventory.ItemStack;
3330
import org.bukkit.inventory.meta.SkullMeta;
3431

32+
import java.lang.reflect.Field;
33+
import java.lang.reflect.Method;
34+
import java.util.UUID;
35+
3536
/**
3637
* @author Despical
3738
* <p>
@@ -59,26 +60,33 @@ public static ItemStack getSkull(String url) {
5960
return head;
6061
}
6162

62-
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
63+
SkullMeta skullMeta = (SkullMeta) head.getItemMeta();
6364
GameProfile profile = new GameProfile(UUID.randomUUID(), XReflection.supports(20) ? "" : null);
64-
6565
profile.getProperties().put("textures", new Property("textures", url));
6666

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)) {
6874
try {
69-
Method method = headMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
75+
Method method = skullMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
7076
method.setAccessible(true);
71-
method.invoke(headMeta, profile);
72-
} catch(Exception ignored) {}
77+
method.invoke(skullMeta, profile);
78+
} catch (Exception ignored) {
79+
}
7380
} else {
7481
try {
75-
Field profileField = headMeta.getClass().getDeclaredField("profile");
82+
Field profileField = skullMeta.getClass().getDeclaredField("profile");
7683
profileField.setAccessible(true);
77-
profileField.set(headMeta, profile);
78-
} catch(Exception ignored) {}
84+
profileField.set(skullMeta, profile);
85+
} catch (Exception ignored) {
86+
}
7987
}
8088

81-
head.setItemMeta(headMeta);
89+
head.setItemMeta(skullMeta);
8290
return head;
8391
}
8492

0 commit comments

Comments
 (0)