Skip to content

Instantly share code, notes, and snippets.

@Cryptite
Created February 15, 2019 18:38
Show Gist options
  • Save Cryptite/e13ce315384fa97205fe1f0536621064 to your computer and use it in GitHub Desktop.
Save Cryptite/e13ce315384fa97205fe1f0536621064 to your computer and use it in GitHub Desktop.
Get Player Head ItemStack from Base64 encoded URL
public static ItemStack getHeadByUrl(String url) {
if (url == null) return new ItemStack(Material.BARRIER);
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
if (url.isEmpty()) return head;
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
GameProfile profile = getGameProfile(url);
Field profileField;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
head.setItemMeta(headMeta);
return head;
}
public static GameProfile getGameProfile(String url) {
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", url));
return profile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment