mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-29 03:31:27 +01:00
Implemented vehicle hooks (some changes will still be made).
By: sk89q <the.sk89q@gmail.com>
This commit is contained in:
parent
339e57513a
commit
2ff558c10b
@ -337,12 +337,12 @@ public abstract class Event {
|
|||||||
/**
|
/**
|
||||||
* Called when a vehicle is placed by a player
|
* 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
|
* 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
|
* 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
|
* 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
|
* 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
|
* Called when a vehicle moves position in the world
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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) {
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,7 @@ import org.bukkit.event.block.*;
|
|||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.server.PluginEvent;
|
import org.bukkit.event.server.PluginEvent;
|
||||||
import org.bukkit.event.server.ServerListener;
|
import org.bukkit.event.server.ServerListener;
|
||||||
|
import org.bukkit.event.vehicle.*;
|
||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,6 +133,32 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||||||
trueListener.onPluginDisabled((PluginEvent)event);
|
trueListener.onPluginDisabled((PluginEvent)event);
|
||||||
break;
|
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) {
|
} else if(listener instanceof CustomEventListener) {
|
||||||
if(event.getType()==Event.Type.CUSTOM_EVENT) {
|
if(event.getType()==Event.Type.CUSTOM_EVENT) {
|
||||||
((CustomEventListener)listener).onCustomEvent(event);
|
((CustomEventListener)listener).onCustomEvent(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user