Fix villager professions once and for all

This commit is contained in:
libraryaddict 2017-12-24 09:26:44 +13:00
parent 3f27bcf999
commit 5b86025fa0
6 changed files with 8 additions and 65 deletions

View File

@ -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;
}

View File

@ -1,9 +0,0 @@
package me.libraryaddict.disguise.disguisetypes;
/**
* Created by libraryaddict on 23/12/2017.
*/
public enum ZombieProfession {
NORMAL,
HUSK;
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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");