Solved How to setBlock Skull with Skin?

Discussion in 'Spigot Plugin Development' started by KohakuSaintCrown, May 21, 2016.

  1. Hello, i need know how set block but a skull and skin include.

    b.getLocation().getBlock().setType(Material.SKULL); //is not working..
     
  2. SkullMeta allows you to set the metadata of the block
     
    • Agree Agree x 1
  3. but that code is not working is not placing a skull in the ground
     
  4. Code (Text):
    ItemStack skull = new ItemStack(Material.SKULL_ITEM);
            SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
            skullMeta.setOwner("Players skin");
            skull.setItemMeta(skullMeta);
     
  5. Choco

    Moderator

    1. b.getLocation().getBlock() - Unless your naming conventions are horrible, why are you getting a block's location then getting the block again? Is b a Block? If it is, just get rid of getLocation().getBlock(). - b.setType(Material.SKULL);
    2. Cast the state to a Skull,
    Code (Java):
    Skull skull = (Skull) b.getState();
    skull.setOwner("2008Choco");
     
  6. Thanks guys is solved, im using this code thanks for you help
    Code (Text):

                                    Block Head = w.getBlockAt(X, Y, Z);
                                    Head.setType(Material.SKULL);
                                    Head.setData((byte) 0x1);
                                    BlockState state = Head.getState();
                                    if (state instanceof Skull) {
                                        Skull skull = (Skull) state;
                                        skull.setRotation(BlockFace.NORTH);
                                        skull.setSkullType(SkullType.PLAYER);
                                        skull.setOwner(p.getName);
                                        skull.update();
                                    }
     
    • Like Like x 1
    • Useful Useful x 1