From 5801356fbfcbbede78335e3a734ebabd9779c0fc Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 13 Apr 2014 13:15:04 +1200 Subject: [PATCH] Try avoid infinite loops when sending self disguise --- .../disguise/disguisetypes/Disguise.java | 2 +- .../disguise/disguisetypes/FlagWatcher.java | 2 +- .../disguise/utilities/DisguiseUtilities.java | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index ab6df813..7f625709 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -209,7 +209,7 @@ public abstract class Disguise { refreshDisguise = 0; DisguiseUtilities.refreshTrackers(disguise); if (getEntity() instanceof Player && isSelfDisguiseVisible()) { - DisguiseUtilities.sendSelfDisguise((Player) getEntity()); + DisguiseUtilities.sendSelfDisguise((Player) getEntity(), disguise); } } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 6455983e..6ed8e6a7 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -134,7 +134,7 @@ public class FlagWatcher { float newHealth = (Float) value; if (newHealth > 0 && hasDied) { hasDied = false; - DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity()); + DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise); } else if (newHealth <= 0 && !hasDied) { hasDied = true; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index f6e30a75..229e721c 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -480,9 +480,9 @@ public class DisguiseUtilities { /** * Sends the self disguise to the player */ - public static void sendSelfDisguise(final Player player) { + public static void sendSelfDisguise(final Player player, final Disguise disguise) { try { - if (!player.isValid()) { + if (!player.isValid() || !player.isOnline()) { return; } Object world = ReflectionManager.getWorld(player.getWorld()); @@ -494,9 +494,12 @@ public class DisguiseUtilities { // 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. // Else its going to run in a infinite loop hue hue hue.. + // At least until this disguise is discarded Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { public void run() { - sendSelfDisguise(player); + if (DisguiseAPI.getDisguise(player, player) == disguise) { + sendSelfDisguise(player, disguise); + } } }); return; @@ -633,7 +636,7 @@ public class DisguiseUtilities { } catch (Exception ex) { ex.printStackTrace(); } - sendSelfDisguise(player); + sendSelfDisguise(player, disguise); if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) { if (PacketsManager.isInventoryListenerEnabled()) { player.updateInventory();