Add VillagerProfession and ZombieProfession because Villager.Profession is pure stupid

This commit is contained in:
libraryaddict 2017-12-23 10:37:56 +13:00
parent ed52576277
commit 3f27bcf999
7 changed files with 91 additions and 29 deletions

View File

@ -251,7 +251,8 @@ public class LibsDisguises extends JavaPlugin {
}
/**
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their
* sound volume
* for mob noises. As well as setting their watcher class and entity size.
*/
private void registerValues() {
@ -283,6 +284,8 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = SpiderWatcher.class;
break;
case ZOMBIE_VILLAGER:
watcherClass = ZombieVillagerWatcher.class;
break;
case PIG_ZOMBIE:
case HUSK:
watcherClass = ZombieWatcher.class;
@ -302,8 +305,9 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = IllagerWizardWatcher.class;
break;
default:
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(
disguiseType.name()) + "Watcher");
watcherClass = Class.forName(
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) +
"Watcher");
break;
}
}
@ -438,10 +442,11 @@ public class LibsDisguises extends JavaPlugin {
MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex());
if (flagType == null) {
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch
.getIndex() + " can't be found!");
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue()
.getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " +
watch.getIndex() + " can't be found!");
System.err.println(
"Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" +
nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue;
}
@ -452,21 +457,21 @@ public class LibsDisguises extends JavaPlugin {
Object obj2 = ReflectionManager.convertInvalidItem(watch.getValue());
if (obj1 != obj2 && ((obj1 == null || obj2 == null) || obj1.getClass() != obj2.getClass())) {
System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " + watch
.getIndex() + " has the wrong classtype!");
System.err.println(
"MetaIndex has the " + "default of " + flagType.getDefault() + " (" + flagType
.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass
.getSimpleName());
System.err.println("Where the internals is " + watch.getRawValue() + " (" + watch.getRawValue()
.getClass());
System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " +
watch.getIndex() + " has the wrong classtype!");
System.err.println("MetaIndex has the " + "default of " + flagType.getDefault() + " (" +
flagType.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " +
watcherClass.getSimpleName());
System.err.println("Where the internals is " + watch.getRawValue() + " (" +
watch.getRawValue().getClass());
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
}
}
for (MetaIndex index : indexes) {
System.out.println(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher()
.getSimpleName() + " at index " + index.getIndex());
System.out.println(
disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() +
" at index " + index.getIndex());
}
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
@ -495,12 +500,13 @@ public class LibsDisguises extends JavaPlugin {
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
}
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType
.name() + "!");
System.out
.print("[LibsDisguises] Before reporting this error, " + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
System.out
.print("[LibsDisguises] Development builds are available at (ProtocolLib) " + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " +
disguiseType.name() + "!");
System.out.print("[LibsDisguises] Before reporting this error, " +
"please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) " +
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming" +
".com:8080/job/LibsDisguises%201.9+/");
ex.printStackTrace();
}

View File

@ -0,0 +1,13 @@
package me.libraryaddict.disguise.disguisetypes;
/**
* Created by libraryaddict on 23/12/2017.
*/
public enum VillagerProfession {
FARMER,
LIBRARIAN,
PRIEST,
BLACKSMITH,
BUTCHER,
NITWIT;
}

View File

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

View File

@ -2,6 +2,7 @@ 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;
@ -12,16 +13,26 @@ 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)];
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, Math.max(1, Math.min(professionId, Profession.BUTCHER.ordinal()) - 1));
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());
}

View File

@ -2,6 +2,7 @@ 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 {
@ -42,6 +43,10 @@ public class ZombieVillagerWatcher extends ZombieWatcher {
return Profession.NORMAL;
}
public ZombieProfession getZombieProfession() {
return ZombieProfession.values()[getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION)];
}
/**
* Sets the profession of this zombie, in turn turning it into a Zombie Villager
*
@ -58,7 +63,12 @@ public class ZombieVillagerWatcher extends ZombieWatcher {
*
* @param profession
*/
@Deprecated
public void setProfession(Profession profession) {
setProfession(profession.ordinal());
}
public void setProfession(ZombieProfession profession) {
setProfession(profession.ordinal());
}
}

View File

@ -759,6 +759,20 @@ public class DisguiseParser {
// Parse to string
value = ChatColor.translateAlternateColorCodes('&', valueString);
}
} else if (param == ZombieProfession.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());
}
catch (Exception ex) {
throw parseToException(param, valueString, methodName);
}
} else if (param == AnimalColor.class) {
// Parse to animal color
try {
@ -803,9 +817,6 @@ public class DisguiseParser {
} else if (param == Horse.Style.class) {
// Parse to horse style
value = callValueOf(param, valueString, methodName);
} else if (param == Villager.Profession.class) {
// Parse to villager profession
value = callValueOf(param, valueString, methodName);
} else if (param == Art.class) {
// Parse to art type
value = callValueOf(param, valueString, methodName);

View File

@ -153,8 +153,10 @@ 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(Villager.Profession.class, "Villager Profession",
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(BlockFace.class, Arrays.copyOf(BlockFace.values(), 6),
"Direction (North, East, South, West, " + "Up, Down)",
"View the directions usable on player setSleeping and shulker direction");