Minor code clean

This commit is contained in:
libraryaddict 2013-11-19 08:39:28 +13:00
parent 33460a6fb7
commit 4e101c3ec6
4 changed files with 5 additions and 24 deletions

View File

@ -171,7 +171,7 @@ public class LibsDisguises extends JavaPlugin {
break; break;
} }
try { try {
Object entity = ReflectionManager.getEntityInstance(name); Object entity = ReflectionManager.createEntityInstance(name);
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity") Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity")
.invoke(entity); .invoke(entity);
int size = 0; int size = 0;

View File

@ -612,7 +612,7 @@ public class PacketsManager {
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT, Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT, Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT,
Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT, Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT,
/* Packets.Server.ENTITY_STATUS, */Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) { Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld()); StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld());

View File

@ -20,7 +20,7 @@ public class ReflectionManager {
try { try {
if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers()) if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers())
&& method.getParameterTypes().length == 0) { && method.getParameterTypes().length == 0) {
Object entity = getEntityInstance("Pig"); Object entity = createEntityInstance("Pig");
method.setAccessible(true); method.setAccessible(true);
method.invoke(entity); method.invoke(entity);
Field random = getNmsClass("Entity").getDeclaredField("random"); Field random = getNmsClass("Entity").getDeclaredField("random");
@ -79,11 +79,11 @@ public class ReflectionManager {
return null; return null;
} }
public static Object getEntityInstance(String entityName) { public static Object createEntityInstance(String entityName) {
try { try {
Class entityClass = getNmsClass("Entity" + entityName); Class entityClass = getNmsClass("Entity" + entityName);
Object entityObject; Object entityObject;
Object world = getWorld(); Object world = getWorld(Bukkit.getWorlds().get(0));
if (entityName.equals("Player")) { if (entityName.equals("Player")) {
Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null); Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null);
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World")) Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
@ -121,7 +121,6 @@ public class ReflectionManager {
public static Float getSoundModifier(Object entity) { public static Float getSoundModifier(Object entity) {
try { try {
// TODO Update this each update!
soundMethod.setAccessible(true); soundMethod.setAccessible(true);
return (Float) soundMethod.invoke(entity); return (Float) soundMethod.invoke(entity);
} catch (Exception ex) { } catch (Exception ex) {
@ -129,10 +128,6 @@ public class ReflectionManager {
return null; return null;
} }
private static Object getWorld() {
return getWorld(Bukkit.getWorlds().get(0));
}
public static Object getWorld(World world) { public static Object getWorld(World world) {
try { try {
return getCraftClass("CraftWorld").getMethod("getHandle").invoke(world); return getCraftClass("CraftWorld").getMethod("getHandle").invoke(world);

View File

@ -6,10 +6,6 @@ public class Values {
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>(); private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
/* public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
return getValues(type).getAttributesValues();
}*/
public static Class getEntityClass(DisguiseType type) { public static Class getEntityClass(DisguiseType type) {
return getValues(type).getEntityClass(); return getValues(type).getEntityClass();
} }
@ -45,8 +41,6 @@ public class Values {
return values.get(type); return values.get(type);
} }
// private HashMap<String, Double> attributesValues = new HashMap<String, Double>();
private Class declared; private Class declared;
private int enumEntitySize; private int enumEntitySize;
@ -58,10 +52,6 @@ public class Values {
declared = classType; declared = classType;
} }
/*public HashMap<String, Double> getAttributesValues() {
return attributesValues;
}*/
public Class getEntityClass() { public Class getEntityClass() {
return declared; return declared;
} }
@ -113,10 +103,6 @@ public class Values {
return metaValues; return metaValues;
} }
/*public void setAttributesValue(String attribute, Double value) {
attributesValues.put(attribute, value);
}*/
public void setMetaValue(int no, Object value) { public void setMetaValue(int no, Object value) {
metaValues.put(no, value); metaValues.put(no, value);
} }