Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
EnchantmentTarget.java
1 package org.bukkit.enchantments;
2 
3 import org.bukkit.Material;
5 
6 /**
7  * Represents the applicable target for a {@link Enchantment}
8  */
9 public enum EnchantmentTarget {
10  /**
11  * Allows the Enchantment to be placed on all items
12  */
13  ALL {
14  @Override
15  public boolean includes(Material item) {
16  return true;
17  }
18  },
19 
20  /**
21  * Allows the Enchantment to be placed on armor
22  */
23  ARMOR {
24  @Override
25  public boolean includes(Material item) {
26  return ARMOR_FEET.includes(item)
27  || ARMOR_LEGS.includes(item)
28  || ARMOR_HEAD.includes(item)
29  || ARMOR_TORSO.includes(item);
30  }
31  },
32 
33  /**
34  * Allows the Enchantment to be placed on feet slot armor
35  */
36  ARMOR_FEET {
37  @Override
38  public boolean includes(Material item) {
39  return item.equals(Material.LEATHER_BOOTS)
40  || item.equals(Material.CHAINMAIL_BOOTS)
41  || item.equals(Material.IRON_BOOTS)
42  || item.equals(Material.DIAMOND_BOOTS)
43  || item.equals(Material.GOLD_BOOTS);
44  }
45  },
46 
47  /**
48  * Allows the Enchantment to be placed on leg slot armor
49  */
50  ARMOR_LEGS {
51  @Override
52  public boolean includes(Material item) {
53  return item.equals(Material.LEATHER_LEGGINGS)
54  || item.equals(Material.CHAINMAIL_LEGGINGS)
55  || item.equals(Material.IRON_LEGGINGS)
56  || item.equals(Material.DIAMOND_LEGGINGS)
57  || item.equals(Material.GOLD_LEGGINGS);
58  }
59  },
60 
61  /**
62  * Allows the Enchantment to be placed on torso slot armor
63  */
64  ARMOR_TORSO {
65  @Override
66  public boolean includes(Material item) {
67  return item.equals(Material.LEATHER_CHESTPLATE)
68  || item.equals(Material.CHAINMAIL_CHESTPLATE)
69  || item.equals(Material.IRON_CHESTPLATE)
70  || item.equals(Material.DIAMOND_CHESTPLATE)
71  || item.equals(Material.GOLD_CHESTPLATE);
72  }
73  },
74 
75  /**
76  * Allows the Enchantment to be placed on head slot armor
77  */
78  ARMOR_HEAD {
79  @Override
80  public boolean includes(Material item) {
81  return item.equals(Material.LEATHER_HELMET)
82  || item.equals(Material.CHAINMAIL_HELMET)
83  || item.equals(Material.DIAMOND_HELMET)
84  || item.equals(Material.IRON_HELMET)
85  || item.equals(Material.GOLD_HELMET);
86  }
87  },
88 
89  /**
90  * Allows the Enchantment to be placed on weapons (swords)
91  */
92  WEAPON {
93  @Override
94  public boolean includes(Material item) {
95  return item.equals(Material.WOOD_SWORD)
96  || item.equals(Material.STONE_SWORD)
97  || item.equals(Material.IRON_SWORD)
98  || item.equals(Material.DIAMOND_SWORD)
99  || 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 }