From 239bc6d6457d19fc486e23b2136cb4d8547560c2 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 4 Jun 2014 14:12:09 +1200 Subject: [PATCH] Check a second after the future disguise was added that it was successful. --- .../disguise/utilities/DisguiseUtilities.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index c6e6fd4e..20e155f6 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -24,11 +24,13 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.Ageable; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Zombie; import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import com.comphenix.protocol.PacketType; @@ -91,11 +93,33 @@ public class DisguiseUtilities { } } - public static void addFutureDisguise(int entityId, TargetedDisguise disguise) { + public static void addFutureDisguise(final int entityId, final TargetedDisguise disguise) { if (!futureDisguises.containsKey(entityId)) { futureDisguises.put(entityId, new HashSet()); } futureDisguises.get(entityId).add(disguise); + final BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + if (futureDisguises.containsKey(entityId) && futureDisguises.get(entityId).contains(disguise)) { + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getEntityId() == entityId) { + UUID uniqueId = entity.getUniqueId(); + for (TargetedDisguise disguise : futureDisguises.remove(entityId)) { + addDisguise(uniqueId, disguise); + } + return; + } + } + } + futureDisguises.get(entityId).remove(disguise); + if (futureDisguises.get(entityId).isEmpty()) { + futureDisguises.remove(entityId); + } + } + } + }; + runnable.runTaskLater(libsDisguises, 20); } public static void addGameProfile(String string, Object gameProfile) {