summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorSenmori <thesenmori@gmail.com>2017-12-31 21:20:41 +1100
committermd_5 <git@md-5.net>2017-12-31 21:20:41 +1100
commit07afa3d58b1869147b5e6b44e1227001512a68d1 (patch)
tree85aa248f0cf4bfc8631597e47ee7d85d7fb31048 /src/main/java
parent2b5427b390fee05729c8e576be3e1969982f04ad (diff)
downloadbukkit-07afa3d58b1869147b5e6b44e1227001512a68d1.tar
bukkit-07afa3d58b1869147b5e6b44e1227001512a68d1.tar.gz
bukkit-07afa3d58b1869147b5e6b44e1227001512a68d1.tar.lz
bukkit-07afa3d58b1869147b5e6b44e1227001512a68d1.tar.xz
bukkit-07afa3d58b1869147b5e6b44e1227001512a68d1.zip
SPIGOT-355: API for Villager careers
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/entity/Villager.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/entity/Villager.java b/src/main/java/org/bukkit/entity/Villager.java
index 151c2aaf..f2095f61 100644
--- a/src/main/java/org/bukkit/entity/Villager.java
+++ b/src/main/java/org/bukkit/entity/Villager.java
@@ -1,5 +1,9 @@
package org.bukkit.entity;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.LinkedListMultimap;
+import com.google.common.collect.Multimap;
+import java.util.List;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.Merchant;
@@ -24,6 +28,34 @@ public interface Villager extends Ageable, NPC, InventoryHolder, Merchant {
public void setProfession(Profession profession);
/**
+ * Get the current {@link Career} for this Villager.
+ *
+ * @return the {@link Career}
+ */
+ public Career getCareer();
+
+ /**
+ * Set the new {@link Career} for this Villager.
+ * This method will reset the villager's trades to the new career.
+ *
+ * @param career the new career, or null to clear the career to a random one
+ * @throws IllegalArgumentException when the new {@link Career} cannot be
+ * used with this Villager's current {@link Profession}.
+ */
+ public void setCareer(Career career);
+
+ /**
+ * Set the new {@link Career} for this Villager.
+ *
+ * @param career the new career, or null to clear the career to a random one
+ * @param resetTrades true to reset this Villager's trades to the new
+ * career's (if any)
+ * @throws IllegalArgumentException when the new {@link Career} cannot be
+ * used with this Villager's current {@link Profession}.
+ */
+ public void setCareer(Career career, boolean resetTrades);
+
+ /**
* Gets this villager's inventory.
* <br>
* Note that this inventory is not the Merchant inventory, rather, it is the
@@ -108,5 +140,125 @@ public interface Villager extends Ageable, NPC, InventoryHolder, Merchant {
public boolean isZombie() {
return zombie;
}
+
+ /**
+ * Get an immutable list of {@link Career} belonging to this Profession.
+ *
+ * @return an immutable list of careers for this profession, or an empty
+ * map if this Profession has no careers.
+ */
+ public List<Career> getCareers() {
+ return Career.getCareers(this);
+ }
+ }
+
+ /**
+ * The Career of this Villager.
+ * Each {@link Profession} has a set of careers it is applicable to. Each
+ * career dictates the trading options that are generated.
+ */
+ public enum Career {
+ /*
+ NOTE: The Career entries are order-specific. They should be maintained in the numerical order they are used in the CB implementation.
+ (e.g. Farmer careers are 1,2,3,4 so Career should reflect that numerical order in their ordinal status)
+ */
+ // Farmer careers
+ /**
+ * Farmers primarily trade for food-related items.
+ */
+ FARMER(Profession.FARMER),
+ /**
+ * Fisherman primarily trade for fish, as well as possibly selling
+ * string and/or coal.
+ */
+ FISHERMAN(Profession.FARMER),
+ /**
+ * Shepherds primarily trade for wool items, and shears.
+ */
+ SHEPHERD(Profession.FARMER),
+ /**
+ * Fletchers primarily trade for string, bows, and arrows.
+ */
+ FLETCHER(Profession.FARMER),
+ // Librarian careers
+ /**
+ * Librarians primarily trade for paper, books, and enchanted books.
+ */
+ LIBRARIAN(Profession.LIBRARIAN),
+ /**
+ * Cartographers primarily trade for explorer maps and some paper.
+ */
+ CARTOGRAPHER(Profession.LIBRARIAN),
+ // Priest careers
+ /**
+ * Clerics primarily trade for rotten flesh, gold ingot, redstone,
+ * lapis, ender pearl, glowstone, and bottle o' enchanting.
+ */
+ CLERIC(Profession.PRIEST),
+ // Blacksmith careers
+ /**
+ * Armorers primarily trade for iron armor, chainmail armor, and
+ * sometimes diamond armor.
+ */
+ ARMORER(Profession.BLACKSMITH),
+ /**
+ * Weapon smiths primarily trade for iron and diamond weapons, sometimes
+ * enchanted.
+ */
+ WEAPON_SMITH(Profession.BLACKSMITH),
+ /**
+ * Tool smiths primarily trade for iron and diamond tools.
+ */
+ TOOL_SMITH(Profession.BLACKSMITH),
+ // Butcher careers
+ /**
+ * Butchers primarily trade for raw and cooked food.
+ */
+ BUTCHER(Profession.BUTCHER),
+ /**
+ * Leatherworkers primarily trade for leather, and leather armor, as
+ * well as saddles.
+ */
+ LEATHERWORKER(Profession.BUTCHER),
+ // Nitwit
+ /**
+ * Nitwit villagers do not do anything. They do not have any trades by
+ * default.
+ */
+ NITWIT(Profession.NITWIT);
+
+ private static final Multimap<Profession, Career> careerMap = LinkedListMultimap.create();
+ private final Profession profession;
+
+ private Career(Profession profession) {
+ this.profession = profession;
+ }
+
+ /**
+ * Get the {@link Profession} this {@link Career} belongs to.
+ *
+ * @return the {@link Profession}.
+ */
+ public Profession getProfession() {
+ return profession;
+ }
+
+ /**
+ * Get an immutable list of {@link Career}s that can be used with a
+ * given {@link Profession}
+ *
+ * @param profession the profession to get careers for
+ * @return an immutable list of Careers that can be used by a
+ * profession, or an empty map if the profession was not found
+ */
+ public static List<Career> getCareers(Profession profession) {
+ return careerMap.containsKey(profession) ? ImmutableList.copyOf(careerMap.get(profession)) : ImmutableList.<Career>of();
+ }
+
+ static {
+ for (Career career : Career.values()) {
+ careerMap.put(career.profession, career);
+ }
+ }
}
}