From cd44c50f2e5ae54b6f26661cf9d9e11d12c880df Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 28 Jul 2013 11:00:29 +1200 Subject: [PATCH] Fetch the watcher that it will use. And stop using empty watchers --- .../Watchers/ChickenWatcher.java | 11 -- .../DisguiseTypes/Watchers/CowWatcher.java | 11 -- .../Watchers/EnderDragonWatcher.java | 11 -- .../Watchers/MagmaCubeWatcher.java | 10 -- .../Watchers/MushroomCowWatcher.java | 11 -- .../Watchers/PigZombieWatcher.java | 11 -- .../Watchers/SkeletonWatcher.java | 11 -- .../DisguiseTypes/Watchers/WitherWatcher.java | 10 -- .../libraryaddict/disguise/LibsDisguises.java | 109 ++++++++++++++---- 9 files changed, 84 insertions(+), 111 deletions(-) delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ChickenWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CowWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EnderDragonWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MagmaCubeWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MushroomCowWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigZombieWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SkeletonWatcher.java delete mode 100644 src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WitherWatcher.java diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ChickenWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ChickenWatcher.java deleted file mode 100644 index 592b9021..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ChickenWatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class ChickenWatcher extends AgeableWatcher { - - public ChickenWatcher(Disguise disguise) { - super(disguise); - } - -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CowWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CowWatcher.java deleted file mode 100644 index 249a9b11..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CowWatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class CowWatcher extends AgeableWatcher { - - public CowWatcher(Disguise disguise) { - super(disguise); - } - -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EnderDragonWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EnderDragonWatcher.java deleted file mode 100644 index cd87b94e..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EnderDragonWatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class EnderDragonWatcher extends LivingWatcher { - - public EnderDragonWatcher(Disguise disguise) { - super(disguise); - } - -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MagmaCubeWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MagmaCubeWatcher.java deleted file mode 100644 index bc3319c9..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MagmaCubeWatcher.java +++ /dev/null @@ -1,10 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class MagmaCubeWatcher extends SlimeWatcher { - - public MagmaCubeWatcher(Disguise disguise) { - super(disguise); - } -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MushroomCowWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MushroomCowWatcher.java deleted file mode 100644 index c3e03e47..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MushroomCowWatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class MushroomCowWatcher extends AgeableWatcher { - - public MushroomCowWatcher(Disguise disguise) { - super(disguise); - } - -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigZombieWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigZombieWatcher.java deleted file mode 100644 index 724f3c55..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigZombieWatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class PigZombieWatcher extends ZombieWatcher { - - public PigZombieWatcher(Disguise disguise) { - super(disguise); - } - -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SkeletonWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SkeletonWatcher.java deleted file mode 100644 index d6779a41..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SkeletonWatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class SkeletonWatcher extends LivingWatcher { - - public SkeletonWatcher(Disguise disguise) { - super(disguise); - } - -} diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WitherWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WitherWatcher.java deleted file mode 100644 index ed55b6b8..00000000 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WitherWatcher.java +++ /dev/null @@ -1,10 +0,0 @@ -package me.libraryaddict.disguise.DisguiseTypes.Watchers; - -import me.libraryaddict.disguise.DisguiseTypes.Disguise; - -public class WitherWatcher extends EnderDragonWatcher { - - public WitherWatcher(Disguise disguise) { - super(disguise); - } -} diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index a4816dcf..d8228320 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -11,8 +11,11 @@ import me.libraryaddict.disguise.Commands.*; import me.libraryaddict.disguise.DisguiseTypes.Disguise; import me.libraryaddict.disguise.DisguiseTypes.DisguiseSound; import me.libraryaddict.disguise.DisguiseTypes.DisguiseType; +import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher; import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise; import me.libraryaddict.disguise.DisguiseTypes.Values; +import me.libraryaddict.disguise.DisguiseTypes.Watchers.AgeableWatcher; +import me.libraryaddict.disguise.DisguiseTypes.Watchers.LivingWatcher; import net.minecraft.server.v1_6_R2.AttributeSnapshot; import net.minecraft.server.v1_6_R2.ChatMessage; import net.minecraft.server.v1_6_R2.ChunkCoordinates; @@ -24,10 +27,12 @@ import net.minecraft.server.v1_6_R2.World; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_6_R2.CraftWorld; +import org.bukkit.entity.Ageable; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.Packets; @@ -236,35 +241,89 @@ public class LibsDisguises extends JavaPlugin { private void registerValues() { World world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); for (DisguiseType disguiseType : DisguiseType.values()) { + Class watcherClass = null; + try { + String name; + switch (disguiseType) { + case MINECART_FURNACE: + case MINECART_HOPPER: + case MINECART_MOB_SPAWNER: + case MINECART_TNT: + case MINECART_CHEST: + name = "Minecart"; + break; + case DONKEY: + case MULE: + case UNDEAD_HORSE: + case SKELETON_HORSE: + name = "Horse"; + break; + case ZOMBIE_VILLAGER: + case PIG_ZOMBIE: + name = "Zombie"; + break; + case MAGMA_CUBE: + name = "Slime"; + default: + name = toReadable(disguiseType.name()); + break; + } + watcherClass = Class.forName("me.libraryaddict.disguise.DisguiseTypes.Watchers." + name + "Watcher"); + } catch (Exception ex) { + // There is no watcher for this entity, or a error was thrown. + try { + Class c = disguiseType.getEntityType().getEntityClass(); + if (c.isAssignableFrom(Ageable.class)) + watcherClass = AgeableWatcher.class; + else if (c.isAssignableFrom(LivingEntity.class)) + watcherClass = LivingWatcher.class; + else + watcherClass = FlagWatcher.class; + } catch (Exception ex1) { + ex1.printStackTrace(); + } + } + disguiseType.setWatcherClass(watcherClass); String name = toReadable(disguiseType.name()); - if (disguiseType == DisguiseType.WITHER_SKELETON) { - continue; - } else if (disguiseType == DisguiseType.ZOMBIE_VILLAGER) { - continue; - } else if (disguiseType == DisguiseType.PRIMED_TNT) { + boolean dontDo = false; + switch (disguiseType) { + case WITHER_SKELETON: + case ZOMBIE_VILLAGER: + case DONKEY: + case MULE: + case UNDEAD_HORSE: + case SKELETON_HORSE: + dontDo = true; + break; + case PRIMED_TNT: name = "TNTPrimed"; - } else if (disguiseType == DisguiseType.DONKEY) { - continue; - } else if (disguiseType == DisguiseType.MULE) { - continue; - } else if (disguiseType == DisguiseType.UNDEAD_HORSE) { - continue; - } else if (disguiseType == DisguiseType.SKELETON_HORSE) { - continue; - } else if (disguiseType == DisguiseType.MINECART_TNT) { + break; + case MINECART_TNT: name = "MinecartTNT"; - } else if (disguiseType == DisguiseType.MINECART) { + break; + case MINECART: name = "MinecartRideable"; - } else if (disguiseType == DisguiseType.FIREWORK) { + break; + case FIREWORK: name = "Fireworks"; - } else if (disguiseType == DisguiseType.SPLASH_POTION) + break; + case SPLASH_POTION: name = "Potion"; - else if (disguiseType == DisguiseType.GIANT) + break; + case GIANT: name = "GiantZombie"; - else if (disguiseType == DisguiseType.DROPPED_ITEM) + break; + case DROPPED_ITEM: name = "Item"; - else if (disguiseType == DisguiseType.FIREBALL) + break; + case FIREBALL: name = "LargeFireball"; + break; + default: + break; + } + if (dontDo) + continue; try { net.minecraft.server.v1_6_R2.Entity entity = null; Class entityClass; @@ -299,10 +358,10 @@ public class LibsDisguises extends JavaPlugin { } private String toReadable(String string) { - String[] strings = string.split("_"); - string = ""; - for (String s : strings) - string += s.substring(0, 1) + s.substring(1).toLowerCase(); - return string; + StringBuilder builder = new StringBuilder(); + for (String s : string.split("_")) { + builder.append(s.substring(0, 1) + s.substring(1).toLowerCase()); + } + return builder.toString(); } } \ No newline at end of file