001 package org.bukkit.event.entity; 002 003 import org.bukkit.entity.Creeper; 004 import org.bukkit.entity.LightningStrike; 005 import org.bukkit.event.Cancellable; 006 import org.bukkit.event.HandlerList; 007 008 /** 009 * Called when a Creeper is struck by lightning. 010 * <p> 011 * If a Creeper Power event is cancelled, the Creeper will not be powered. 012 */ 013 public class CreeperPowerEvent extends EntityEvent implements Cancellable { 014 private static final HandlerList handlers = new HandlerList(); 015 private boolean canceled; 016 private final PowerCause cause; 017 private LightningStrike bolt; 018 019 public CreeperPowerEvent(final Creeper creeper, final LightningStrike bolt, final PowerCause cause) { 020 this(creeper, cause); 021 this.bolt = bolt; 022 } 023 024 public CreeperPowerEvent(final Creeper creeper, final PowerCause cause) { 025 super(creeper); 026 this.cause = cause; 027 } 028 029 public boolean isCancelled() { 030 return canceled; 031 } 032 033 public void setCancelled(boolean cancel) { 034 canceled = cancel; 035 } 036 037 @Override 038 public Creeper getEntity() { 039 return (Creeper) entity; 040 } 041 042 /** 043 * Gets the lightning bolt which is striking the Creeper. 044 * 045 * @return The Entity for the lightning bolt which is striking the Creeper 046 */ 047 public LightningStrike getLightning() { 048 return bolt; 049 } 050 051 /** 052 * Gets the cause of the creeper being (un)powered. 053 * 054 * @return A PowerCause value detailing the cause of change in power. 055 */ 056 public PowerCause getCause() { 057 return cause; 058 } 059 060 @Override 061 public HandlerList getHandlers() { 062 return handlers; 063 } 064 065 public static HandlerList getHandlerList() { 066 return handlers; 067 } 068 069 /** 070 * An enum to specify the cause of the change in power 071 */ 072 public enum PowerCause { 073 074 /** 075 * Power change caused by a lightning bolt 076 * <p> 077 * Powered state: true 078 */ 079 LIGHTNING, 080 /** 081 * Power change caused by something else (probably a plugin) 082 * <p> 083 * Powered state: true 084 */ 085 SET_ON, 086 /** 087 * Power change caused by something else (probably a plugin) 088 * <p> 089 * Powered state: false 090 */ 091 SET_OFF 092 } 093 }