Read desc
Added method getBukkitEntity to reflectionmanager Added a way for itemframe values to exist.
This commit is contained in:
parent
ca913347ce
commit
473769eb26
@ -24,6 +24,7 @@ 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;
|
||||||
|
|
||||||
@ -96,6 +97,15 @@ 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) {
|
if (disguiseType.getEntityType() == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -179,10 +189,12 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
||||||
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity")
|
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
||||||
.invoke(nmsEntity);
|
|
||||||
int entitySize = 0;
|
int entitySize = 0;
|
||||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||||
if (field.getType().getName().equals("EnumEntitySize")) {
|
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||||
|
@ -213,7 +213,7 @@ public abstract class Disguise {
|
|||||||
Location loc = getEntity().getLocation();
|
Location loc = getEntity().getLocation();
|
||||||
mods.write(
|
mods.write(
|
||||||
4,
|
4,
|
||||||
PacketsManager.getYaw(getType(), DisguiseType.getType(getEntity().getType()),
|
PacketsManager.getYaw(getType(), getEntity().getType(),
|
||||||
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
|
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
|
||||||
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
||||||
if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
|
if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
|
||||||
@ -295,11 +295,10 @@ public abstract class Disguise {
|
|||||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||||
.invoke(trackedEntities, getEntity().getEntityId());
|
.invoke(trackedEntities, getEntity().getEntityId());
|
||||||
if (entityTrackerEntry != null) {
|
if (entityTrackerEntry != null) {
|
||||||
Method method = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
|
||||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||||
.get(entityTrackerEntry);
|
.get(entityTrackerEntry);
|
||||||
for (Object p : trackedPlayers) {
|
for (Object p : trackedPlayers) {
|
||||||
players.add((Player) method.invoke(p));
|
players.add((Player) ReflectionManager.getBukkitEntity(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -445,7 +444,15 @@ 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 = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType()));
|
HashMap<Integer, Object> 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
|
// Start from 2 as they ALL share 0 and 1
|
||||||
for (int dataNo = 2; dataNo <= 31; dataNo++) {
|
for (int dataNo = 2; 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.
|
||||||
|
@ -167,7 +167,11 @@ public enum DisguiseType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
||||||
|
try {
|
||||||
return DisguiseType.valueOf(entityType.name());
|
return DisguiseType.valueOf(entityType.name());
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int defaultData;
|
private int defaultData;
|
||||||
|
@ -58,13 +58,12 @@ public class DisguiseUtilities {
|
|||||||
if (entityTrackerEntry != null) {
|
if (entityTrackerEntry != null) {
|
||||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||||
.get(entityTrackerEntry);
|
.get(entityTrackerEntry);
|
||||||
Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
|
||||||
Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
||||||
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
||||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||||
HashSet cloned = (HashSet) trackedPlayers.clone();
|
HashSet cloned = (HashSet) trackedPlayers.clone();
|
||||||
for (Object player : cloned) {
|
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;
|
continue;
|
||||||
clear.invoke(entityTrackerEntry, player);
|
clear.invoke(entityTrackerEntry, player);
|
||||||
updatePlayer.invoke(entityTrackerEntry, player);
|
updatePlayer.invoke(entityTrackerEntry, player);
|
||||||
|
@ -2,11 +2,13 @@ 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<DisguiseType, DisguiseValues> values = new HashMap<DisguiseType, DisguiseValues>();
|
private static HashMap<Enum, DisguiseValues> values = new HashMap<Enum, DisguiseValues>();
|
||||||
|
|
||||||
public static DisguiseValues getDisguiseValues(DisguiseType type) {
|
public static DisguiseValues getDisguiseValues(DisguiseType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -35,6 +37,10 @@ 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();
|
||||||
}
|
}
|
||||||
@ -47,7 +53,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(DisguiseType type, Class classType, int entitySize) {
|
public DisguiseValues(Enum type, Class classType, int entitySize) {
|
||||||
values.put(type, this);
|
values.put(type, this);
|
||||||
enumEntitySize = entitySize;
|
enumEntitySize = entitySize;
|
||||||
nmsEntityClass = classType;
|
nmsEntityClass = classType;
|
||||||
|
@ -119,6 +119,16 @@ public class ReflectionManager {
|
|||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public static Object getNmsEntity(Entity entity) {
|
public static Object getNmsEntity(Entity entity) {
|
||||||
try {
|
try {
|
||||||
return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity);
|
return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity);
|
||||||
|
Loading…
Reference in New Issue
Block a user