Teleporting players on horses not working!

Discussion in 'Bukkit Help' started by MrTurtle2005, Jan 10, 2018.

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

    MrTurtle2005

    I made a custom server with a few of my friends. And on it I want helicopters so I started by making a horse with the name heli, invisibility and no gravity then I did this code inside a player interact event:
    Code:
    if(player.getInventory().getItemInMainHand().getType() == Material.LEVER && player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase("Joystick"))
            {
                for(Entity e : player.getNearbyEntities(10, 10, 10))
                {
                    if(e.getCustomName().equalsIgnoreCase("heli") && e.getType() == EntityType.HORSE)
                    {
                        e.eject();
                        e.teleport(e.getLocation().add(0.0, 0.25, 0.0));
                        e.addPassenger(player);
                    }
                }
            }
    And it it should check if the player is holding a lever named "Joystick" and get all the horses nearby, That works but when I teleport it it doesn't work.
    Any help would be great!
     
  2. Offline

    Zombie_Striker

    @MrTurtle2005
    Currently, this does not check if the player was teleported. Add a check to see if the player teleported away from the helecopter. If so, teleport the heli to the player.
     
  3. Offline

    MrTurtle2005

    What do you mean?
     
  4. Offline

    Zombie_Striker

    @MrTurtle2005
    When your plugin/a plugin tries to teleport the player, make sure the player has been ejected from the heli. Then, listen to PlayerTeleportEvent. If the player teleported more than 10 blocks away, then find a helicopter where the player was originally and teleport it to the new location.
     
  5. Offline

    MrTurtle2005

    @Zombie_Striker
    I changed the code a bit but its still not working.
    Code:
    if(player.getInventory().getItemInMainHand().getType() == Material.LEVER && player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase("Joystick"))
            {
                for(Entity e : player.getNearbyEntities(10, 10, 10))
                {
                    if(e.getCustomName().equalsIgnoreCase("heli") && e.getType() == EntityType.HORSE)
                    {
                        e.eject();
                        player.teleport(player.getLocation().add(0.0, 0.25, 0.0));
                        e.teleport(player);
                        e.addPassenger(player);
                    }
                }
            }
     
  6. Offline

    Zombie_Striker

    @MrTurtle2005
    Well, you're still only checking if there is a helicopter close to the player's current position. This is why you need to listen to PlayerTeleportEvent as well.
     
  7. Offline

    ForbiddenSoul

    your teleporting the helicopter 0.25 units up from itself not 0.25 units up from the player
    e.teleport(player.getLocation().add(0.0, 0.25, 0.0));
     
  8. Offline

    MrTurtle2005

    Ok that works! (Sorry for the late reply) But how would I make that go down?
    I tried e.teleport(player.getLocation().subtract(0.0,0.25,0.0) but it doesn’t work any ideas?
     
Thread Status:
Not open for further replies.

Share This Page