From d9febc03d525f901deaf4f4d4ed121882d0a1067 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 27 Nov 2013 16:54:38 +1300 Subject: [PATCH] Readd ITEM_FRAME as a disguise. But not one that works. --- src/me/libraryaddict/disguise/LibsDisguises.java | 16 +++------------- .../disguise/disguisetypes/Disguise.java | 13 ++----------- .../disguise/disguisetypes/DisguiseType.java | 6 ++++-- .../disguise/utilities/DisguiseValues.java | 10 ++-------- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index f25ab631..60820715 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -24,7 +24,6 @@ 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; @@ -97,19 +96,7 @@ 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; - } Class watcherClass = null; try { switch (disguiseType) { @@ -194,6 +181,9 @@ public class LibsDisguises extends JavaPlugin { } try { Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); + if (nmsEntity == null) { + continue; + } Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); int entitySize = 0; for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 90ba5793..edbba176 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -444,17 +443,9 @@ public abstract class Disguise { */ private void setupWatcher() { HashMap disguiseValues = DisguiseValues.getMetaValues(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(); - } + HashMap entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); // Start from 2 as they ALL share 0 and 1 - for (int dataNo = 2; dataNo <= 31; dataNo++) { + for (int dataNo = 0; dataNo <= 31; dataNo++) { // STEP 1. Find out if the watcher has set data on it. // If the watcher already set a metadata on this if (getWatcher().hasValue(dataNo)) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 2c66df24..ea5e1a9e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -54,7 +54,7 @@ public enum DisguiseType { IRON_GOLEM(), - // ITEM_FRAME(71), + ITEM_FRAME(71), LEASH_HITCH(77), @@ -133,8 +133,10 @@ public enum DisguiseType { static { for (DisguiseType type : values()) { try { - EntityType entityType; + EntityType entityType = null; switch (type) { + case ITEM_FRAME: + break; case DONKEY: entityType = EntityType.HORSE; break; diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java index af92f952..0a3cb7c4 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java @@ -2,13 +2,11 @@ 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) { @@ -37,10 +35,6 @@ 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(); } @@ -53,7 +47,7 @@ public class DisguiseValues { private HashMap metaValues = new HashMap(); private Class nmsEntityClass; - public DisguiseValues(Enum type, Class classType, int entitySize) { + public DisguiseValues(DisguiseType type, Class classType, int entitySize) { values.put(type, this); enumEntitySize = entitySize; nmsEntityClass = classType;