Add events

This commit is contained in:
Andrew 2013-07-24 12:16:54 +12:00
parent a0892c56c1
commit b809790ea3
4 changed files with 165 additions and 3 deletions

View File

@ -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()) {

View File

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

View File

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

View File

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