Created
February 15, 2019 18:38
-
-
Save Cryptite/e13ce315384fa97205fe1f0536621064 to your computer and use it in GitHub Desktop.
Get Player Head ItemStack from Base64 encoded URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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