From 5b86025fa0e1b9f912e170c5e2f60f0b6f723875 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 24 Dec 2017 09:26:44 +1300 Subject: [PATCH] Fix villager professions once and for all --- .../disguisetypes/VillagerProfession.java | 13 ------------ .../disguisetypes/ZombieProfession.java | 9 -------- .../watchers/VillagerWatcher.java | 13 +----------- .../watchers/ZombieVillagerWatcher.java | 21 +++---------------- .../disguise/utilities/DisguiseParser.java | 11 ++-------- .../utilities/ReflectionFlagWatchers.java | 6 ++---- 6 files changed, 8 insertions(+), 65 deletions(-) delete mode 100644 src/me/libraryaddict/disguise/disguisetypes/VillagerProfession.java delete mode 100644 src/me/libraryaddict/disguise/disguisetypes/ZombieProfession.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/VillagerProfession.java b/src/me/libraryaddict/disguise/disguisetypes/VillagerProfession.java deleted file mode 100644 index c2cd4cc4..00000000 --- a/src/me/libraryaddict/disguise/disguisetypes/VillagerProfession.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.libraryaddict.disguise.disguisetypes; - -/** - * Created by libraryaddict on 23/12/2017. - */ -public enum VillagerProfession { - FARMER, - LIBRARIAN, - PRIEST, - BLACKSMITH, - BUTCHER, - NITWIT; -} diff --git a/src/me/libraryaddict/disguise/disguisetypes/ZombieProfession.java b/src/me/libraryaddict/disguise/disguisetypes/ZombieProfession.java deleted file mode 100644 index f89cba58..00000000 --- a/src/me/libraryaddict/disguise/disguisetypes/ZombieProfession.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.libraryaddict.disguise.disguisetypes; - -/** - * Created by libraryaddict on 23/12/2017. - */ -public enum ZombieProfession { - NORMAL, - HUSK; -} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java index 56d0b692..8c61f755 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.disguisetypes.VillagerProfession; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import org.bukkit.entity.Villager.Profession; @@ -13,27 +12,17 @@ public class VillagerWatcher extends AgeableWatcher { setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); } - @Deprecated public Profession getProfession() { return Profession.values()[getData(MetaIndex.VILLAGER_PROFESSION) + 1]; } - public VillagerProfession getVillagerProfession() { - return VillagerProfession.values()[getData(MetaIndex.VILLAGER_PROFESSION)]; - } - @Deprecated public void setProfession(int professionId) { setData(MetaIndex.VILLAGER_PROFESSION, professionId); sendData(MetaIndex.VILLAGER_PROFESSION); } - public void setProfession(VillagerProfession profession) { - setProfession(Math.max(1, Math.min(profession.ordinal(), Profession.BUTCHER.ordinal()) - 1)); - } - - @Deprecated public void setProfession(Profession newProfession) { - setProfession(newProfession.ordinal()); + setProfession(newProfession.ordinal() - 1); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java index 9cb11134..c8653d39 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.disguisetypes.ZombieProfession; import org.bukkit.entity.Villager.Profession; public class ZombieVillagerWatcher extends ZombieWatcher { @@ -35,16 +34,7 @@ public class ZombieVillagerWatcher extends ZombieWatcher { * @return */ public Profession getProfession() { - int ord = getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION); - - if (ord == 1) - return Profession.HUSK; - - return Profession.NORMAL; - } - - public ZombieProfession getZombieProfession() { - return ZombieProfession.values()[getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION)]; + return Profession.values()[getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION) + 1]; } /** @@ -54,7 +44,7 @@ public class ZombieVillagerWatcher extends ZombieWatcher { */ @Deprecated public void setProfession(int id) { - setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION, id % 2); + setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION, id); sendData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION); } @@ -63,12 +53,7 @@ public class ZombieVillagerWatcher extends ZombieWatcher { * * @param profession */ - @Deprecated public void setProfession(Profession profession) { - setProfession(profession.ordinal()); - } - - public void setProfession(ZombieProfession profession) { - setProfession(profession.ordinal()); + setProfession(profession.ordinal() - 1); } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index 3c5a1ebd..79bdc97d 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -759,16 +759,9 @@ public class DisguiseParser { // Parse to string value = ChatColor.translateAlternateColorCodes('&', valueString); } - } else if (param == ZombieProfession.class) { + } else if (param == Villager.Profession.class) { try { - value = ZombieProfession.valueOf(valueString.toUpperCase()); - } - catch (Exception ex) { - throw parseToException(param, valueString, methodName); - } - } else if (param == VillagerProfession.class) { - try { - value = VillagerProfession.valueOf(valueString.toUpperCase()); + value = Villager.Profession.valueOf(valueString.toUpperCase()); } catch (Exception ex) { throw parseToException(param, valueString, methodName); diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java index 178c3d5f..63a508b1 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java @@ -153,10 +153,8 @@ public class ReflectionFlagWatchers { new ParamInfo(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color"); new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots"); - new ParamInfo(VillagerProfession.class, "Villager Profession", - "View all the professions you can set on a villager"); - new ParamInfo(ZombieProfession.class, "Zombie Profession", - "View all the professions you can set on a zombie villager"); + new ParamInfo(Villager.Profession.class, "Villager Profession", + "View all the professions you can set on a Zombie and Normal Villager"); new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 6), "Direction (North, East, South, West, " + "Up, Down)", "View the directions usable on player setSleeping and shulker direction");