diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index 25937b552f..2c93a48c95 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -108,7 +108,12 @@ public abstract class Event implements Serializable { LIVING_ENTITY, /** - * Represents Vehicle-based events + * Represents Weather-based events + */ + WEATHER, + + /** + * Vehicle-based events */ VEHICLE, @@ -592,6 +597,45 @@ public abstract class Event implements Serializable { */ ENTITY_INTERACT (Category.LIVING_ENTITY), + /** + * Called when a creeper gains or loses a power shell + * + * @see org.bukkit.event.entity.CreeperPowerEvent + */ + CREEPER_POWER (Category.LIVING_ENTITY), + + /** + * Called when a pig is zapped, zombifying it + * + * @see org.bukkit.event.entity.PigZapEvent + */ + PIG_ZAP (Category.LIVING_ENTITY), + + /** + * WEATHER EVENTS + */ + + /** + * Called when a lightning entity strikes somewhere + * + * @see org.bukkit.event.weather.LightningStrikeEvent + */ + LIGHTNING_STRIKE (Category.WEATHER), + + /** + * Called when the weather in a world changes + * + * @see org.bukkit.event.weather.WeatherChangeEvent + */ + WEATHER_CHANGE (Category.WEATHER), + + /** + * Called when the thunder state in a world changes + * + * @see org.bukkit.event.weather.ThunderChangeEvent + */ + THUNDER_CHANGE (Category.WEATHER), + /** * VEHICLE EVENTS */ diff --git a/paper-api/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java new file mode 100644 index 0000000000..54686f49fd --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java @@ -0,0 +1,89 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * Stores data for creepers being (un)powered + */ +public class CreeperPowerEvent extends EntityEvent implements Cancellable { + + private boolean canceled; + private Entity creeper; + private PowerCause cause; + private Entity bolt; + + public CreeperPowerEvent(Entity creeper, Entity bolt, PowerCause cause) { + super(Type.CREEPER_POWER, creeper); + this.creeper = creeper; + this.bolt = bolt; + this.cause = cause; + } + + public CreeperPowerEvent(Entity creeper, PowerCause cause) { + super(Type.CREEPER_POWER, creeper); + this.creeper = creeper; + this.cause = cause; + this.bolt = null; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the bolt which is striking the creeper. + * + * @return lightning entity + */ + public Entity getLightning() { + return bolt; + } + + /** + * Gets the cause of the creeper being (un)powered. + * @return A PowerCause value detailing the cause of change in power. + */ + public PowerCause getCause() { + return cause; + } + + /** + * An enum to specify the cause of the change in power + */ + public enum PowerCause { + /** + * Power change caused by a lightning bolt + * Powered state: true + */ + LIGHTNING, + + /** + * Power change caused by something else (probably a plugin) + * Powered state: true + */ + SET_ON, + + /** + * Power change caused by something else (probably a plugin) + * Powered state: false + */ + SET_OFF + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java index c0759aa9e0..234a3daa3c 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -40,4 +40,10 @@ public class EntityListener implements Listener { public void onPaintingBreak(PaintingBreakEvent event){ } + + public void onPigZap(PigZapEvent event) { + } + + public void onCreeperPower(CreeperPowerEvent event) { + } } diff --git a/paper-api/src/main/java/org/bukkit/event/entity/PigZapEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/PigZapEvent.java new file mode 100644 index 0000000000..0aca356ca9 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/PigZapEvent.java @@ -0,0 +1,61 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * Stores data for pigs being zapped + */ +public class PigZapEvent extends EntityEvent implements Cancellable { + + private boolean canceled; + private Entity pig; + private Entity pigzombie; + private Entity bolt; + + public PigZapEvent(Entity pig, Entity bolt, Entity pigzombie) { + super(Type.PIG_ZAP, pig); + this.pig = pig; + this.bolt = bolt; + this.pigzombie = pigzombie; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the bolt which is striking the pig. + * + * @return lightning entity + */ + public Entity getLightning() { + return bolt; + } + + /** + * Gets the zombie pig that will replace the pig, + * provided the event is not cancelled first. + * + * @return resulting entity + */ + public Entity getPigZombie() { + return pigzombie; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/weather/LightningStrikeEvent.java b/paper-api/src/main/java/org/bukkit/event/weather/LightningStrikeEvent.java new file mode 100644 index 0000000000..e28fdb520d --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/weather/LightningStrikeEvent.java @@ -0,0 +1,51 @@ +package org.bukkit.event.weather; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * Stores data for lightning striking + */ +public class LightningStrikeEvent extends WeatherEvent implements Cancellable { + + private boolean canceled; + private Entity bolt; + private World world; + + public LightningStrikeEvent(World world, Entity bolt) { + super(Type.LIGHTNING_STRIKE, world); + this.bolt = bolt; + this.world = world; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the bolt which is striking the earth. + * + * @return lightning entity + */ + public Entity getLightning() { + return bolt; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java b/paper-api/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java new file mode 100644 index 0000000000..6d7e07e570 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java @@ -0,0 +1,50 @@ +package org.bukkit.event.weather; + +import org.bukkit.World; +import org.bukkit.event.Cancellable; + +/** + * Stores data for thudner state changing in a world + */ +public class ThunderChangeEvent extends WeatherEvent implements Cancellable { + + private boolean canceled; + private boolean to; + private World world; + + public ThunderChangeEvent(World world, boolean to) { + super(Type.THUNDER_CHANGE, world); + this.world = world; + this.to = to; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the state of thunder that the world is being set to + * + * @return true if the weather is being set to thundering, false otherwise + */ + public boolean toThunderState() { + return to; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java b/paper-api/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java new file mode 100644 index 0000000000..be52a09cdc --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java @@ -0,0 +1,50 @@ +package org.bukkit.event.weather; + +import org.bukkit.World; +import org.bukkit.event.Cancellable; + +/** + * Stores data for weather changing in a world + */ +public class WeatherChangeEvent extends WeatherEvent implements Cancellable { + + private boolean canceled; + private boolean to; + private World world; + + public WeatherChangeEvent(World world, boolean to) { + super(Type.WEATHER_CHANGE, world); + this.world = world; + this.to = to; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the state of weather that the world is being set to + * + * @return true if the weather is being set to raining, false otherwise + */ + public boolean toWeatherState() { + return to; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/weather/WeatherEvent.java b/paper-api/src/main/java/org/bukkit/event/weather/WeatherEvent.java new file mode 100644 index 0000000000..a8694a3642 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/weather/WeatherEvent.java @@ -0,0 +1,24 @@ +package org.bukkit.event.weather; + +import org.bukkit.World; +import org.bukkit.event.Event; + +/** + * Represents an Weather-related event + */ +public class WeatherEvent extends Event { + protected World world; + + public WeatherEvent(final Event.Type type, final World where) { + super(type); + world = where; + } + + /** + * Returns the World where this event is occuring + * @return World this event is occuring in + */ + public final World getWorld() { + return world; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/weather/WeatherListener.java b/paper-api/src/main/java/org/bukkit/event/weather/WeatherListener.java new file mode 100644 index 0000000000..271a7896ef --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/weather/WeatherListener.java @@ -0,0 +1,21 @@ +package org.bukkit.event.weather; + +import org.bukkit.event.Listener; + +/** + * Handles all events fired in relation to weather + */ +public class WeatherListener implements Listener { + public WeatherListener() { + } + + public void onWeatherChange(WeatherChangeEvent event) { + } + + public void onThunderChange(ThunderChangeEvent event) { + } + + public void onLightningStrike(LightningStrikeEvent event) { + } + +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index c7fc725aac..bca6616a19 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -25,6 +25,7 @@ import org.bukkit.event.player.*; import org.bukkit.event.server.*; import org.bukkit.event.vehicle.*; import org.bukkit.event.world.*; +import org.bukkit.event.weather.*; import org.bukkit.plugin.*; import org.yaml.snakeyaml.error.YAMLException; @@ -515,6 +516,18 @@ public final class JavaPluginLoader implements PluginLoader { ((EntityListener) listener).onCreatureSpawn((CreatureSpawnEvent) event); } }; + case PIG_ZAP: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((EntityListener) listener).onPigZap((PigZapEvent) event); + } + }; + case CREEPER_POWER: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((EntityListener) listener).onCreeperPower((CreeperPowerEvent) event); + } + }; // Vehicle Events case VEHICLE_CREATE: @@ -571,6 +584,26 @@ public final class JavaPluginLoader implements PluginLoader { } }; + // Weather Events + case WEATHER_CHANGE: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((WeatherListener) listener).onWeatherChange((WeatherChangeEvent) event); + } + }; + case THUNDER_CHANGE: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((WeatherListener) listener).onThunderChange((ThunderChangeEvent) event); + } + }; + case LIGHTNING_STRIKE: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((WeatherListener) listener).onLightningStrike((LightningStrikeEvent) event); + } + }; + // Custom Events case CUSTOM_EVENT: return new EventExecutor() {