Fix disguises not showing up straight away

This commit is contained in:
libraryaddict 2014-09-03 11:38:28 +12:00
parent 476c756ad1
commit 81d758ca7f

View File

@ -463,26 +463,44 @@ public class DisguiseUtilities {
/** /**
* Resends the entity to this specific player * Resends the entity to this specific player
*/ */
public static void refreshTracker(TargetedDisguise disguise, String player) { public static void refreshTracker(final TargetedDisguise disguise, String player) {
if (disguise.getEntity() != null && disguise.getEntity().isValid()) { if (disguise.getEntity() != null && disguise.getEntity().isValid()) {
try { try {
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player
&& ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) { && ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) {
removeSelfDisguise((Player) disguise.getEntity());
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
} else { } else {
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
.get(entityTrackerEntry); .get(entityTrackerEntry);
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
ReflectionManager.getNmsClass("EntityPlayer")); ReflectionManager.getNmsClass("EntityPlayer"));
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer")); ReflectionManager.getNmsClass("EntityPlayer"));
HashSet cloned = (HashSet) trackedPlayers.clone(); HashSet cloned = (HashSet) trackedPlayers.clone();
for (Object p : cloned) { for (final Object p : cloned) {
if (player.equalsIgnoreCase(((Player) ReflectionManager.getBukkitEntity(p)).getName())) { if (player.equalsIgnoreCase(((Player) ReflectionManager.getBukkitEntity(p)).getName())) {
clear.invoke(entityTrackerEntry, p); clear.invoke(entityTrackerEntry, p);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p); updatePlayer.invoke(entityTrackerEntry, p);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
break; break;
} }
} }
@ -500,23 +518,28 @@ public class DisguiseUtilities {
public static void refreshTrackers(Entity entity) { public static void refreshTrackers(Entity entity) {
if (entity.isValid()) { if (entity.isValid()) {
try { try {
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity); final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity);
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
entityTrackerEntry); entityTrackerEntry);
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
ReflectionManager.getNmsClass("EntityPlayer")); ReflectionManager.getNmsClass("EntityPlayer"));
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer")); ReflectionManager.getNmsClass("EntityPlayer"));
HashSet cloned = (HashSet) trackedPlayers.clone(); HashSet cloned = (HashSet) trackedPlayers.clone();
for (Object p : cloned) { for (final Object p : cloned) {
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(p);
// if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player)
// entity))
// continue;
if (player != entity) { if (player != entity) {
clear.invoke(entityTrackerEntry, p); clear.invoke(entityTrackerEntry, p);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p); updatePlayer.invoke(entityTrackerEntry, p);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
} }
} }
} }
@ -529,29 +552,43 @@ 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(final TargetedDisguise disguise) {
if (disguise.getEntity().isValid()) { if (disguise.getEntity().isValid()) {
try { try {
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) { if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
removeSelfDisguise((Player) disguise.getEntity());
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
} catch (Exception ex) {
ex.printStackTrace();
} }
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); }
});
}
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
entityTrackerEntry); entityTrackerEntry);
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
ReflectionManager.getNmsClass("EntityPlayer")); ReflectionManager.getNmsClass("EntityPlayer"));
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer")); ReflectionManager.getNmsClass("EntityPlayer"));
HashSet cloned = (HashSet) trackedPlayers.clone(); HashSet cloned = (HashSet) trackedPlayers.clone();
for (Object p : cloned) { for (final Object p : cloned) {
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(p);
// if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player)
// entity))
// continue;
if (disguise.getEntity() != player && disguise.canSee(player.getName())) { if (disguise.getEntity() != player && disguise.canSee(player.getName())) {
clear.invoke(entityTrackerEntry, p); clear.invoke(entityTrackerEntry, p);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p); updatePlayer.invoke(entityTrackerEntry, p);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
} }
} }
} }