}
public static void teleport(final Minecart cart, Location destination) {
EntityType type = cart.getType();
final Minecart toCart;
if(type == EntityType.MINECART_CHEST) {
toCart = cart.getWorld().spawn(destination, StorageMinecart.class);
((StorageMinecart)toCart).getInventory().setContents(((StorageMinecart) cart).getInventory().getContents());
} else if(type == EntityType.MINECART_FURNACE) {
toCart = cart.getWorld().spawn(destination, PoweredMinecart.class);
} else if(type == EntityType.MINECART_HOPPER) {
toCart = cart.getWorld().spawn(destination, HopperMinecart.class);
((HopperMinecart)toCart).getInventory().setContents(((HopperMinecart) cart).getInventory().getContents());
} else if(type == EntityType.MINECART_MOB_SPAWNER) {
toCart = cart.getWorld().spawn(destination, SpawnerMinecart.class);
} else if(type == EntityType.MINECART_TNT)
toCart = cart.getWorld().spawn(destination, ExplosiveMinecart.class);
else if(type == EntityType.MINECART_COMMAND) {
toCart = cart.getWorld().spawn(destination, CommandMinecart.class);
((CommandMinecart)toCart).setCommand(((CommandMinecart)toCart).getCommand());
((CommandMinecart)toCart).setName(((CommandMinecart)toCart).getName());
} else
toCart = cart.getWorld().spawn(destination, RideableMinecart.class);
final Entity passenger = cart.getPassenger();
if (passenger != null) {
cart.eject();
passenger.teleport(destination);
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), new Runnable() {
@Override
public void run() {
toCart.setPassenger(passenger);
passenger.setVelocity(cart.getVelocity());
}
});
}
toCart.getLocation().setYaw(cart.getLocation().getYaw());
toCart.getLocation().setPitch(cart.getLocation().getPitch());
toCart.setVelocity(cart.getVelocity()); // speedy thing goes in, speedy thing comes out
cart.remove();
}