Commits
Senmori authored and md_5 committed 07afa3d58b1
1 1 | package org.bukkit.entity; |
2 2 | |
3 + | import com.google.common.collect.ImmutableList; |
4 + | import com.google.common.collect.LinkedListMultimap; |
5 + | import com.google.common.collect.Multimap; |
6 + | import java.util.List; |
3 7 | import org.bukkit.inventory.Inventory; |
4 8 | import org.bukkit.inventory.InventoryHolder; |
5 9 | import org.bukkit.inventory.Merchant; |
6 10 | |
7 11 | /** |
8 12 | * Represents a villager NPC |
9 13 | */ |
10 14 | public interface Villager extends Ageable, NPC, InventoryHolder, Merchant { |
11 15 | |
12 16 | /** |
16 20 | */ |
17 21 | public Profession getProfession(); |
18 22 | |
19 23 | /** |
20 24 | * Sets the new profession of this villager. |
21 25 | * |
22 26 | * @param profession New profession. |
23 27 | */ |
24 28 | public void setProfession(Profession profession); |
25 29 | |
30 + | /** |
31 + | * Get the current {@link Career} for this Villager. |
32 + | * |
33 + | * @return the {@link Career} |
34 + | */ |
35 + | public Career getCareer(); |
36 + | |
37 + | /** |
38 + | * Set the new {@link Career} for this Villager. |
39 + | * This method will reset the villager's trades to the new career. |
40 + | * |
41 + | * @param career the new career, or null to clear the career to a random one |
42 + | * @throws IllegalArgumentException when the new {@link Career} cannot be |
43 + | * used with this Villager's current {@link Profession}. |
44 + | */ |
45 + | public void setCareer(Career career); |
46 + | |
47 + | /** |
48 + | * Set the new {@link Career} for this Villager. |
49 + | * |
50 + | * @param career the new career, or null to clear the career to a random one |
51 + | * @param resetTrades true to reset this Villager's trades to the new |
52 + | * career's (if any) |
53 + | * @throws IllegalArgumentException when the new {@link Career} cannot be |
54 + | * used with this Villager's current {@link Profession}. |
55 + | */ |
56 + | public void setCareer(Career career, boolean resetTrades); |
57 + | |
26 58 | /** |
27 59 | * Gets this villager's inventory. |
28 60 | * <br> |
29 61 | * Note that this inventory is not the Merchant inventory, rather, it is the |
30 62 | * items that a villager might have collected (from harvesting crops, etc.) |
31 63 | * |
32 64 | * {@inheritDoc} |
33 65 | */ |
34 66 | |
35 67 | Inventory getInventory(); |
101 133 | /** |
102 134 | * Returns if this profession can only be used by zombies. |
103 135 | * |
104 136 | * @return zombie profession status |
105 137 | * @deprecated Unused |
106 138 | */ |
107 139 | |
108 140 | public boolean isZombie() { |
109 141 | return zombie; |
110 142 | } |
143 + | |
144 + | /** |
145 + | * Get an immutable list of {@link Career} belonging to this Profession. |
146 + | * |
147 + | * @return an immutable list of careers for this profession, or an empty |
148 + | * map if this Profession has no careers. |
149 + | */ |
150 + | public List<Career> getCareers() { |
151 + | return Career.getCareers(this); |
152 + | } |
153 + | } |
154 + | |
155 + | /** |
156 + | * The Career of this Villager. |
157 + | * Each {@link Profession} has a set of careers it is applicable to. Each |
158 + | * career dictates the trading options that are generated. |
159 + | */ |
160 + | public enum Career { |
161 + | /* |
162 + | NOTE: The Career entries are order-specific. They should be maintained in the numerical order they are used in the CB implementation. |
163 + | (e.g. Farmer careers are 1,2,3,4 so Career should reflect that numerical order in their ordinal status) |
164 + | */ |
165 + | // Farmer careers |
166 + | /** |
167 + | * Farmers primarily trade for food-related items. |
168 + | */ |
169 + | FARMER(Profession.FARMER), |
170 + | /** |
171 + | * Fisherman primarily trade for fish, as well as possibly selling |
172 + | * string and/or coal. |
173 + | */ |
174 + | FISHERMAN(Profession.FARMER), |
175 + | /** |
176 + | * Shepherds primarily trade for wool items, and shears. |
177 + | */ |
178 + | SHEPHERD(Profession.FARMER), |
179 + | /** |
180 + | * Fletchers primarily trade for string, bows, and arrows. |
181 + | */ |
182 + | FLETCHER(Profession.FARMER), |
183 + | // Librarian careers |
184 + | /** |
185 + | * Librarians primarily trade for paper, books, and enchanted books. |
186 + | */ |
187 + | LIBRARIAN(Profession.LIBRARIAN), |
188 + | /** |
189 + | * Cartographers primarily trade for explorer maps and some paper. |
190 + | */ |
191 + | CARTOGRAPHER(Profession.LIBRARIAN), |
192 + | // Priest careers |
193 + | /** |
194 + | * Clerics primarily trade for rotten flesh, gold ingot, redstone, |
195 + | * lapis, ender pearl, glowstone, and bottle o' enchanting. |
196 + | */ |
197 + | CLERIC(Profession.PRIEST), |
198 + | // Blacksmith careers |
199 + | /** |
200 + | * Armorers primarily trade for iron armor, chainmail armor, and |
201 + | * sometimes diamond armor. |
202 + | */ |
203 + | ARMORER(Profession.BLACKSMITH), |
204 + | /** |
205 + | * Weapon smiths primarily trade for iron and diamond weapons, sometimes |
206 + | * enchanted. |
207 + | */ |
208 + | WEAPON_SMITH(Profession.BLACKSMITH), |
209 + | /** |
210 + | * Tool smiths primarily trade for iron and diamond tools. |
211 + | */ |
212 + | TOOL_SMITH(Profession.BLACKSMITH), |
213 + | // Butcher careers |
214 + | /** |
215 + | * Butchers primarily trade for raw and cooked food. |
216 + | */ |
217 + | BUTCHER(Profession.BUTCHER), |
218 + | /** |
219 + | * Leatherworkers primarily trade for leather, and leather armor, as |
220 + | * well as saddles. |
221 + | */ |
222 + | LEATHERWORKER(Profession.BUTCHER), |
223 + | // Nitwit |
224 + | /** |
225 + | * Nitwit villagers do not do anything. They do not have any trades by |
226 + | * default. |
227 + | */ |
228 + | NITWIT(Profession.NITWIT); |
229 + | |
230 + | private static final Multimap<Profession, Career> careerMap = LinkedListMultimap.create(); |
231 + | private final Profession profession; |
232 + | |
233 + | private Career(Profession profession) { |
234 + | this.profession = profession; |
235 + | } |
236 + | |
237 + | /** |
238 + | * Get the {@link Profession} this {@link Career} belongs to. |
239 + | * |
240 + | * @return the {@link Profession}. |
241 + | */ |
242 + | public Profession getProfession() { |
243 + | return profession; |
244 + | } |
245 + | |
246 + | /** |
247 + | * Get an immutable list of {@link Career}s that can be used with a |
248 + | * given {@link Profession} |
249 + | * |
250 + | * @param profession the profession to get careers for |
251 + | * @return an immutable list of Careers that can be used by a |
252 + | * profession, or an empty map if the profession was not found |
253 + | */ |
254 + | public static List<Career> getCareers(Profession profession) { |
255 + | return careerMap.containsKey(profession) ? ImmutableList.copyOf(careerMap.get(profession)) : ImmutableList.<Career>of(); |
256 + | } |
257 + | |
258 + | static { |
259 + | for (Career career : Career.values()) { |
260 + | careerMap.put(career.profession, career); |
261 + | } |
262 + | } |
111 263 | } |
112 264 | } |