Program: 5415
Project: 5415
Buggy source:
/** 
 * Teleports the passed in Entity through the portal. Given an Entity object, attempts to teleport them through the portal. This involves many steps. 1) Verify the portal on the other end still exists. If it doesn't, mark this as such. 2) If there is no counterpart, figure out where it would be, and get it. This may involve generating and placing a portal into the world. 3) Assuming we now have a counterpart, figure out where to teleport the entity to. 3a) Figure out the entity's position relative to the entry portal. 3b) Translate this to a position relative to the exit portal. 3c) Preserve the entity's camera's orientation relative to the portal. 4) Teleport the entity. 4a) If the entity is a Player in a vehicle, we do a dance. - Raise the destination by 1 (vehicles have to 'fall' into the portal to avoid losing momentum, so they should be one higher). - Make the player leave the vehicle. - Spawn a new minecart at the destination. - Teleport the player to the destination. - Make the player a passenger of the minecart. - Give the new minecart the (properly translated) velocity of the old vehicle. - Remove the old vehicle.
 * @param e The entity to teleport.
 * @return The location the entity was teleported to, or null if theentity was not teleported.
 */
public Location teleport(Entity e){
  if (this.counterpart != null) {
    if (!this.counterpart.isValid()) {
      PortalUtil.removePortal(this.counterpart);
      this.counterpart=null;
      PortalUtil.getCounterpartPortalFor(this);
    }
  }
 else {
    PortalUtil.getCounterpartPortalFor(this);
  }
  if (this.counterpart == null) {
    return null;
  }
  double destX, destY, destZ;
  float destPitch, destYaw;
  int rotateVehicleVelocity=0;
  Vector offset=e.getLocation().toVector().subtract(this.keyBlock.getLocation().toVector());
  Vector finalOffset;
  if (this.facingNorth) {
    if (offset.getX() < .5) {
      offset.setX(offset.getX() + 1);
    }
 else {
      offset.setX(offset.getX() - 1);
    }
    if (this.counterpart.isFacingNorth()) {
      destYaw=e.getLocation().getYaw();
      finalOffset=offset;
    }
 else {
      destYaw=e.getLocation().getYaw() - 90;
      finalOffset=new Vector(offset.getZ(),offset.getY(),-offset.getX() + 1);
      rotateVehicleVelocity=1;
    }
  }
 else {
    if (offset.getZ() < .5) {
      offset.setZ(offset.getZ() + 1);
    }
 else {
      offset.setZ(offset.getZ() - 1);
    }
    if (this.counterpart.isFacingNorth()) {
      destYaw=e.getLocation().getYaw() + 90;
      finalOffset=new Vector(-offset.getZ() + 1,offset.getY(),offset.getX());
      rotateVehicleVelocity=2;
    }
 else {
      destYaw=e.getLocation().getYaw();
      finalOffset=offset;
    }
  }
  World destWorld=this.counterpart.getKeyBlock().getWorld();
  destX=this.counterpart.getKeyBlock().getX() + finalOffset.getX();
  destY=this.counterpart.getKeyBlock().getY() + finalOffset.getY();
  destZ=this.counterpart.getKeyBlock().getZ() + finalOffset.getZ();
  destPitch=e.getLocation().getPitch();
  if (e instanceof Player && ((Player)e).isInsideVehicle() || e instanceof Vehicle) {
    destY+=1.0;
  }
  Location dest;
  dest=new Location(destWorld,destX,destY,destZ,destYaw,destPitch);
  Chunk destChunk=dest.getBlock().getChunk();
  for (int dx=-1; dx <= 1; dx++) {
    for (int dz=-1; dz <= 1; dz++) {
      destWorld.loadChunk(destChunk.getX() + dx,destChunk.getZ() + dz);
    }
  }
  Vehicle oldV=null, newV=null;
  if (e instanceof Player) {
    if (((Player)e).isInsideVehicle()) {
      oldV=((Player)e).getVehicle();
      ((Player)e).leaveVehicle();
    }
  }
 else   if (e instanceof StorageMinecart || e instanceof Minecart || e instanceof Boat) {
    oldV=((Vehicle)e);
  }
  if (oldV != null) {
    if (oldV instanceof StorageMinecart) {
      newV=destWorld.spawn(dest,StorageMinecart.class);
      ((StorageMinecart)newV).getInventory().setContents(((StorageMinecart)oldV).getInventory().getContents());
    }
 else     if (oldV instanceof Minecart) {
      newV=destWorld.spawn(dest,Minecart.class);
    }
 else     if (oldV instanceof Boat) {
      newV=destWorld.spawn(dest,Boat.class);
    }
 else {
      log.warning("String_Node_Str");
    }
    Vector oldVelocity=oldV.getVelocity();
    Vector newVelocity;
switch (rotateVehicleVelocity) {
case 1:
      newVelocity=new Vector(oldVelocity.getZ(),oldVelocity.getY(),oldVelocity.getX() * -1);
    break;
case 2:
  newVelocity=new Vector(oldVelocity.getZ() * -1,oldVelocity.getY(),oldVelocity.getX());
break;
default :
newVelocity=oldVelocity;
break;
}
final Location threadDest=dest;
final Entity threadE=e;
final Vehicle threadOldV=oldV;
final Vehicle threadNewV=newV;
final Vector threadNewVelocity=newVelocity;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(PortalUtil.getPlugin(),new Runnable(){
public void run(){
if (threadE instanceof Player) {
if (((Player)threadE).teleport(threadDest)) {
World destWorld=threadE.getLocation().getWorld();
Chunk destChunk=threadE.getLocation().getBlock().getChunk();
int x=destChunk.getX(), z=destChunk.getZ();
for (int dx=-1; dx <= 1; dx++) {
  for (int dz=-1; dz <= 1; dz++) {
    destWorld.refreshChunk(x + dx,z + dz);
  }
}
}
 else {
return;
}
}
if (threadNewV != null) {
if (threadE instanceof Player) {
threadNewV.setPassenger(threadE);
}
threadNewV.setVelocity(threadNewVelocity);
}
Bukkit.getServer().getPluginManager().callEvent(new NethrarVehicleTeleportEvent(threadOldV,threadNewV));
threadOldV.remove();
}
}
);
}
 else {
final Location threadDest=dest;
final Entity threadE=e;
return dest;
}
return null;
}

Fixed version (ground truth):
/** 
 * Teleports the passed in Entity through the portal. Given an Entity object, attempts to teleport them through the portal. This involves many steps. 1) Verify the portal on the other end still exists. If it doesn't, mark this as such. 2) If there is no counterpart, figure out where it would be, and get it. This may involve generating and placing a portal into the world. 3) Assuming we now have a counterpart, figure out where to teleport the entity to. 3a) Figure out the entity's position relative to the entry portal. 3b) Translate this to a position relative to the exit portal. 3c) Preserve the entity's camera's orientation relative to the portal. 4) Teleport the entity. 4a) If the entity is a Player in a vehicle, we do a dance. - Raise the destination by 1 (vehicles have to 'fall' into the portal to avoid losing momentum, so they should be one higher). - Make the player leave the vehicle. - Spawn a new minecart at the destination. - Teleport the player to the destination. - Make the player a passenger of the minecart. - Give the new minecart the (properly translated) velocity of the old vehicle. - Remove the old vehicle.
 * @param e The entity to teleport.
 * @return The location the entity was teleported to, or null if theentity was not teleported.
 */
public Location teleport(Entity e,Location interaction){
  if (this.counterpart != null) {
    if (!this.counterpart.isValid()) {
      PortalUtil.removePortal(this.counterpart);
      this.counterpart=null;
      PortalUtil.getCounterpartPortalFor(this);
    }
  }
 else {
    PortalUtil.getCounterpartPortalFor(this);
  }
  if (this.counterpart == null) {
    return null;
  }
  double destX, destY, destZ;
  float destPitch, destYaw;
  int rotateVehicleVelocity=0;
  Vector offset=interaction.toVector().subtract(this.keyBlock.getLocation().toVector());
  Vector finalOffset;
  if (this.facingNorth) {
    if (offset.getX() < .5) {
      offset.setX(offset.getX() + OFFSET);
    }
 else {
      offset.setX(offset.getX() - OFFSET);
    }
    if (this.counterpart.isFacingNorth()) {
      destYaw=e.getLocation().getYaw();
      finalOffset=offset;
    }
 else {
      destYaw=e.getLocation().getYaw() - 90;
      finalOffset=new Vector(offset.getZ(),offset.getY(),-offset.getX() + 1);
      rotateVehicleVelocity=1;
    }
  }
 else {
    if (offset.getZ() < .5) {
      offset.setZ(offset.getZ() + OFFSET);
    }
 else {
      offset.setZ(offset.getZ() - OFFSET);
    }
    if (this.counterpart.isFacingNorth()) {
      destYaw=e.getLocation().getYaw() + 90;
      finalOffset=new Vector(-offset.getZ() + 1,offset.getY(),offset.getX());
      rotateVehicleVelocity=2;
    }
 else {
      destYaw=e.getLocation().getYaw();
      finalOffset=offset;
    }
  }
  World destWorld=this.counterpart.getKeyBlock().getWorld();
  destX=this.counterpart.getKeyBlock().getX() + finalOffset.getX();
  destY=this.counterpart.getKeyBlock().getY() + finalOffset.getY();
  destZ=this.counterpart.getKeyBlock().getZ() + finalOffset.getZ();
  destPitch=e.getLocation().getPitch();
  if (e instanceof Player && ((Player)e).isInsideVehicle() || e instanceof Vehicle) {
    destY+=1.0;
  }
  Location dest;
  dest=new Location(destWorld,destX,destY,destZ,destYaw,destPitch);
  Chunk destChunk=dest.getBlock().getChunk();
  for (int dx=-1; dx <= 1; dx++) {
    for (int dz=-1; dz <= 1; dz++) {
      destWorld.loadChunk(destChunk.getX() + dx,destChunk.getZ() + dz);
    }
  }
  Vehicle oldV=null, newV=null;
  if (e instanceof Player) {
    if (((Player)e).isInsideVehicle()) {
      oldV=((Player)e).getVehicle();
      ((Player)e).leaveVehicle();
    }
  }
 else   if (e instanceof StorageMinecart || e instanceof Minecart || e instanceof Boat) {
    oldV=((Vehicle)e);
  }
  if (oldV != null) {
    if (oldV instanceof StorageMinecart) {
      newV=destWorld.spawn(dest,StorageMinecart.class);
      ((StorageMinecart)newV).getInventory().setContents(((StorageMinecart)oldV).getInventory().getContents());
    }
 else     if (oldV instanceof Minecart) {
      newV=destWorld.spawn(dest,Minecart.class);
    }
 else     if (oldV instanceof Boat) {
      newV=destWorld.spawn(dest,Boat.class);
    }
 else {
      log.warning("String_Node_Str");
    }
    Vector oldVelocity=oldV.getVelocity();
    Vector newVelocity;
switch (rotateVehicleVelocity) {
case 1:
      newVelocity=new Vector(oldVelocity.getZ(),oldVelocity.getY(),oldVelocity.getX() * -1);
    break;
case 2:
  newVelocity=new Vector(oldVelocity.getZ() * -1,oldVelocity.getY(),oldVelocity.getX());
break;
default :
newVelocity=oldVelocity;
break;
}
final Location threadDest=dest;
final Entity threadE=e;
final Vehicle threadOldV=oldV;
final Vehicle threadNewV=newV;
final Vector threadNewVelocity=newVelocity;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(PortalUtil.getPlugin(),new Runnable(){
public void run(){
if (threadE instanceof Player) {
if (((Player)threadE).teleport(threadDest)) {
World destWorld=threadE.getLocation().getWorld();
Chunk destChunk=threadE.getLocation().getBlock().getChunk();
int x=destChunk.getX(), z=destChunk.getZ();
for (int dx=-1; dx <= 1; dx++) {
  for (int dz=-1; dz <= 1; dz++) {
    destWorld.refreshChunk(x + dx,z + dz);
  }
}
}
 else {
return;
}
}
if (threadNewV != null) {
if (threadE instanceof Player) {
threadNewV.setPassenger(threadE);
}
threadNewV.setVelocity(threadNewVelocity);
}
Bukkit.getServer().getPluginManager().callEvent(new NethrarVehicleTeleportEvent(threadOldV,threadNewV));
threadOldV.remove();
}
}
);
}
 else {
final Location threadDest=dest;
final Entity threadE=e;
return dest;
}
return null;
}