Created
April 15, 2016 20:14
-
-
Save TheLexoPlexx/ed8afd446c0cfda151640cd0f5ccca00 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| private static ItemStack getItem(String b64stringtexture) { | |
| GameProfile profile = new GameProfile(UUID.randomUUID(), null); | |
| PropertyMap propertyMap = profile.getProperties(); | |
| if (propertyMap == null) { | |
| throw new IllegalStateException("Profile doesn't contain a property map"); | |
| } | |
| propertyMap.put("textures", new Property("textures", b64stringtexture)); | |
| ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); | |
| ItemMeta headMeta = head.getItemMeta(); | |
| Class<?> headMetaClass = headMeta.getClass(); | |
| try { | |
| getField(headMetaClass, "profile", GameProfile.class, 0).set(headMeta, profile); | |
| } catch (IllegalArgumentException e) { | |
| e.printStackTrace(); | |
| } catch (IllegalAccessException e) { | |
| e.printStackTrace(); | |
| } | |
| head.setItemMeta(headMeta); | |
| return head; | |
| } | |
| private static <T> Field getField(Class<?> target, String name, Class<T> fieldType, int index) { | |
| for (final Field field : target.getDeclaredFields()) { | |
| if ((name == null || field.getName().equals(name)) && fieldType.isAssignableFrom(field.getType()) && index-- <= 0) { | |
| field.setAccessible(true); | |
| return field; | |
| } | |
| } | |
| // Search in parent classes | |
| if (target.getSuperclass() != null) | |
| return getField(target.getSuperclass(), name, fieldType, index); | |
| throw new IllegalArgumentException("Cannot find field with type " + fieldType); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment