mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-21 23:51:42 +01:00
Add Villager variants, pt 1
This commit is contained in:
parent
72ca629cf1
commit
7790f8818b
@ -8,17 +8,11 @@ import org.bukkit.entity.Villager;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MobCompat {
|
||||
|
||||
public static final EntityType CAT = EnumUtil.getEntityType("CAT", "OCELOT");
|
||||
|
||||
private static Class catClass = null;
|
||||
private static Class catTypeClass = null;
|
||||
private static Method catSetTypeMethod = null;
|
||||
private static Boolean isNewCat = null;
|
||||
|
||||
public enum CatType {
|
||||
SIAMESE("SIAMESE", "SIAMESE_CAT"),
|
||||
WHITE("WHITE", "SIAMESE_CAT"),
|
||||
@ -42,6 +36,60 @@ public class MobCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public enum VillagerProfession {
|
||||
NONE("FARMER", "FARMER", "NONE"),
|
||||
ARMORER("BLACKSMITH", "ARMORER"),
|
||||
BUTCHER("FARMER", "BUTCHER"),
|
||||
CARTOGRAPHER("LIBRARIAN", "CARTOGRAPHER"),
|
||||
CLERIC("PRIEST", "CLERIC"),
|
||||
FARMER("FARMER", "FARMER"),
|
||||
FISHERMAN("FARMER", "FISHERMAN"),
|
||||
FLETCHER("FARMER", "FLETCHER"),
|
||||
LEATHERWORKER("BUTCHER", "LEATHERWORKER"),
|
||||
LIBRARIAN("LIBRARIAN", "LIBRARIAN"),
|
||||
MASON(null, null, "MASON"),
|
||||
NITWIT("NITWIT", "NITWIT"),
|
||||
SHEPHERD("FARMER", "SHEPHERD"),
|
||||
TOOLSMITH("BLACKSMITH", "TOOL_SMITH", "TOOLSMITH"),
|
||||
WEAPONSMITH("BLACKSMITH", "WEAPON_SMITH", "WEAPONSMITH")
|
||||
;
|
||||
|
||||
private String oldProfession;
|
||||
private String oldCareer;
|
||||
private String newProfession;
|
||||
|
||||
VillagerProfession(final String oldProfession, final String career) {
|
||||
this.oldProfession = oldProfession;
|
||||
this.oldCareer = career;
|
||||
this.newProfession = career;
|
||||
}
|
||||
|
||||
VillagerProfession(final String oldProfession, final String oldCareer, final String newProfession) {
|
||||
this.oldProfession = oldProfession;
|
||||
this.oldCareer = oldCareer;
|
||||
this.newProfession = newProfession;
|
||||
}
|
||||
|
||||
private Villager.Profession asEnum() {
|
||||
return EnumUtil.valueOf(Villager.Profession.class, newProfession, oldProfession);
|
||||
}
|
||||
}
|
||||
|
||||
public enum VillagerType {
|
||||
DESERT,
|
||||
JUNGLE,
|
||||
PLAINS,
|
||||
SAVANNA,
|
||||
SNOWY,
|
||||
SWAMP,
|
||||
TAIGA
|
||||
}
|
||||
|
||||
private static Class catClass = null;
|
||||
private static Class catTypeClass = null;
|
||||
private static Method catSetTypeMethod = null;
|
||||
private static Boolean isNewCat = null;
|
||||
|
||||
public static void setCatType(final Entity entity, final CatType type) {
|
||||
if (isNewCat == null) {
|
||||
try {
|
||||
@ -65,10 +113,60 @@ public class MobCompat {
|
||||
}
|
||||
}
|
||||
|
||||
private static Villager.Profession getVillagerProfession(String... names) {
|
||||
// Add nitwit as a default in case we're on older versions
|
||||
names = Arrays.asList(names, "NITWIT").toArray(new String[0]);
|
||||
return EnumUtil.valueOf(Villager.Profession.class, names);
|
||||
private static Boolean isNewVillager = null;
|
||||
private static Class villagerCareerClass = null;
|
||||
private static Method villagerSetCareerMethod = null;
|
||||
private static Class villagerTypeClass = null;
|
||||
private static Method villagerSetTypeMethod = null;
|
||||
|
||||
|
||||
private static void checkVillagerEnums() {
|
||||
try {
|
||||
villagerCareerClass = Class.forName("org.bukkit.entity.Villager.Career");
|
||||
villagerSetCareerMethod = Villager.class.getDeclaredMethod("setCareer", villagerCareerClass);
|
||||
isNewVillager = false;
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
try {
|
||||
villagerTypeClass = Class.forName("org.bukkit.entity.Villager.Type");
|
||||
villagerSetTypeMethod = Villager.class.getDeclaredMethod("setVillagerType", villagerTypeClass);
|
||||
isNewVillager = true;
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setVillagerProfession(final Entity entity, final VillagerProfession profession) {
|
||||
if (isNewVillager == null) {
|
||||
checkVillagerEnums();
|
||||
}
|
||||
|
||||
if (isNewVillager) {
|
||||
((Villager) entity).setProfession(profession.asEnum());
|
||||
} else {
|
||||
((Villager) entity).setProfession(profession.asEnum());
|
||||
try {
|
||||
villagerSetCareerMethod.invoke(entity, EnumUtil.valueOf(villagerCareerClass, profession.oldCareer));
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setVillagerType(final Entity entity, final VillagerType type) {
|
||||
if (isNewVillager == null) {
|
||||
checkVillagerEnums();
|
||||
}
|
||||
|
||||
if (!isNewVillager) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
villagerSetTypeMethod.invoke(entity, EnumUtil.valueOf(villagerTypeClass, type.name()));
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -91,21 +91,22 @@ public enum MobData {
|
||||
SADDLE_PIG("saddle", EntityType.PIG, Data.PIGSADDLE, true),
|
||||
ANGRY_WOLF("angry", EntityType.WOLF, Data.ANGRY, true),
|
||||
RABID_WOLF("rabid", EntityType.WOLF, Data.ANGRY, false),
|
||||
VILLAGER("villager", EntityType.VILLAGER, Villager.Profession.NONE, true),
|
||||
ARMORER_VILLAGER("armorer", EntityType.VILLAGER, Villager.Profession.ARMORER, true),
|
||||
BUTCHER_VILLAGER("butcher", EntityType.VILLAGER, Villager.Profession.BUTCHER, true),
|
||||
CARTOGRAPHER_VILLAGER("cartographer", EntityType.VILLAGER, Villager.Profession.CARTOGRAPHER, true),
|
||||
CLERIC_VILLAGER("cleric", EntityType.VILLAGER, Villager.Profession.CLERIC, true),
|
||||
FARMER_VILLAGER("farmer", EntityType.VILLAGER, Villager.Profession.FARMER, true),
|
||||
FISHERMAN_VILLAGER("fisherman", EntityType.VILLAGER, Villager.Profession.FISHERMAN, true),
|
||||
FLETCHER_VILLAGER("fletcher", EntityType.VILLAGER, Villager.Profession.FLETCHER, true),
|
||||
LEATHERWORKER_VILLAGER("leatherworker", EntityType.VILLAGER, Villager.Profession.LEATHERWORKER, true),
|
||||
LIBRARIAN_VILLAGER("librarian", EntityType.VILLAGER, Villager.Profession.LIBRARIAN, true),
|
||||
MASON_VILLAGER("mason", EntityType.VILLAGER, Villager.Profession.MASON, true),
|
||||
NITWIT_VILLAGER("nitwit", EntityType.VILLAGER, Villager.Profession.NITWIT, true),
|
||||
SHEPHERD_VILLAGER("shepherd", EntityType.VILLAGER, Villager.Profession.SHEPHERD, true),
|
||||
TOOLSMITH_VILLAGER("toolsmith", EntityType.VILLAGER, Villager.Profession.TOOLSMITH, true),
|
||||
WEAPONSMITH("weaponsmith", EntityType.VILLAGER, Villager.Profession.WEAPONSMITH, true),
|
||||
VILLAGER("villager", EntityType.VILLAGER, MobCompat.VillagerProfession.NONE, true),
|
||||
ARMORER_VILLAGER("armorer", EntityType.VILLAGER, MobCompat.VillagerProfession.ARMORER, true),
|
||||
BUTCHER_VILLAGER("butcher", EntityType.VILLAGER, MobCompat.VillagerProfession.BUTCHER, true),
|
||||
CARTOGRAPHER_VILLAGER("cartographer", EntityType.VILLAGER, MobCompat.VillagerProfession.CARTOGRAPHER, true),
|
||||
CLERIC_VILLAGER("cleric", EntityType.VILLAGER, MobCompat.VillagerProfession.CLERIC, true),
|
||||
FARMER_VILLAGER("farmer", EntityType.VILLAGER, MobCompat.VillagerProfession.FARMER, true),
|
||||
FISHERMAN_VILLAGER("fisherman", EntityType.VILLAGER, MobCompat.VillagerProfession.FISHERMAN, true),
|
||||
FLETCHER_VILLAGER("fletcher", EntityType.VILLAGER, MobCompat.VillagerProfession.FLETCHER, true),
|
||||
LEATHERWORKER_VILLAGER("leatherworker", EntityType.VILLAGER, MobCompat.VillagerProfession.LEATHERWORKER, true),
|
||||
LIBRARIAN_VILLAGER("librarian", EntityType.VILLAGER, MobCompat.VillagerProfession.LIBRARIAN, true),
|
||||
MASON_VILLAGER("mason", EntityType.VILLAGER, MobCompat.VillagerProfession.MASON, true),
|
||||
NITWIT_VILLAGER("nitwit", EntityType.VILLAGER, MobCompat.VillagerProfession.NITWIT, true),
|
||||
SHEPHERD_VILLAGER("shepherd", EntityType.VILLAGER, MobCompat.VillagerProfession.SHEPHERD, true),
|
||||
TOOLSMITH_VILLAGER("toolsmith", EntityType.VILLAGER, MobCompat.VillagerProfession.TOOLSMITH, true),
|
||||
WEAPONSMITH_VILLAGER("weaponsmith", EntityType.VILLAGER, MobCompat.VillagerProfession.WEAPONSMITH, true),
|
||||
// TODO: VillagerTypes
|
||||
SIZE_SLIME("", "<1-100>", EntityType.SLIME.getEntityClass(), Data.SIZE, true),
|
||||
NUM_EXPERIENCE_ORB("", "<1-2000000000>", EntityType.EXPERIENCE_ORB, Data.EXP, true),
|
||||
RED_PARROT("red", EntityType.PARROT, Parrot.Variant.RED, true),
|
||||
|
Loading…
Reference in New Issue
Block a user