001 package org.bukkit.enchantments; 002 003 import org.bukkit.Material; 004 import org.bukkit.inventory.ItemStack; 005 006 /** 007 * Represents the applicable target for a {@link Enchantment} 008 */ 009 public enum EnchantmentTarget { 010 /** 011 * Allows the Enchantment to be placed on all items 012 */ 013 ALL { 014 @Override 015 public boolean includes(Material item) { 016 return true; 017 } 018 }, 019 020 /** 021 * Allows the Enchantment to be placed on armor 022 */ 023 ARMOR { 024 @Override 025 public boolean includes(Material item) { 026 return ARMOR_FEET.includes(item) 027 || ARMOR_LEGS.includes(item) 028 || ARMOR_HEAD.includes(item) 029 || ARMOR_TORSO.includes(item); 030 } 031 }, 032 033 /** 034 * Allows the Enchantment to be placed on feet slot armor 035 */ 036 ARMOR_FEET { 037 @Override 038 public boolean includes(Material item) { 039 return item.equals(Material.LEATHER_BOOTS) 040 || item.equals(Material.CHAINMAIL_BOOTS) 041 || item.equals(Material.IRON_BOOTS) 042 || item.equals(Material.DIAMOND_BOOTS) 043 || item.equals(Material.GOLD_BOOTS); 044 } 045 }, 046 047 /** 048 * Allows the Enchantment to be placed on leg slot armor 049 */ 050 ARMOR_LEGS { 051 @Override 052 public boolean includes(Material item) { 053 return item.equals(Material.LEATHER_LEGGINGS) 054 || item.equals(Material.CHAINMAIL_LEGGINGS) 055 || item.equals(Material.IRON_LEGGINGS) 056 || item.equals(Material.DIAMOND_LEGGINGS) 057 || item.equals(Material.GOLD_LEGGINGS); 058 } 059 }, 060 061 /** 062 * Allows the Enchantment to be placed on torso slot armor 063 */ 064 ARMOR_TORSO { 065 @Override 066 public boolean includes(Material item) { 067 return item.equals(Material.LEATHER_CHESTPLATE) 068 || item.equals(Material.CHAINMAIL_CHESTPLATE) 069 || item.equals(Material.IRON_CHESTPLATE) 070 || item.equals(Material.DIAMOND_CHESTPLATE) 071 || item.equals(Material.GOLD_CHESTPLATE); 072 } 073 }, 074 075 /** 076 * Allows the Enchantment to be placed on head slot armor 077 */ 078 ARMOR_HEAD { 079 @Override 080 public boolean includes(Material item) { 081 return item.equals(Material.LEATHER_HELMET) 082 || item.equals(Material.CHAINMAIL_HELMET) 083 || item.equals(Material.DIAMOND_HELMET) 084 || item.equals(Material.IRON_HELMET) 085 || item.equals(Material.GOLD_HELMET); 086 } 087 }, 088 089 /** 090 * Allows the Enchantment to be placed on weapons (swords) 091 */ 092 WEAPON { 093 @Override 094 public boolean includes(Material item) { 095 return item.equals(Material.WOOD_SWORD) 096 || item.equals(Material.STONE_SWORD) 097 || item.equals(Material.IRON_SWORD) 098 || item.equals(Material.DIAMOND_SWORD) 099 || item.equals(Material.GOLD_SWORD); 100 } 101 }, 102 103 /** 104 * Allows the Enchantment to be placed on tools (spades, pickaxe, hoes, 105 * axes) 106 */ 107 TOOL { 108 @Override 109 public boolean includes(Material item) { 110 return item.equals(Material.WOOD_SPADE) 111 || item.equals(Material.STONE_SPADE) 112 || item.equals(Material.IRON_SPADE) 113 || item.equals(Material.DIAMOND_SPADE) 114 || item.equals(Material.GOLD_SPADE) 115 || item.equals(Material.WOOD_PICKAXE) 116 || item.equals(Material.STONE_PICKAXE) 117 || item.equals(Material.IRON_PICKAXE) 118 || item.equals(Material.DIAMOND_PICKAXE) 119 || item.equals(Material.GOLD_PICKAXE) 120 || item.equals(Material.WOOD_HOE) // NOTE: No vanilla enchantments for this 121 || item.equals(Material.STONE_HOE) // NOTE: No vanilla enchantments for this 122 || item.equals(Material.IRON_HOE) // NOTE: No vanilla enchantments for this 123 || item.equals(Material.DIAMOND_HOE) // NOTE: No vanilla enchantments for this 124 || item.equals(Material.GOLD_HOE) // NOTE: No vanilla enchantments for this 125 || item.equals(Material.WOOD_AXE) 126 || item.equals(Material.STONE_AXE) 127 || item.equals(Material.IRON_AXE) 128 || item.equals(Material.DIAMOND_AXE) 129 || item.equals(Material.GOLD_AXE) 130 || item.equals(Material.SHEARS) // NOTE: No vanilla enchantments for this 131 || item.equals(Material.FLINT_AND_STEEL); // NOTE: No vanilla enchantments for this 132 } 133 }, 134 135 /** 136 * Allows the Enchantment to be placed on bows. 137 */ 138 BOW { 139 @Override 140 public boolean includes(Material item) { 141 return item.equals(Material.BOW); 142 } 143 }, 144 145 /** 146 * Allows the Enchantment to be placed on fishing rods. 147 */ 148 FISHING_ROD { 149 @Override 150 public boolean includes(Material item) { 151 return item.equals(Material.FISHING_ROD); 152 } 153 }; 154 155 /** 156 * Check whether this target includes the specified item. 157 * 158 * @param item The item to check 159 * @return True if the target includes the item 160 */ 161 public abstract boolean includes(Material item); 162 163 /** 164 * Check whether this target includes the specified item. 165 * 166 * @param item The item to check 167 * @return True if the target includes the item 168 */ 169 public boolean includes(ItemStack item) { 170 return includes(item.getType()); 171 } 172 }