diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index e3eacef1..d4cfcc48 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -9,12 +9,16 @@ import me.libraryaddict.disguise.DisguiseTypes.DisguiseSound; import me.libraryaddict.disguise.DisguiseTypes.DisguiseType; import me.libraryaddict.disguise.DisguiseTypes.DisguiseSound.SoundType; import me.libraryaddict.disguise.DisguiseTypes.MobDisguise; +import me.libraryaddict.disguise.Events.DisguisedEvent; +import me.libraryaddict.disguise.Events.RedisguisedEvent; +import me.libraryaddict.disguise.Events.UndisguisedEvent; import net.minecraft.server.v1_6_R2.Block; import net.minecraft.server.v1_6_R2.EntityPlayer; import net.minecraft.server.v1_6_R2.EntityTrackerEntry; import net.minecraft.server.v1_6_R2.World; import net.minecraft.server.v1_6_R2.WorldServer; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftLivingEntity; @@ -60,11 +64,21 @@ public class DisguiseAPI { public static void disguiseToAll(Entity entity, Disguise disguise) { if (disguise == null) return; + Disguise oldDisguise = getDisguise(entity); + if (oldDisguise != null) { + RedisguisedEvent event = new RedisguisedEvent(entity, oldDisguise, disguise); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + oldDisguise.getScheduler().cancel(); + } else { + DisguisedEvent event = new DisguisedEvent(entity, disguise); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + } if (disguise.getWatcher() != null) disguise = disguise.clone(); - Disguise oldDisguise = getDisguise(entity); - if (oldDisguise != null) - oldDisguise.getScheduler().cancel(); put(entity, disguise); disguise.constructWatcher(plugin, entity); refresh(entity); @@ -315,6 +329,10 @@ public class DisguiseAPI { Disguise disguise = getDisguise(entity); if (disguise == null) return; + UndisguisedEvent event = new UndisguisedEvent(entity, disguise); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; disguise.getScheduler().cancel(); put(entity, null); if (entity.isValid()) { diff --git a/src/me/libraryaddict/disguise/Events/DisguisedEvent.java b/src/me/libraryaddict/disguise/Events/DisguisedEvent.java new file mode 100644 index 00000000..fc22069d --- /dev/null +++ b/src/me/libraryaddict/disguise/Events/DisguisedEvent.java @@ -0,0 +1,46 @@ +package me.libraryaddict.disguise.Events; + +import me.libraryaddict.disguise.DisguiseTypes.Disguise; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class DisguisedEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private Disguise disguise; + private Entity disguised; + private boolean isCancelled; + + public DisguisedEvent(Entity entity, Disguise disguise) { + this.disguised = entity; + this.disguise = disguise; + } + + public Disguise getDisguise() { + return disguise; + } + + public Entity getDisguised() { + return disguised; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + isCancelled = cancelled; + } +} \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/Events/RedisguisedEvent.java b/src/me/libraryaddict/disguise/Events/RedisguisedEvent.java new file mode 100644 index 00000000..65312e90 --- /dev/null +++ b/src/me/libraryaddict/disguise/Events/RedisguisedEvent.java @@ -0,0 +1,52 @@ +package me.libraryaddict.disguise.Events; + +import me.libraryaddict.disguise.DisguiseTypes.Disguise; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class RedisguisedEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private Disguise oldDisguise; + private Disguise newDisguise; + private Entity disguised; + private boolean isCancelled; + + public RedisguisedEvent(Entity entity, Disguise oldDisguise, Disguise newDisguise) { + this.disguised = entity; + this.oldDisguise = oldDisguise; + this.newDisguise = newDisguise; + } + + public Disguise getOldDisguise() { + return oldDisguise; + } + + public Disguise getNewDisguise() { + return newDisguise; + } + + public Entity getDisguised() { + return disguised; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + isCancelled = cancelled; + } +} \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/Events/UndisguisedEvent.java b/src/me/libraryaddict/disguise/Events/UndisguisedEvent.java new file mode 100644 index 00000000..09558518 --- /dev/null +++ b/src/me/libraryaddict/disguise/Events/UndisguisedEvent.java @@ -0,0 +1,46 @@ +package me.libraryaddict.disguise.Events; + +import me.libraryaddict.disguise.DisguiseTypes.Disguise; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class UndisguisedEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private Disguise disguise; + private Entity disguised; + private boolean isCancelled; + + public UndisguisedEvent(Entity entity, Disguise disguise) { + this.disguised = entity; + this.disguise = disguise; + } + + public Disguise getDisguise() { + return disguise; + } + + public Entity getDisguised() { + return disguised; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + isCancelled = cancelled; + } +} \ No newline at end of file