Making a player's "helmet" a certain player's head?

Discussion in 'Plugin Development' started by C0nsole, May 6, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    C0nsole

    How to do I set a player's "helmet" to be another player's head? I tried the following, but it gave me a skeleton skull as my head:
    Code:
    ItemStack skull = new ItemStack(Material.SKULL_ITEM);
                        SkullMeta meta3 = (SkullMeta) skull.getItemMeta();
                        meta3.setOwner("garrett2smart87");
                        skull.setItemMeta(meta3);
                        player.getInventory().setHelmet(skull);
     
  2. Offline

    chasechocolate

  3. Offline

    C0nsole

    chasechocolate
    Thanks! I'll look there first next time!

    Totally changed the thread :p different thing entirely
    Didn't want to make a new thread :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    FuZioN720

    Can we seen your class?
     
  5. Offline

    C0nsole

    FuZioN720
    Don't know why this is necessary, nor did I want to do this, but here.
    Code:
    package me.C0nsole.BeSuperman;
     
     
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class BeSuperman extends JavaPlugin{
       
        @Override
        public void onDisable() {
            System.out.println("[BeSuperman] v1.0 has been disabled.");
        }
     
        @Override
        public void onEnable() {
            System.out.println("[BeSuperman] v1.0 has been enabled.");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String [] args){
            Player player = (Player) sender;
            if(commandlabel.equalsIgnoreCase("supermanon")){
                if(player.hasPermission("superman.use")){
                    player.setMaxHealth(100);
                    Inventory inv = player.getInventory();
                    if(inv instanceof PlayerInventory){
                        ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
                        LeatherArmorMeta meta = (LeatherArmorMeta) boots.getItemMeta();
                        meta.setColor(Color.RED);
                        boots.setItemMeta(meta);
                        player.getInventory().setBoots(boots);
                        ItemStack pants = new ItemStack(Material.LEATHER_LEGGINGS);
                        LeatherArmorMeta meta1 = (LeatherArmorMeta) pants.getItemMeta();
                        meta1.setColor(Color.BLUE);
                        pants.setItemMeta(meta1);
                        player.getInventory().setLeggings(pants);
                        ItemStack shirt = new ItemStack(Material.LEATHER_CHESTPLATE);
                        LeatherArmorMeta meta2 = (LeatherArmorMeta) shirt.getItemMeta();
                        meta2.setColor(Color.BLUE);
                        shirt.setItemMeta(meta2);
                        player.getInventory().setChestplate(shirt);
                        ItemStack skull = new ItemStack(Material.SKULL_ITEM);
                        SkullMeta meta3 = (SkullMeta) skull.getItemMeta();
                        meta3.setOwner("garrett2smart87");
                        skull.setItemMeta(meta3);
                        player.getInventory().setHelmet(skull);
                        }
                    player.setAllowFlight(true);
                    player.setFlying(true);
                }
            }
            return false;
        }
    }
    
     
  6. Offline

    FuZioN720

    I was making sure that it didn't have to do with other code and i don't know whats going on sorry, You can edit that reply if you dont want anyone to see your code, but this section noone should.

    See if this helps

    ItemStack:
    Code:
    SkullMeta meta = (SkullMeta)skullStack.getItemMeta();
    meta.setOwner("Fireblast709");
    skullStack.setItemMeta(meta);
    Skull block:
    Code:
    org.bukkit.block.Skull skull = (org.bukkit.block.Skull)skullBlock.getState();
    skull.setSkullType(SkullType.PLAYER);
    skull.setOwner("Fireblast709");
    skull.update();
    I don't think this matters but in your code
    Code:
    SkullMeta meta3 = (SkullMeta) skull.getItemMeta();
    is there suppose to be a space after the ) in skullmeta. Or does it need to be this
    Code:
    SkullMeta meta3 = (SkullMeta)skull.getItemMeta();
    I know i'm posting a lot but i'm trying to help. Here is another function that might work if you implement it some how.

    Code:
     private ItemStack playerSkullForName(String name)
      {
        ItemStack is = new ItemStack(Material.SKULL_ITEM, 1);
        is.setDurability((short)3);
        SkullMeta meta = (SkullMeta)is.getItemMeta();
        meta.setOwner(name);
        is.setItemMeta(meta);
        return is;
      }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  7. Offline

    C0nsole

    FuZioN720
    Have to go right now but will try this at some point tomorrow and get back to you with results. Thanks!

    FuZioN720
    I got it working, but I'm not sure it's what you said. It was this,
    Code:
                ItemStack skull = new ItemStack(397, 1, (short) 3);
                         SkullMeta meta3 = (SkullMeta) skull.getItemMeta();
                         meta3.setOwner("garrett2smart87");
                         skull.setItemMeta(meta3);
                         player.getInventory().setHelmet(skull);
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  8. Offline

    FuZioN720

    Well if it was or not congrats on the achievement
     
  9. Offline

    WolfLeader116

    FuZioN720 C0nsole Is there any way to use the code above, but make it so that it's a command such as /head <player> <head name> so that when HeroOfTime500 types /head WolfLeader116 Notch for example, I get Notch's head in my head slot? So I could do /head Notch Dinnerbone and then Notch would have Dinnerbone's head in his head slot.
     
  10. Offline

    Garris0n

    WolfLeader116
    1. This thread is a year old.
    2. Yes, of course there is. Make a command in which you spawn a head item, set the meta, and put it on the player's head.
     
    iPoke111 likes this.
  11. Offline

    WolfLeader116

    Garris0n
    1. I know that this thread is a year old, but it would be useless to make another thread when I could just use this to ask because it is very related.
    2. That does not exactly answer my question about making a command that puts a certain specified head on a specified player.
     
  12. Offline

    iPoke111

    WolfLeader116
    That precisely answers your question. Maybe not with an example, but he said 'Of course there is' to 'Is there a way to', which is perfectly valid. In any case, what Garris0n is saying is right.
     
    Garris0n likes this.
  13. Offline

    Garris0n

    You asked if it could be done. I said yes. That answered your question. I'm not going to write the code for you. If you can't do it, start with something simpler.
     
    HungryThirstyDead likes this.
  14. Get Owned WolfLeader xD
     
Thread Status:
Not open for further replies.

Share This Page