Java Code Examples for org.bukkit.inventory.meta.ItemMeta#getClass()

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkinsGUI.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
private void setSkin(ItemStack head, 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));
    ItemMeta headMeta = head.getItemMeta();
    Class<?> headMetaClass = headMeta.getClass();
    try {
        ReflectionUtil.getField(headMetaClass, "profile", GameProfile.class, 0).set(headMeta, profile);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
    head.setItemMeta(headMeta);
}
 
Example 2
Source File: SkullHandler.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return a skull that has a custom texture specified by url.
 *
 * @param url
 *            skin url
 * @return itemstack
 */
@SuppressWarnings("deprecation")
public static ItemStack getCustomSkull64(byte[] url64) {

	GameProfile profile = new GameProfile(UUID.randomUUID(), null);
	PropertyMap propertyMap = profile.getProperties();
	if (propertyMap == null) {
		throw new IllegalStateException("Profile doesn't contain a property map");
	}
	String encodedData = new String(url64);
	propertyMap.put("textures", new Property("textures", encodedData));
	ItemStack head = new ItemStack(MultiVersionLookup.getSkull(), 1, (short) 3);
	ItemMeta headMeta = head.getItemMeta();
	Class<?> headMetaClass = headMeta.getClass();
	ReflectionsUtil.getField(headMetaClass, "profile", GameProfile.class).set(headMeta, profile);
	head.setItemMeta(headMeta);
	return head;
}
 
Example 3
Source File: SkullHandler.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
public static String getURL(ItemStack is) {
	if (is.getType() !=MultiVersionLookup.getSkull())
		return null;
	ItemMeta headMeta = is.getItemMeta();
	Class<?> headMetaClass = headMeta.getClass();
	GameProfile prof = ReflectionsUtil.getField(headMetaClass, "profile", GameProfile.class).get(headMeta);
	PropertyMap propertyMap = prof.getProperties();
	Collection<Property> textures64 = propertyMap.get("textures");
	String tex64 = null;
	for (Property p : textures64) {
		if (p.getName().equals("textures")) {
			tex64 = p.getValue();
			break;
		}
	}
	if (tex64 != null) {
	    byte[] decode = null;
		decode = Base64.getDecoder().decode(tex64);
		String string = new String(decode);
		String parsed = string.split("SKIN:{url:\"")[1].split("\"}}}")[0];
		return parsed;
	}
	return null;
}
 
Example 4
Source File: SkullHandler.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
public static String getURL64(ItemStack is) {
	if (is.getType() != MultiVersionLookup.getSkull())
		return null;
	ItemMeta headMeta = is.getItemMeta();
	Class<?> headMetaClass = headMeta.getClass();
	GameProfile prof = ReflectionsUtil.getField(headMetaClass, "profile", GameProfile.class).get(headMeta);
	PropertyMap propertyMap = prof.getProperties();
	Collection<Property> textures64 = propertyMap.get("textures");
	String tex64 = null;
	for (Property p : textures64) {
		if (p.getName().equals("textures")) {
			tex64 = p.getValue();
			break;
		}
	}
	if (tex64 != null) {
		return tex64;
	}
	return null;
}