}
@EventHandler
public void vehicleMove(VehicleMoveEvent event) {
if (event.getVehicle().getPassenger() instanceof Player) {
Vehicle v = event.getVehicle();
Player p = (Player) v.getPassenger();
PortalPlayerSession ps = this.plugin.getPortalSession(p);
ps.setStaleLocation(v.getLocation(), MoveType.VEHICLE_MOVE);
if (ps.isStaleLocation()) {
return;
}
// Teleport the Player
teleportVehicle(p, v, event.getTo());
} else {
MVPortal portal = this.plugin.getPortalManager().getPortal(event.getFrom());
if ((portal != null) && (portal.getTeleportNonPlayers())) {
MVDestination dest = portal.getDestination();
if (dest == null || dest instanceof InvalidDestination)
return;
// Check the portal's frame.
if (!portal.isFrameValid(event.getVehicle().getLocation())) {
return;
}
Vector vehicleVec = event.getVehicle().getVelocity();
Location target = dest.getLocation(event.getVehicle());
if (dest instanceof PortalDestination) {
PortalDestination pd = (PortalDestination) dest;
// Translate the direction of travel.
vehicleVec = this.locationManipulation.getTranslatedVector(vehicleVec, pd.getOrientationString());
}
this.setVehicleVelocity(vehicleVec, dest, event.getVehicle());
Entity formerPassenger = event.getVehicle().getPassenger();
event.getVehicle().eject();
Vehicle newVehicle = target.getWorld().spawn(target, event.getVehicle().getClass());
if (formerPassenger != null) {
formerPassenger.teleport(target);
newVehicle.setPassenger(formerPassenger);
}
this.setVehicleVelocity(vehicleVec, dest, newVehicle);
// remove the old one