Move Disguise and Undisguise events into the Disguise methods instead of the api calls

This commit is contained in:
libraryaddict 2014-06-15 14:57:06 +12:00
parent 264b2ef8a2
commit 7c5a7b0225
2 changed files with 13 additions and 12 deletions

View File

@ -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();
}
}

View File

@ -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