Add MetaIndex.printMetadata()

This commit is contained in:
libraryaddict 2017-04-15 16:22:17 +12:00
parent 901ba70ff3
commit 7a2d360528
3 changed files with 133 additions and 115 deletions

View File

@ -123,7 +123,8 @@ public class LibsDisguises extends JavaPlugin {
registerCommand("disguisemodify", new DisguiseModifyCommand()); registerCommand("disguisemodify", new DisguiseModifyCommand());
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand()); registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand()); registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
registerCommand("disguisemodifyradius", new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax"))); registerCommand("disguisemodifyradius",
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
@ -167,43 +168,43 @@ public class LibsDisguises extends JavaPlugin {
try { try {
switch (disguiseType) { switch (disguiseType) {
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
watcherClass = ArrowWatcher.class; watcherClass = ArrowWatcher.class;
break; break;
case PRIMED_TNT: case PRIMED_TNT:
watcherClass = TNTWatcher.class; watcherClass = TNTWatcher.class;
break; break;
case MINECART_CHEST: case MINECART_CHEST:
case MINECART_COMMAND: case MINECART_COMMAND:
case MINECART_FURNACE: case MINECART_FURNACE:
case MINECART_HOPPER: case MINECART_HOPPER:
case MINECART_MOB_SPAWNER: case MINECART_MOB_SPAWNER:
case MINECART_TNT: case MINECART_TNT:
watcherClass = MinecartWatcher.class; watcherClass = MinecartWatcher.class;
break; break;
case SPIDER: case SPIDER:
case CAVE_SPIDER: case CAVE_SPIDER:
watcherClass = SpiderWatcher.class; watcherClass = SpiderWatcher.class;
break; break;
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case PIG_ZOMBIE: case PIG_ZOMBIE:
case HUSK: case HUSK:
watcherClass = ZombieWatcher.class; watcherClass = ZombieWatcher.class;
break; break;
case MAGMA_CUBE: case MAGMA_CUBE:
watcherClass = SlimeWatcher.class; watcherClass = SlimeWatcher.class;
break; break;
case ELDER_GUARDIAN: case ELDER_GUARDIAN:
watcherClass = GuardianWatcher.class; watcherClass = GuardianWatcher.class;
break; break;
case WITHER_SKELETON: case WITHER_SKELETON:
case STRAY: case STRAY:
watcherClass = SkeletonWatcher.class; watcherClass = SkeletonWatcher.class;
break; break;
default: default:
watcherClass = Class.forName( watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher"); disguiseType.name()) + "Watcher");
break; break;
} }
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
@ -213,21 +214,16 @@ public class LibsDisguises extends JavaPlugin {
if (entityClass != null) { if (entityClass != null) {
if (Tameable.class.isAssignableFrom(entityClass)) { if (Tameable.class.isAssignableFrom(entityClass)) {
watcherClass = TameableWatcher.class; watcherClass = TameableWatcher.class;
} } else if (Ageable.class.isAssignableFrom(entityClass)) {
else if (Ageable.class.isAssignableFrom(entityClass)) {
watcherClass = AgeableWatcher.class; watcherClass = AgeableWatcher.class;
} } else if (Creature.class.isAssignableFrom(entityClass)) {
else if (Creature.class.isAssignableFrom(entityClass)) {
watcherClass = InsentientWatcher.class; watcherClass = InsentientWatcher.class;
} } else if (LivingEntity.class.isAssignableFrom(entityClass)) {
else if (LivingEntity.class.isAssignableFrom(entityClass)) {
watcherClass = LivingWatcher.class; watcherClass = LivingWatcher.class;
} } else {
else {
watcherClass = FlagWatcher.class; watcherClass = FlagWatcher.class;
} }
} } else {
else {
watcherClass = FlagWatcher.class; // Disguise is unknown type watcherClass = FlagWatcher.class; // Disguise is unknown type
} }
} }
@ -246,50 +242,50 @@ public class LibsDisguises extends JavaPlugin {
String nmsEntityName = toReadable(disguiseType.name()); String nmsEntityName = toReadable(disguiseType.name());
switch (disguiseType) { switch (disguiseType) {
case WITHER_SKELETON: case WITHER_SKELETON:
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case DONKEY: case DONKEY:
case MULE: case MULE:
case ZOMBIE_HORSE: case ZOMBIE_HORSE:
case SKELETON_HORSE: case SKELETON_HORSE:
case STRAY: case STRAY:
case HUSK: case HUSK:
continue; continue;
case PRIMED_TNT: case PRIMED_TNT:
nmsEntityName = "TNTPrimed"; nmsEntityName = "TNTPrimed";
break; break;
case MINECART_TNT: case MINECART_TNT:
nmsEntityName = "MinecartTNT"; nmsEntityName = "MinecartTNT";
break; break;
case MINECART: case MINECART:
nmsEntityName = "MinecartRideable"; nmsEntityName = "MinecartRideable";
break; break;
case FIREWORK: case FIREWORK:
nmsEntityName = "Fireworks"; nmsEntityName = "Fireworks";
break; break;
case SPLASH_POTION: case SPLASH_POTION:
nmsEntityName = "Potion"; nmsEntityName = "Potion";
break; break;
case GIANT: case GIANT:
nmsEntityName = "GiantZombie"; nmsEntityName = "GiantZombie";
break; break;
case DROPPED_ITEM: case DROPPED_ITEM:
nmsEntityName = "Item"; nmsEntityName = "Item";
break; break;
case FIREBALL: case FIREBALL:
nmsEntityName = "LargeFireball"; nmsEntityName = "LargeFireball";
break; break;
case LEASH_HITCH: case LEASH_HITCH:
nmsEntityName = "Leash"; nmsEntityName = "Leash";
break; break;
case ELDER_GUARDIAN: case ELDER_GUARDIAN:
nmsEntityName = "Guardian"; nmsEntityName = "Guardian";
break; break;
case ARROW: case ARROW:
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
nmsEntityName = "TippedArrow"; nmsEntityName = "TippedArrow";
default: default:
break; break;
} }
try { try {
@ -337,21 +333,21 @@ 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.getIndex() System.err.println(
+ " can't be found!"); "Error finding the FlagType for " + disguiseType.name() + "! Index " + watch.getIndex() + " can't be found!");
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" System.err.println(
+ 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;
} }
if (ReflectionManager.convertInvalidItem(flagType.getDefault()).getClass() != ReflectionManager if (ReflectionManager.convertInvalidItem(
.convertInvalidItem(watch.getValue()).getClass()) { flagType.getDefault()).getClass() != ReflectionManager.convertInvalidItem(
System.err.println("Mismatch of FlagType's for " + disguiseType.name() + "! Index " + watch.getIndex() watch.getValue()).getClass()) {
+ " has the wrong classtype!"); System.err.println(
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" "Mismatch of FlagType's for " + disguiseType.name() + "! Index " + watch.getIndex() + " has the wrong classtype!");
+ nmsEntity.getClass() + ") & " + watcherClass.getSimpleName() + " which doesn't match up with " System.err.println(
+ flagType.getDefault().getClass()); "Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName() + " which doesn't match up with " + flagType.getDefault().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!");
continue; continue;
} }
@ -374,8 +370,7 @@ public class LibsDisguises extends JavaPlugin {
((Ageable) bukkitEntity).setBaby(); ((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} } else if (bukkitEntity instanceof Zombie) {
else if (bukkitEntity instanceof Zombie) {
((Zombie) bukkitEntity).setBaby(true); ((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
@ -386,10 +381,10 @@ public class LibsDisguises extends JavaPlugin {
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) { catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
System.out.print( System.out.print(
"[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!"); "[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
System.out.print("[LibsDisguises] Before reporting this error, " System.out.print(
+ "please make sure you are using the latest version of LibsDisguises and ProtocolLib."); "[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) " System.out.print(
+ "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/"); "[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(); ex.printStackTrace();
} }

View File

@ -10,11 +10,9 @@ import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.lang.reflect.Field;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID;
public class MetaIndex<Y> { public class MetaIndex<Y> {
private static MetaIndex[] _values = new MetaIndex[0]; private static MetaIndex[] _values = new MetaIndex[0];
@ -313,6 +311,31 @@ public class MetaIndex<Y> {
} }
} }
public static void printMetadata() {
ArrayList<String> toPrint = new ArrayList<>();
try {
for (Field field : MetaIndex.class.getFields()) {
if (field.getType() != MetaIndex.class)
continue;
MetaIndex index = (MetaIndex) field.get(null);
toPrint.add(
index.getFlagWatcher().getSimpleName() + " " + field.getName() + " " + index.getIndex() + " " + index.getDefault().getClass().getSimpleName());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
Collections.sort(toPrint, String.CASE_INSENSITIVE_ORDER);
for (String s : toPrint) {
System.out.println(s);
}
}
public static MetaIndex getFlag(Class<? extends FlagWatcher> watcherClass, int flagNo) { public static MetaIndex getFlag(Class<? extends FlagWatcher> watcherClass, int flagNo) {
for (MetaIndex type : values()) { for (MetaIndex type : values()) {
if (type.getIndex() != flagNo) if (type.getIndex() != flagNo)