How to set a players Helmet as a Golden Helmet?

Discussion in 'Plugin Development' started by Jag.1000, Aug 3, 2012.

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

    Jag.1000

    Code:
    if(cmd.getName().equalsIgnoreCase("king")){
                if(sender instanceof Player){
                    if(!permCheck((Player)sender, "heir.king")){
                        sender.sendMessage(ChatColor.RED+ "You do not have Permission.");
                        return true;
                    }
                }
               
               
               
               
                Player king = getServer().getPlayer(args[0]);
                king.setHelmet(Material.GOLD_HELMET);
                        Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "Long live " + king.getName() + "! Long live the new King!");
                        return true;
           
           
            }

    Theres an error on setHelmet when I do this. How could I fix it?
     
  2. Offline

    Malikk

    I think it takes an ItemStack, not a Material. Also, you'll need to use getInventory() before you can use setHelmet()

    Code:
    king.getInventory().setHelmet(new ItemStack(Material.GOLD_HELMET, 1));
    
     
  3. Offline

    Jag.1000

    Error- The method setHelmet(ItemStack) in the type PlayerInventory is not applicable for the arguments(ItemStack)
     
  4. Offline

    Malikk

    It's not getting any errors in my eclipse.

    Try making an itemstack object, rather than New ItemStack directly in there

    EDIT: That error doesn't even make sense, it says it takes an ItemStack but ItemStack is invalid?
     
  5. Offline

    d0de

    Something like this

    Code:
    ItemStack is = new ItemStack(Material.GOLD_HELMET, 1)
     
     
    king.getInventory().setHelmet(is);
    EDIT : Also make sure u import ItemStack from Bukkit.
     
    Jag.1000 likes this.
  6. Offline

    Jag.1000

    Code:
    if(cmd.getName().equalsIgnoreCase("king")){
                if(sender instanceof Player){
                    if(!permCheck((Player)sender, "heir.king")){
                        sender.sendMessage(ChatColor.RED+ "You do not have Permission.");
                        return true;
                    }
                }
               
               
               
               
                Player king = getServer().getPlayer(args[0]);
               
                king.getInventory().setHelmet(new ItemStack(Material.GOLD_HELMET, 1));
     
     
                        Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "Long live " + king.getName() + "! Long live the new King!");
                        return true;
           
           
            }
            
    Am I putting it in the wrong spot?
     
  7. Offline

    Malikk

    Does it throw the same error if you replace
    Code:
     king.getInventory().setHelmet(new ItemStack(Material.GOLD_HELMET, 1));
    
    with

    Code:
    ItemStack crown = new ItemStack(Material.GOLD_HELMET, 1);
    king.getInventory().setHelmet(crown);
    
    Also, double check that you've imported ItemStack
     
    anthonyc39 likes this.
  8. Offline

    Jag.1000

    I imported the minecraft.net ItemStack on accident... I feel like an idiot....
    Well thank you a lot!
     
    anthonyc39 likes this.
  9. Offline

    Malikk

    Ah, that makes a lot of sense
     
  10. Offline

    DealerNextDoor

    I was just looking at that and it was just bothering me... declaring an object that is tagged or just initialized as you need it doesn't really make a difference on if the method will take that specific variable or not.
     
Thread Status:
Not open for further replies.

Share This Page