Readd ITEM_FRAME as a disguise. But not one that works.

This commit is contained in:
libraryaddict 2013-11-27 16:54:38 +13:00
parent 473769eb26
commit d9febc03d5
4 changed files with 11 additions and 34 deletions

View File

@ -24,7 +24,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.java.JavaPlugin; 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. * for mob noises. As well as setting their watcher class and entity size.
*/ */
private void registerValues() { 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()) { for (DisguiseType disguiseType : DisguiseType.values()) {
if (disguiseType.getEntityType() == null) {
continue;
}
Class watcherClass = null; Class watcherClass = null;
try { try {
switch (disguiseType) { switch (disguiseType) {
@ -194,6 +181,9 @@ public class LibsDisguises extends JavaPlugin {
} }
try { try {
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
if (nmsEntity == null) {
continue;
}
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
int entitySize = 0; int entitySize = 0;
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {

View File

@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -444,17 +443,9 @@ public abstract class Disguise {
*/ */
private void setupWatcher() { private void setupWatcher() {
HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType()); HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType());
HashMap<Integer, Object> entityValues = null; HashMap<Integer, Object> entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType()));
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 // 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. // STEP 1. Find out if the watcher has set data on it.
// If the watcher already set a metadata on this // If the watcher already set a metadata on this
if (getWatcher().hasValue(dataNo)) { if (getWatcher().hasValue(dataNo)) {

View File

@ -54,7 +54,7 @@ public enum DisguiseType {
IRON_GOLEM(), IRON_GOLEM(),
// ITEM_FRAME(71), ITEM_FRAME(71),
LEASH_HITCH(77), LEASH_HITCH(77),
@ -133,8 +133,10 @@ public enum DisguiseType {
static { static {
for (DisguiseType type : values()) { for (DisguiseType type : values()) {
try { try {
EntityType entityType; EntityType entityType = null;
switch (type) { switch (type) {
case ITEM_FRAME:
break;
case DONKEY: case DONKEY:
entityType = EntityType.HORSE; entityType = EntityType.HORSE;
break; break;

View File

@ -2,13 +2,11 @@ package me.libraryaddict.disguise.utilities;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.entity.EntityType;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
public class DisguiseValues { public class DisguiseValues {
private static HashMap<Enum, DisguiseValues> values = new HashMap<Enum, DisguiseValues>(); private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<DisguiseType, DisguiseValues>();
public static DisguiseValues getDisguiseValues(DisguiseType type) { public static DisguiseValues getDisguiseValues(DisguiseType type) {
switch (type) { switch (type) {
@ -37,10 +35,6 @@ public class DisguiseValues {
return values.get(type); return values.get(type);
} }
public static DisguiseValues getEntityValues(EntityType type) {
return values.get(type);
}
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) { public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
return getDisguiseValues(type).getMetaValues(); return getDisguiseValues(type).getMetaValues();
} }
@ -53,7 +47,7 @@ public class DisguiseValues {
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>(); private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
private Class nmsEntityClass; private Class nmsEntityClass;
public DisguiseValues(Enum type, Class classType, int entitySize) { public DisguiseValues(DisguiseType type, Class classType, int entitySize) {
values.put(type, this); values.put(type, this);
enumEntitySize = entitySize; enumEntitySize = entitySize;
nmsEntityClass = classType; nmsEntityClass = classType;