From 7c5a7b0225c734ee124f0ce6fb70e4ca828e2251 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 15 Jun 2014 14:57:06 +1200 Subject: [PATCH] Move Disguise and Undisguise events into the Disguise methods instead of the api calls --- src/me/libraryaddict/disguise/DisguiseAPI.java | 12 ------------ .../disguise/disguisetypes/Disguise.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index b5475994..60dcc9ec 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -18,7 +18,6 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.ReflectionManager; @@ -149,13 +148,6 @@ public class DisguiseAPI { // Just return. if (entity == null || disguise == null) return; - // Fire a disguise event - DisguiseEvent event = new DisguiseEvent(entity, disguise); - Bukkit.getPluginManager().callEvent(event); - // If they cancelled this disguise event. No idea why. - // Just return. - if (event.isCancelled()) - return; // The event wasn't cancelled. // If the disguise entity isn't the same as the one we are disguising if (disguise.getEntity() != entity) { @@ -331,10 +323,6 @@ public class DisguiseAPI { public static void undisguiseToAll(Entity entity) { Disguise[] disguises = getDisguises(entity); for (Disguise disguise : disguises) { - UndisguiseEvent event = new UndisguiseEvent(entity, disguise); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - continue; disguise.removeDisguise(); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index ff956897..35a5eb8c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -13,6 +13,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; +import me.libraryaddict.disguise.events.DisguiseEvent; +import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; @@ -404,6 +406,10 @@ public abstract class Disguise { */ public void removeDisguise() { if (disguiseInUse) { + UndisguiseEvent event = new UndisguiseEvent(entity, this); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; disguiseInUse = false; if (task != null) { task.cancel(); @@ -657,6 +663,13 @@ public abstract class Disguise { if (getEntity() == null) { throw new RuntimeException("No entity is assigned to this disguise!"); } + // Fire a disguise event + DisguiseEvent event = new DisguiseEvent(entity, this); + Bukkit.getPluginManager().callEvent(event); + // If they cancelled this disguise event. No idea why. + // Just return. + if (event.isCancelled()) + return; disguiseInUse = true; task = Bukkit.getScheduler().runTaskTimer(plugin, velocityRunnable, 1, 1); // Stick the disguise in the disguises bin