Create getEntityTrackerEntry()

This commit is contained in:
riking 2014-06-14 15:52:11 -07:00
parent d7a903c86e
commit 2566d8824e
2 changed files with 19 additions and 38 deletions

View File

@ -27,8 +27,7 @@ public class LivingWatcher extends FlagWatcher {
static Method potionNo; static Method potionNo;
static { static {
try { try {
Class mobEffectList = ReflectionManager.getNmsClass("MobEffectList"); list = (Object[]) ReflectionManager.getNmsField("MobEffectList", "byId").get(null);
list = (Object[]) mobEffectList.getField("byId").get(null);
for (Object obj : list) { for (Object obj : list) {
if (obj != null) { if (obj != null) {
for (Method field : obj.getClass().getMethods()) { for (Method field : obj.getClass().getMethods()) {

View File

@ -197,16 +197,22 @@ public class DisguiseUtilities {
} }
} }
private static final Field trackerField = ReflectionManager.getNmsField("World", "tracker");
private static final Field entitiesField = ReflectionManager.getNmsField("EntityTracker", "trackedEntities");
private static final Method ihmGet = ReflectionManager.getNmsMethod("IntHashMap", "get", int.class);
private static Object getEntityTrackerEntry(Entity target) throws Exception {
Object world = ReflectionManager.getWorld(target.getWorld());
Object tracker = trackerField.get(world);
Object trackedEntities = entitiesField.get(tracker);
return ihmGet.invoke(trackedEntities, target.getEntityId());
}
/** /**
* Sends entity removal packets, as this disguise was removed * Sends entity removal packets, as this disguise was removed
*/ */
public static void destroyEntity(TargetedDisguise disguise) { public static void destroyEntity(TargetedDisguise disguise) {
try { try {
Object world = ReflectionManager.getWorld(disguise.getEntity().getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(disguise.getEntity());
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, disguise.getEntity().getEntityId());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
@ -325,13 +331,9 @@ public class DisguiseUtilities {
public static ArrayList<Player> getPerverts(Disguise disguise) { public static ArrayList<Player> getPerverts(Disguise disguise) {
ArrayList<Player> players = new ArrayList<Player>(); ArrayList<Player> players = new ArrayList<Player>();
try { try {
Object world = ReflectionManager.getWorld(disguise.getEntity().getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(disguise.getEntity());
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, disguise.getEntity().getEntityId());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField(entityTrackerEntry.getClass(), "trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
for (Object p : trackedPlayers) { for (Object p : trackedPlayers) {
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(p);
@ -466,11 +468,7 @@ public class DisguiseUtilities {
public static void refreshTracker(TargetedDisguise disguise, String player) { public static void refreshTracker(TargetedDisguise disguise, String player) {
if (disguise.getEntity() != null && disguise.getEntity().isValid()) { if (disguise.getEntity() != null && disguise.getEntity().isValid()) {
try { try {
Object world = ReflectionManager.getWorld(disguise.getEntity().getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(disguise.getEntity());
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, disguise.getEntity().getEntityId());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
@ -499,11 +497,7 @@ public class DisguiseUtilities {
public static void refreshTrackers(Entity entity) { public static void refreshTrackers(Entity entity) {
if (entity.isValid()) { if (entity.isValid()) {
try { try {
Object world = ReflectionManager.getWorld(entity.getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(entity);
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, entity.getEntityId());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
@ -534,11 +528,7 @@ public class DisguiseUtilities {
*/ */
public static void refreshTrackers(TargetedDisguise disguise) { public static void refreshTrackers(TargetedDisguise disguise) {
try { try {
Object world = ReflectionManager.getWorld(disguise.getEntity().getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(disguise.getEntity());
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, disguise.getEntity().getEntityId());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
@ -599,11 +589,7 @@ public class DisguiseUtilities {
selfDisguisesIds.remove(player.getUniqueId()); selfDisguisesIds.remove(player.getUniqueId());
// Get the entity tracker // Get the entity tracker
try { try {
Object world = ReflectionManager.getWorld(player.getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(player);
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, player.getEntityId());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
@ -637,11 +623,7 @@ public class DisguiseUtilities {
if (!player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible()) { if (!player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible()) {
return; return;
} }
Object world = ReflectionManager.getWorld(player.getWorld()); Object entityTrackerEntry = getEntityTrackerEntry(player);
Object tracker = world.getClass().getField("tracker").get(world);
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
.invoke(trackedEntities, player.getEntityId());
if (entityTrackerEntry == null) { if (entityTrackerEntry == null) {
// A check incase the tracker is null. // A check incase the tracker is null.
// If it is, then this method will be run again in one tick. Which is when it should be constructed. // If it is, then this method will be run again in one tick. Which is when it should be constructed.