


        String owner = "Notch";
        Location loc = new Location(p.getWorld(), 1, 65, 1); //any location
        loc.getBlock().setType(Material.SKULL);
        loc.getBlock().setData((byte) 0x3);
        Skull s = (Skull)loc.getBlock().getState();

        Object nmsWorld = null;
        try {
            nmsWorld = loc.getWorld().getClass().getMethod("getHandle").invoke(loc.getWorld());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        Object tileEntity = null;
        Method getTileEntity = null;
        try {
            getTileEntity = nmsWorld.getClass().getMethod("getTileEntity", blockPositionClass);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        try {
            tileEntity = tileEntityClass.cast(getTileEntity.invoke(nmsWorld, getBlockPositionFor(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        try {
            tileEntityClass.getMethod("setGameProfile", GameProfile.class).invoke(tileEntity, getProfile(U));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        s.setOwner(owner);
        //s.setData((MaterialData) headMeta);
        s.update(true);


    }

    private static GameProfile getProfile(String skinURL) {
        ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);

        SkullMeta headMeta = (SkullMeta) head.getItemMeta();
        GameProfile profile = new GameProfile(UUID.randomUUID(), null);
        byte[] encodedData = base64.encode(String.format("{\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}", skinURL).getBytes());
        profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
        try{
            Field profileField = headMeta.getClass().getDeclaredField("profile");
            profileField.setAccessible(true);
            profileField.set(headMeta, profile);
        }
        catch (IllegalArgumentException|NoSuchFieldException|SecurityException | IllegalAccessException error) {
            error.printStackTrace();
        }
        return profile;
    }

    private static Object getBlockPositionFor(int x, int y, int z) {
        Object blockPosition = null;
        try {
            Constructor<?> cons = blockPositionClass.getConstructor(int.class, int.class, int.class);
            blockPosition = cons.newInstance(x, y, z);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return blockPosition;
    }