Finish up the refresh tracker. Its retarded and I don't want to look at it.

This commit is contained in:
libraryaddict 2014-06-21 08:01:42 +12:00
parent 992e416edf
commit 7453053131

View File

@ -455,20 +455,25 @@ 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 entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player
if (entityTrackerEntry != null) { && ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) {
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
entityTrackerEntry); } else {
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
ReflectionManager.getNmsClass("EntityPlayer")); if (entityTrackerEntry != null) {
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
ReflectionManager.getNmsClass("EntityPlayer")); .get(entityTrackerEntry);
HashSet cloned = (HashSet) trackedPlayers.clone(); Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
for (Object p : cloned) { ReflectionManager.getNmsClass("EntityPlayer"));
if (player.equals(((Player) ReflectionManager.getBukkitEntity(p)).getName())) { Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
clear.invoke(entityTrackerEntry, p); ReflectionManager.getNmsClass("EntityPlayer"));
updatePlayer.invoke(entityTrackerEntry, p); HashSet cloned = (HashSet) trackedPlayers.clone();
break; for (Object p : cloned) {
if (player.equalsIgnoreCase(((Player) ReflectionManager.getBukkitEntity(p)).getName())) {
clear.invoke(entityTrackerEntry, p);
updatePlayer.invoke(entityTrackerEntry, p);
break;
}
} }
} }
} }
@ -514,32 +519,34 @@ public class DisguiseUtilities {
* Resends the entity to all the watching players, which is where the magic begins * Resends the entity to all the watching players, which is where the magic begins
*/ */
public static void refreshTrackers(TargetedDisguise disguise) { public static void refreshTrackers(TargetedDisguise disguise) {
try { if (disguise.getEntity().isValid()) {
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player) { try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player) {
} DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); }
if (entityTrackerEntry != null) { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( if (entityTrackerEntry != null) {
entityTrackerEntry); HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", entityTrackerEntry);
ReflectionManager.getNmsClass("EntityPlayer")); Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer"));
ReflectionManager.getNmsClass("EntityPlayer")); Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
HashSet cloned = (HashSet) trackedPlayers.clone(); ReflectionManager.getNmsClass("EntityPlayer"));
for (Object p : cloned) { HashSet cloned = (HashSet) trackedPlayers.clone();
Player player = (Player) ReflectionManager.getBukkitEntity(p); for (Object p : cloned) {
// if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player) Player player = (Player) ReflectionManager.getBukkitEntity(p);
// entity)) // if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player)
// continue; // entity))
if (disguise.canSee(player.getName())) { // continue;
clear.invoke(entityTrackerEntry, p); if (disguise.canSee(player.getName())) {
updatePlayer.invoke(entityTrackerEntry, p); clear.invoke(entityTrackerEntry, p);
updatePlayer.invoke(entityTrackerEntry, p);
}
} }
} }
} catch (Exception ex) {
ex.printStackTrace();
} }
} catch (Exception ex) {
ex.printStackTrace();
} }
} }