import java.lang.reflect.Field;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.craftbukkit.libs.org.apache.commons.codec.binary.Base64;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
/*
* @class Skull , erstellt einen @ItemStack{@SKULL} mit einer @Properties Texture
* @author: ILoveJava
* @version: 1.0
* */
public class Skull {
/*
* Funktion zum erstellen der Köpfe
* @param url{@String} Skull Texture
* @return ItemStack{@SKULL}
* @exception NoSuchFieldException
* @exception IllegalArgumentException
* @exception IllegalAcces***ception
* */
public static ItemStack getSkull(String url) {
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
if(url.isEmpty())return item;
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
try
{
profileField = itemMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(itemMeta, profile);
}
catch (NoSuchFieldException | IllegalArgumentException | IllegalAcces***ception e)
{
e.printStackTrace();
}
item.setItemMeta(itemMeta);
return item;
}
}