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 2559fd1472..51992ad361 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -337,12 +337,12 @@ public abstract class Event { /** * Called when a vehicle is placed by a player */ - VEHICLE_PLACED (Category.VEHICLE), + VEHICLE_PLACE (Category.VEHICLE), /** * Called when a vehicle is damaged by a LivingEntity */ - VEHICLE_DAMAGED (Category.VEHICLE), + VEHICLE_DAMAGE (Category.VEHICLE), /** * Called when a vehicle collides with an Entity @@ -357,12 +357,12 @@ public abstract class Event { /** * Called when a vehicle is entered by a LivingEntity */ - VEHICLE_ENTERED (Category.VEHICLE), + VEHICLE_ENTER (Category.VEHICLE), /** * Called when a vehicle is exited by a LivingEntity */ - VEHICLE_EXITED (Category.VEHICLE), + VEHICLE_EXIT (Category.VEHICLE), /** * Called when a vehicle moves position in the world diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java new file mode 100644 index 0000000000..6141c1c12e --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java @@ -0,0 +1,22 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Block; +import org.bukkit.Vehicle; + +/** + * Raised when a vehicle collides with a block. + * + * @author sk89q + */ +public class VehicleBlockCollisionEvent extends VehicleCollisionEvent { + private Block block; + + public VehicleBlockCollisionEvent(Type type, Vehicle vehicle, Block block) { + super(type, vehicle); + this.block = block; + } + + public Block getBlock() { + return block; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCollisionEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCollisionEvent.java new file mode 100644 index 0000000000..6e4bb48a89 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCollisionEvent.java @@ -0,0 +1,14 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Vehicle; + +/** + * Raised when a vehicle collides. + * + * @author sk89q + */ +public class VehicleCollisionEvent extends VehicleEvent { + public VehicleCollisionEvent(Type type, Vehicle vehicle) { + super(type, vehicle); + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleDamageEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleDamageEvent.java new file mode 100644 index 0000000000..fd112bd6ce --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleDamageEvent.java @@ -0,0 +1,26 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Vehicle; +import org.bukkit.event.Cancellable; + +/** + * Raised when a vehicle receives damage. + * + * @author sk89q + */ +public class VehicleDamageEvent extends VehicleEvent implements Cancellable { + private boolean cancelled; + + public VehicleDamageEvent(Type type, Vehicle vehicle) { + super(type, vehicle); + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java new file mode 100644 index 0000000000..da8fc30c3c --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java @@ -0,0 +1,38 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.LivingEntity; +import org.bukkit.Vehicle; +import org.bukkit.event.Cancellable; + +/** + * Raised when a living entity enters a vehicle. + * + * @author sk89q + */ +public class VehicleEnterEvent extends VehicleEvent implements Cancellable { + private boolean cancelled; + private LivingEntity entered; + + public VehicleEnterEvent(Type type, Vehicle vehicle, LivingEntity entered) { + super(type, vehicle); + + this.entered = entered; + } + + /** + * Get the living entity that entered the vehicle. + * + * @return + */ + public LivingEntity getEntered() { + return entered; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java new file mode 100644 index 0000000000..fe2c3b71c6 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java @@ -0,0 +1,22 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Entity; +import org.bukkit.Vehicle; + +/** + * Raised when a vehicle collides with an entity. + * + * @author sk89q + */ +public class VehicleEntityCollisionEvent extends VehicleCollisionEvent { + private Entity entity; + + public VehicleEntityCollisionEvent(Type type, Vehicle vehicle, Entity entity) { + super(type, vehicle); + this.entity = entity; + } + + public Entity getEntity() { + return entity; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEvent.java new file mode 100644 index 0000000000..b08c334046 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEvent.java @@ -0,0 +1,27 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Vehicle; +import org.bukkit.event.Event; + +/** + * Represents a vehicle-related event. + * + * @author sk89q + */ +public class VehicleEvent extends Event { + protected Vehicle vehicle; + + public VehicleEvent(final Event.Type type, final Vehicle vehicle) { + super(type); + this.vehicle = vehicle; + } + + /** + * Get the vehicle. + * + * @return the vehicle + */ + public final Vehicle getVehicle() { + return vehicle; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleExitEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleExitEvent.java new file mode 100644 index 0000000000..957571edd6 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleExitEvent.java @@ -0,0 +1,38 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.LivingEntity; +import org.bukkit.Vehicle; +import org.bukkit.event.Cancellable; + +/** + * Raised when a living entity exits a vehicle. + * + * @author sk89q + */ +public class VehicleExitEvent extends VehicleEvent implements Cancellable { + private boolean cancelled; + private LivingEntity exited; + + public VehicleExitEvent(Type type, Vehicle vehicle, LivingEntity exited) { + super(type, vehicle); + + this.exited = exited; + } + + /** + * Get the living entity that exited the vehicle. + * + * @return + */ + public LivingEntity getExited() { + return exited; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleListener.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleListener.java new file mode 100644 index 0000000000..95e6e2df49 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleListener.java @@ -0,0 +1,64 @@ +package org.bukkit.event.vehicle; + +/** + * Listener for vehicle events. + * + * @author sk89q + */ +public class VehicleListener { + /** + * Called when a vehicle is placed by a player. + * + * @param event + */ + public void onVehiclePlace(VehiclePlaceEvent event) { + } + + /** + * Called when a vehicle is damaged by the player. + * + * @param event + */ + public void onVehicleDamage(VehicleDamageEvent event) { + } + + /** + * Called when a vehicle collides with a block. + * + * @param event + */ + public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) { + } + + /** + * Called when a vehicle collides with an entity. + * + * @param event + */ + public void onVehicleEntityCollision(VehicleEntityCollisionEvent event) { + } + + /** + * Called when an entity enters a vehicle. + * + * @param event + */ + public void onVehicleEnter(VehicleEnterEvent event) { + } + + /** + * Called when an entity exits a vehicle. + * + * @param event + */ + public void onVehicleExit(VehicleExitEvent event) { + } + + /** + * Called when an vehicle moves. + * + * @param event + */ + public void onVehicleMove(VehicleMoveEvent event) { + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java new file mode 100644 index 0000000000..65921ad489 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java @@ -0,0 +1,40 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Location; +import org.bukkit.Vehicle; + +/** + * Raised when a vehicle moves. + * + * @author sk89q + */ +public class VehicleMoveEvent extends VehicleEvent { + private Location from; + private Location to; + + public VehicleMoveEvent(Type type, Vehicle vehicle, + Location from, Location to) { + super(type, vehicle); + + this.from = from; + this.to = to; + } + + /** + * Get the previous position. + * + * @return + */ + public Location getFrom() { + return from; + } + + /** + * Get the next position. + * + * @return + */ + public Location getTo() { + return to; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehiclePlaceEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehiclePlaceEvent.java new file mode 100644 index 0000000000..446288790c --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehiclePlaceEvent.java @@ -0,0 +1,26 @@ +package org.bukkit.event.vehicle; + +import org.bukkit.Vehicle; +import org.bukkit.event.Cancellable; + +/** + * Raised when a vehicle is placed by a player. + * + * @author sk89q + */ +public class VehiclePlaceEvent extends VehicleEvent implements Cancellable { + private boolean cancelled; + + public VehiclePlaceEvent(Type type, Vehicle vehicle) { + super(type, vehicle); + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + +} 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 667fcb3f2c..56fcbe7984 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 @@ -19,6 +19,7 @@ import org.bukkit.event.block.*; import org.bukkit.event.player.*; import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.ServerListener; +import org.bukkit.event.vehicle.*; import org.bukkit.plugin.*; /** @@ -132,6 +133,32 @@ public final class JavaPluginLoader implements PluginLoader { trueListener.onPluginDisabled((PluginEvent)event); break; } + } else if (listener instanceof VehicleListener) { + VehicleListener trueListener = (VehicleListener)listener; + + switch (event.getType()) { + case VEHICLE_PLACE: + trueListener.onVehiclePlace((VehiclePlaceEvent)event); + break; + case VEHICLE_DAMAGE: + trueListener.onVehicleDamage((VehicleDamageEvent)event); + break; + case VEHICLE_COLLISION_BLOCK: + trueListener.onVehicleBlockCollision((VehicleBlockCollisionEvent)event); + break; + case VEHICLE_COLLISION_ENTITY: + trueListener.onVehicleEntityCollision((VehicleEntityCollisionEvent)event); + break; + case VEHICLE_ENTER: + trueListener.onVehicleEnter((VehicleEnterEvent)event); + break; + case VEHICLE_EXIT: + trueListener.onVehicleExit((VehicleExitEvent)event); + break; + case VEHICLE_MOVE: + trueListener.onVehicleMove((VehicleMoveEvent)event); + break; + } } else if(listener instanceof CustomEventListener) { if(event.getType()==Event.Type.CUSTOM_EVENT) { ((CustomEventListener)listener).onCustomEvent(event);