001package com.jeff_media.armorequipevent;
002
003import org.bukkit.Material;
004import org.bukkit.inventory.ItemStack;
005
006/**
007 * Represents the different types of armor.
008 *
009 * @author Arnah
010 * @since Jul 30, 2015
011 */
012public enum ArmorType{
013        /**
014         * Represents armor belonging to the helmet slot, e.g. helmets, skulls, and carved pumpkins.
015         */
016        HELMET(5),
017        /**
018         * Represents armor belonging to the chestplate slot, e.g. chestplates and elytras.
019         */
020        CHESTPLATE(6),
021        /**
022         * Represents leggings.
023         */
024        LEGGINGS(7),
025        /**
026         * Represents boots.
027         */
028        BOOTS(8);
029
030        private final int slot;
031
032        ArmorType(int slot){
033                this.slot = slot;
034        }
035
036        /**
037         * Attempts to match the ArmorType for the specified ItemStack.
038         *
039         * @param itemStack The ItemStack to parse the type of.
040         * @return The parsed ArmorType, or null if not found.
041         */
042        public static ArmorType matchType(final ItemStack itemStack){
043                if(ArmorListener.isEmpty(itemStack)) return null;
044                Material type = itemStack.getType();
045                String typeName = type.name();
046                if(typeName.endsWith("_HELMET") || typeName.endsWith("_SKULL") || typeName.endsWith("_HEAD") || type == Material.CARVED_PUMPKIN) return HELMET;
047                else if(typeName.endsWith("_CHESTPLATE") || typeName.equals("ELYTRA")) return CHESTPLATE;
048                else if(typeName.endsWith("_LEGGINGS")) return LEGGINGS;
049                else if(typeName.endsWith("_BOOTS")) return BOOTS;
050                else return null;
051        }
052
053        /**
054         * Returns the raw slot where this piece of armor usually gets equipped
055         * @return Raw slot belonging to this piece of armor
056         */
057        public int getSlot(){
058                return slot;
059        }
060}