added cancellable EggCaptureEvent

This commit is contained in:
Andre LeBlanc 2013-02-13 12:14:32 -05:00
parent 2787a65585
commit b1b7dbd71d
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package me.shansen.EggCatcher.events;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;
public class EggCaptureEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
boolean cancelled = false;
Egg egg;
public EggCaptureEvent(Entity what, Egg egg) {
super(what);
this.egg = egg;
}
public boolean isCancelled() {
return this.cancelled;
}
public Egg getEgg() {
return this.egg;
}
public void setCancelled(boolean isCancelled) {
this.cancelled = isCancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package me.shansen.EggCatcher.listeners;
import me.shansen.EggCatcher.events.EggCaptureEvent;
import me.shansen.EggCatcher.EggCatcher;
import me.shansen.EggCatcher.EggType;
@ -142,6 +143,13 @@ public class EggCatcherEntityListener implements Listener {
}
}
EggCaptureEvent eggCaptureEvent = new EggCaptureEvent(entity, egg);
this.plugin.getServer().getPluginManager().callEvent(eggCaptureEvent);
if (eggCaptureEvent.isCancelled()) {
return;
}
if (egg.getShooter() instanceof Player) {
Player player = (Player) egg.getShooter();