Cannot teleport occupied boat.

Discussion in 'Plugin Development' started by Symphonic, Jan 7, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Symphonic

    It works fine when the boat is unoccupied. Here is the code I am using:


    Code:
    boatLoc = boat.getLocation();
           
            boatLoc.setYaw(shipOwner.getLocation().getYaw());
            boatLoc.setY(100);
           
            boat.teleport(boatLoc);
     
  2. Offline

    KarimAKL

    @Symphonic I've never tried it but it sounds like this would work:
    Code:Java
    1.  
    2. Boat boat = ...; // Your boat
    3. List<Entity> passengers = boat.getPassengers();
    4.  
    5. for (Entity entity : passengers) boat.removePassenger(entity);
    6.  
    7. Location location = ...; // Your location
    8. boat.teleport(location);
    9.  
    10. for (Entity entity : passengers) boat.addPassenger(entity); // I'm not sure if this teleports the entities, otherwise you can do it manually
     
  3. Offline

    Symphonic

    oh see this is high IQ

    Edit: this does not work, and it does give some very seizure inducing teleportation behavior. :/
     
    Last edited: Jan 8, 2020
  4. Offline

    KarimAKL

    What happens?
     
  5. Offline

    Symphonic

    The boat does not teleport, it stays put and the player is teleported in and out of the boat very fast and screen gets all vibratey because of it
     
  6. Offline

    KarimAKL

    @Symphonic Try using a BukkitRunnable to delay the teleport, and addPassenger loop by 1 tick.
     
  7. Offline

    Niv-Mizzet

  8. Offline

    The_Spaceman

    this is some code I use:

    Code:java
    1.  
    2. private static void teleportPlayer(@Nullable Player player, Location l) {
    3. if (player == null) return;
    4.  
    5. ArrayList<LivingEntity> slaves = new ArrayList<>();
    6. for (Entity e : player.getWorld().getEntities()) {
    7. if (e instanceof LivingEntity) {
    8. LivingEntity livingEntity = (LivingEntity) e;
    9. if (livingEntity.isLeashed()) {
    10. if (livingEntity.getLeashHolder() instanceof Player) {
    11. if (livingEntity.getLeashHolder().getUniqueId().equals(player.getUniqueId())) {
    12. slaves.add(livingEntity);
    13. livingEntity.setLeashHolder(null);
    14. }
    15. }
    16. }
    17. }
    18. }
    19.  
    20. LivingEntity horse = null;
    21. TreeSpecies boatType = null;
    22. Entity sailor = null;
    23. if (player.getVehicle() instanceof LivingEntity) {
    24. horse = (LivingEntity) player.getVehicle();
    25. } else if (player.getVehicle() instanceof Boat) {
    26. Boat b = (Boat) player.getVehicle();
    27. boatType = b.getWoodType();
    28. if (b.getPassengers().size() > 1) {
    29. sailor = b.getPassengers().get(1);
    30. }
    31. b.remove();
    32. }
    33.  
    34. player.teleport(l);
    35.  
    36. try {
    37. if (horse != null) {
    38. horse.teleport(player);
    39. horse.addPassenger(player);
    40. } else if (boatType != null) {
    41. Boat b = player.getWorld().spawn(player.getLocation(), Boat.class);
    42. b.setWoodType(boatType);
    43. b.teleport(player);
    44. b.addPassenger(player);
    45. if (sailor != null) {
    46. sailor.teleport(player);
    47. b.addPassenger(sailor);
    48. }
    49. }
    50. } catch (Exception ex) {
    51. ex.printStackTrace();
    52. }
    53.  
    54. for (LivingEntity e : slaves) {
    55. try {
    56. e.teleport(player);
    57. e.setLeashHolder(player);
    58. } catch (Exception ex) {
    59. ex.printStackTrace();
    60. }
    61. }
    62. }
    63.  


    This is for horses/llamas/donkeys aswell, and for entities on a leash

    The LivingEntity horse is the horse/llama
    The TreeSpecies boatType is the boat you are in
    The Entity sailor is the passenger in the boat with you
    The ArrayList<LivingEntity> slaves are the entities on a leash

    In some cases the sailor would dissapear for the teleported player, but when he rejoins the server its back. For other players (who just watch the teleport) its all fine

    I hope this helps you in the right way
     
  9. Offline

    Symphonic

    The issue is i'm trying to do this very fast every tick and this isnt gonna do that very well
     
  10. Offline

    Symphonic

  11. Offline

    Niv-Mizzet

  12. Offline

    Symphonic

    Will this interfere with normal movement of the boat? e.g. if the player in the boat presses W when this is happening will the boat move? forward as well as the launchprojectile direction?
     
  13. Offline

    Niv-Mizzet

    @Symphonic likely not, basically what this is doing is "pushing it" in a certain direction.
    You could probably make it that way if you need.

    EDIT: I also just realized that the player can't move a boat forward in the air, but you could probably check for the oars moving.
     
    Last edited: Jan 14, 2020
Thread Status:
Not open for further replies.

Share This Page