Fixed a weird system where I use strings for getting the watcher class

This commit is contained in:
libraryaddict 2013-11-23 08:22:06 +13:00
parent 6b225f18c3
commit 81933b90bd

View File

@ -12,7 +12,11 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.Values; import me.libraryaddict.disguise.disguisetypes.Values;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -91,35 +95,34 @@ public class LibsDisguises extends JavaPlugin {
} }
Class watcherClass = null; Class watcherClass = null;
try { try {
String name;
switch (disguiseType) { switch (disguiseType) {
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:
case MINECART_CHEST: case MINECART_CHEST:
name = "Minecart"; watcherClass = MinecartWatcher.class;
break; break;
case DONKEY: case DONKEY:
case MULE: case MULE:
case UNDEAD_HORSE: case UNDEAD_HORSE:
case SKELETON_HORSE: case SKELETON_HORSE:
name = "Horse"; watcherClass = HorseWatcher.class;
break; break;
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case PIG_ZOMBIE: case PIG_ZOMBIE:
name = "Zombie"; watcherClass = ZombieWatcher.class;
break; break;
case MAGMA_CUBE: case MAGMA_CUBE:
name = "Slime"; watcherClass = SlimeWatcher.class;
break; break;
default: default:
name = toReadable(disguiseType.name()); watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
+ toReadable(disguiseType.name()) + "Watcher");
break; break;
} }
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + name + "Watcher"); } catch (ClassNotFoundException ex) {
} catch (Exception ex) { // There is no explict watcher for this entity.
// There is no watcher for this entity, or a error was thrown.
Class c = disguiseType.getEntityType().getEntityClass(); Class c = disguiseType.getEntityType().getEntityClass();
if (Ageable.class.isAssignableFrom(c)) { if (Ageable.class.isAssignableFrom(c)) {
watcherClass = AgeableWatcher.class; watcherClass = AgeableWatcher.class;