From 6ac7106df7475ed1b99a6fc4d021e5341a616ff1 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 2 Jun 2014 03:27:14 +1200 Subject: [PATCH] Added method to get the disguisetype from a entity, including horses, zombie villager and wither skeleton --- .../disguise/disguisetypes/DisguiseType.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index e43daf28..9dcb6f7f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -1,6 +1,9 @@ package me.libraryaddict.disguise.disguisetypes; +import java.lang.reflect.Method; + import org.apache.commons.lang.StringUtils; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; public enum DisguiseType { @@ -166,7 +169,46 @@ public enum DisguiseType { } } - public static DisguiseType getType(org.bukkit.entity.EntityType entityType) { + public static DisguiseType getType(Entity entity) { + DisguiseType disguiseType = getType(entity.getType()); + switch (disguiseType) { + case ZOMBIE: + try { + Method isVillager = entity.getClass().getMethod("isVillager"); + if ((Boolean) isVillager.invoke(entity)) { + disguiseType = DisguiseType.ZOMBIE_VILLAGER; + } + } catch (NoSuchMethodException ex) { + } catch (Exception ex) { + ex.printStackTrace(); + } + break; + case HORSE: + try { + Object variant = entity.getClass().getMethod("getVariant").invoke(entity); + disguiseType = DisguiseType.valueOf(((Enum) variant).name()); + } catch (Exception ex) { + ex.printStackTrace(); + } + break; + case SKELETON: + try { + Object type = entity.getClass().getMethod("getSkeletonType").invoke(entity); + if (((Enum) type).name().equals("WITHER")) { + disguiseType = DisguiseType.WITHER_SKELETON; + } + } catch (NoSuchMethodException ex) { + } catch (Exception ex) { + ex.printStackTrace(); + } + break; + default: + break; + } + return disguiseType; + } + + public static DisguiseType getType(EntityType entityType) { try { return DisguiseType.valueOf(entityType.name()); } catch (Throwable ex) {