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. * for mob noises. As well as setting their watcher class and entity size.
*/ */
private void registerValues() { private void registerValues() {
@ -283,6 +284,8 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = SpiderWatcher.class; watcherClass = SpiderWatcher.class;
break; break;
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
watcherClass = ZombieVillagerWatcher.class;
break;
case PIG_ZOMBIE: case PIG_ZOMBIE:
case HUSK: case HUSK:
watcherClass = ZombieWatcher.class; watcherClass = ZombieWatcher.class;
@ -302,8 +305,9 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = IllagerWizardWatcher.class; watcherClass = IllagerWizardWatcher.class;
break; break;
default: default:
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable( watcherClass = Class.forName(
disguiseType.name()) + "Watcher"); "me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) +
"Watcher");
break; break;
} }
} }
@ -438,10 +442,11 @@ public class LibsDisguises extends JavaPlugin {
MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex()); MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex());
if (flagType == null) { if (flagType == null) {
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " +
.getIndex() + " can't be found!"); watch.getIndex() + " can't be found!");
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue() System.err.println(
.getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName()); "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!"); System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue; continue;
} }
@ -452,21 +457,21 @@ public class LibsDisguises extends JavaPlugin {
Object obj2 = ReflectionManager.convertInvalidItem(watch.getValue()); Object obj2 = ReflectionManager.convertInvalidItem(watch.getValue());
if (obj1 != obj2 && ((obj1 == null || obj2 == null) || obj1.getClass() != obj2.getClass())) { if (obj1 != obj2 && ((obj1 == null || obj2 == null) || obj1.getClass() != obj2.getClass())) {
System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " + watch System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " +
.getIndex() + " has the wrong classtype!"); watch.getIndex() + " has the wrong classtype!");
System.err.println( System.err.println("MetaIndex has the " + "default of " + flagType.getDefault() + " (" +
"MetaIndex has the " + "default of " + flagType.getDefault() + " (" + flagType flagType.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " +
.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass watcherClass.getSimpleName());
.getSimpleName()); System.err.println("Where the internals is " + watch.getRawValue() + " (" +
System.err.println("Where the internals is " + watch.getRawValue() + " (" + watch.getRawValue() watch.getRawValue().getClass());
.getClass());
System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
} }
} }
for (MetaIndex index : indexes) { for (MetaIndex index : indexes) {
System.out.println(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher() System.out.println(
.getSimpleName() + " at index " + index.getIndex()); disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() +
" at index " + index.getIndex());
} }
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
@ -495,12 +500,13 @@ public class LibsDisguises extends JavaPlugin {
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity)); disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
} }
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) { catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " +
.name() + "!"); disguiseType.name() + "!");
System.out System.out.print("[LibsDisguises] Before reporting this error, " +
.print("[LibsDisguises] Before reporting this error, " + "please make sure you are using the latest version of LibsDisguises and ProtocolLib."); "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
System.out System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) " +
.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+/"); "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming" +
".com:8080/job/LibsDisguises%201.9+/");
ex.printStackTrace(); 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.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.VillagerProfession;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
@ -12,16 +13,26 @@ public class VillagerWatcher extends AgeableWatcher {
setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
} }
@Deprecated
public Profession getProfession() { 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 @Deprecated
public void setProfession(int professionId) { 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); 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) { public void setProfession(Profession newProfession) {
setProfession(newProfession.ordinal()); 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.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.ZombieProfession;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
public class ZombieVillagerWatcher extends ZombieWatcher { public class ZombieVillagerWatcher extends ZombieWatcher {
@ -42,6 +43,10 @@ public class ZombieVillagerWatcher extends ZombieWatcher {
return Profession.NORMAL; 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 * 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 * @param profession
*/ */
@Deprecated
public void setProfession(Profession profession) { public void setProfession(Profession profession) {
setProfession(profession.ordinal()); setProfession(profession.ordinal());
} }
public void setProfession(ZombieProfession profession) {
setProfession(profession.ordinal());
}
} }

View File

@ -759,6 +759,20 @@ public class DisguiseParser {
// Parse to string // Parse to string
value = ChatColor.translateAlternateColorCodes('&', valueString); 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) { } else if (param == AnimalColor.class) {
// Parse to animal color // Parse to animal color
try { try {
@ -803,9 +817,6 @@ public class DisguiseParser {
} else if (param == Horse.Style.class) { } else if (param == Horse.Style.class) {
// Parse to horse style // Parse to horse style
value = callValueOf(param, valueString, methodName); 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) { } else if (param == Art.class) {
// Parse to art type // Parse to art type
value = callValueOf(param, valueString, methodName); 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(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(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"); "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), new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 6),
"Direction (North, East, South, West, " + "Up, Down)", "Direction (North, East, South, West, " + "Up, Down)",
"View the directions usable on player setSleeping and shulker direction"); "View the directions usable on player setSleeping and shulker direction");