diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 6302f62c..f25ab631 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -24,6 +24,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Ageable; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.plugin.java.JavaPlugin; @@ -96,6 +97,15 @@ public class LibsDisguises extends JavaPlugin { * for mob noises. As well as setting their watcher class and entity size. */ private void registerValues() { + try { + DisguiseValues disguiseValues = new DisguiseValues((Enum) Class.forName("org.bukkit.entity.EntityType") + .getField("ITEM_FRAME").get(null), null, 0); + for (WrappedWatchableObject watch : WrappedDataWatcher.getEntityWatcher( + ReflectionManager.getBukkitEntity(ReflectionManager.createEntityInstance("ItemFrame"))).getWatchableObjects()) + disguiseValues.setMetaValue(watch.getIndex(), watch.getValue()); + } catch (Exception ex) { + ex.printStackTrace(); + } for (DisguiseType disguiseType : DisguiseType.values()) { if (disguiseType.getEntityType() == null) { continue; @@ -179,10 +189,12 @@ public class LibsDisguises extends JavaPlugin { default: break; } + if (DisguiseValues.getDisguiseValues(disguiseType) != null) { + continue; + } try { Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); - Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity") - .invoke(nmsEntity); + Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); int entitySize = 0; for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { if (field.getType().getName().equals("EnumEntitySize")) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 7e3293d7..90ba5793 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -139,7 +139,7 @@ public abstract class Disguise { case ENDER_CRYSTAL: case ENDER_DRAGON: case GHAST: - // case ITEM_FRAME: + // case ITEM_FRAME: case MINECART: case MINECART_CHEST: case MINECART_FURNACE: @@ -213,7 +213,7 @@ public abstract class Disguise { Location loc = getEntity().getLocation(); mods.write( 4, - PacketsManager.getYaw(getType(), DisguiseType.getType(getEntity().getType()), + PacketsManager.getYaw(getType(), getEntity().getType(), (byte) Math.floor(loc.getYaw() * 256.0F / 360.0F))); mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)); if (isSelfDisguiseVisible() && getEntity() instanceof Player) { @@ -295,11 +295,10 @@ public abstract class Disguise { Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class) .invoke(trackedEntities, getEntity().getEntityId()); if (entityTrackerEntry != null) { - Method method = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity"); HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") .get(entityTrackerEntry); for (Object p : trackedPlayers) { - players.add((Player) method.invoke(p)); + players.add((Player) ReflectionManager.getBukkitEntity(p)); } } } catch (Exception ex) { @@ -445,7 +444,15 @@ public abstract class Disguise { */ private void setupWatcher() { HashMap disguiseValues = DisguiseValues.getMetaValues(getType()); - HashMap entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); + HashMap entityValues = null; + if (DisguiseType.getType(getEntity().getType()) != null) + entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); + else { + DisguiseValues.getEntityValues(getEntity().getType()).getMetaValues(); + } + if (entityValues == null) { + entityValues = new HashMap(); + } // Start from 2 as they ALL share 0 and 1 for (int dataNo = 2; dataNo <= 31; dataNo++) { // STEP 1. Find out if the watcher has set data on it. diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index f98af161..2c66df24 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -167,7 +167,11 @@ public enum DisguiseType { } public static DisguiseType getType(org.bukkit.entity.EntityType entityType) { - return DisguiseType.valueOf(entityType.name()); + try { + return DisguiseType.valueOf(entityType.name()); + } catch (Throwable ex) { + return null; + } } private int defaultData; diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index dffc9393..15aa569c 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -58,13 +58,12 @@ public class DisguiseUtilities { if (entityTrackerEntry != null) { HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") .get(entityTrackerEntry); - Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity"); Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer")); Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); HashSet cloned = (HashSet) trackedPlayers.clone(); for (Object player : cloned) { - if (entity instanceof Player && !((Player) getBukkitEntity.invoke(player)).canSee((Player) entity)) + if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player) entity)) continue; clear.invoke(entityTrackerEntry, player); updatePlayer.invoke(entityTrackerEntry, player); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java index 0a3cb7c4..af92f952 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java @@ -2,11 +2,13 @@ package me.libraryaddict.disguise.utilities; import java.util.HashMap; +import org.bukkit.entity.EntityType; + import me.libraryaddict.disguise.disguisetypes.DisguiseType; public class DisguiseValues { - private static HashMap values = new HashMap(); + private static HashMap values = new HashMap(); public static DisguiseValues getDisguiseValues(DisguiseType type) { switch (type) { @@ -35,6 +37,10 @@ public class DisguiseValues { return values.get(type); } + public static DisguiseValues getEntityValues(EntityType type) { + return values.get(type); + } + public static HashMap getMetaValues(DisguiseType type) { return getDisguiseValues(type).getMetaValues(); } @@ -47,7 +53,7 @@ public class DisguiseValues { private HashMap metaValues = new HashMap(); private Class nmsEntityClass; - public DisguiseValues(DisguiseType type, Class classType, int entitySize) { + public DisguiseValues(Enum type, Class classType, int entitySize) { values.put(type, this); enumEntitySize = entitySize; nmsEntityClass = classType; diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index bc508c55..d580e0fc 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -114,7 +114,17 @@ public class ReflectionManager { try { return Class.forName("net.minecraft.server." + bukkitVersion + "." + className); } catch (Exception e) { - // e.printStackTrace(); + // e.printStackTrace(); + } + return null; + } + + public static Entity getBukkitEntity(Object nmsEntity) { + try { + Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity").invoke(nmsEntity); + return bukkitEntity; + } catch (Exception ex) { + ex.printStackTrace(); } return null; }