package org.royaldev.royalcommands.rcommands;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.royaldev.royalcommands.PConfManager;
import org.royaldev.royalcommands.RUtils;
import org.royaldev.royalcommands.RoyalCommands;

public class CmdHelmet implements CommandExecutor {

    RoyalCommands plugin;

    public CmdHelmet(RoyalCommands instance) {
        plugin = instance;
    }

    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("helmet")) {
            if (!plugin.isAuthorized(cs, "rcmds.helmet")) {
                RUtils.dispNoPerms(cs);
                return true;
            }
            if (!(cs instanceof Player)) {
                cs.sendMessage(ChatColor.RED + "This command is only available to players!");
                return true;
            }
            if (args.length < 1) {
                cs.sendMessage(cmd.getDescription());
                return false;
            }
            Player p = (Player) cs;
            PConfManager pcm = new PConfManager(p);
            String name = args[0];
            if (name.trim().equalsIgnoreCase("none")) {
                p.getInventory().setHelmet(null);
                if (plugin.requireHelm) {
                    if (pcm.getString("helmet") != null) {
                        ItemStack stack = RUtils.getItem(pcm.getString("helmet"), 1);
                        p.getInventory().addItem(stack);
                        pcm.set(null, "helmet");
                    }
                }
                p.sendMessage(ChatColor.BLUE + "Removed your helmet.");
                return true;
            }
            ItemStack stack = RUtils.getItem(name, 1);
            if (stack == null) {
                p.sendMessage(ChatColor.RED + "Invalid item name!");
                return true;
            }
            if (plugin.requireHelm) {
                if (!p.getInventory().contains(stack)) {
                    p.sendMessage(ChatColor.RED + "You don't have that item!");
                    return true;
                }
                pcm.setString(stack.getType().name(), "helmet");
                p.getInventory().remove(stack);
            }
            p.getInventory().setHelmet(stack);
            p.sendMessage(ChatColor.BLUE + "Set your helmet to " + ChatColor.GRAY + stack.getType().name().toLowerCase().replace("_", " ") + ChatColor.BLUE + ".");
            return true;
        }
        return false;
    }

}

@@ -398,16 +398,87 @@
 ommands;
+%0Aimport org.royaldev.royalcommands.exceptions.InvalidItemNameException;
 %0A%0Apublic
@@ -1992,32 +1992,541 @@
 tack == null) %7B%0A
+                try %7B%0A                    stack = RUtils.getItemFromAlias(name, 1);%0A                %7D catch (InvalidItemNameException e) %7B%0A                    cs.sendMessage(ChatColor.RED + %22Invalid item name!%22);%0A                    return true;%0A                %7D catch (NullPointerException e) %7B%0A                    cs.sendMessage(ChatColor.RED + %22ItemNameManager was not loaded. Let an administrator know.%22);%0A                    return true;%0A                %7D%0A            %7D%0A            if (stack == null) %7B%0A
                 

Allow item aliases in /helm