Teleport player to surface

Discussion in 'Plugin Development' started by MOMOTHEREAL, Nov 6, 2013.

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

    MOMOTHEREAL

    Hello,
    I am just wondering if there is a way to teleport players to the surface.
    More precisely, I don't want the player to be teleported to Y=64 always because if he is in a mountain he will suffocate :p
    Momo.
     
  2. Offline

    Deleted user

    MOMOTHEREAL
    Use a loop....start really high up (150-300) and go down and check if the block is air
    Then omce it isnt...teleport him there
     
    The Gaming Grunts likes this.
  3. Offline

    justcool393

    I thought there was a Block.getHighestYAt, or something like that.
     
  4. Offline

    Deleted user

    justcool393
    Will get the highest highest block...even if air I believe
     
  5. Offline

    Noxyro

    Code:java
    1. Player player;
    2. int height = 0;
    3. int maxHeight = player.getWorld().getMaxHeight();
    4. Block block;
    5.  
    6. while (height <= maxHeight) {
    7. height++;
    8. block = player.getLocation().add(0, height, 0).getBlock();
    9. if (block.isEmpty()) {
    10. block = player.getEyeLocation().add(0, height, 0).getBlock();
    11. if (block.isEmpty()) {
    12. player.teleport(player.getLocation().add(0, height, 0));
    13. break;
    14. }
    15. }
    16. }



    Not the shortest solution but it should work.
     
  6. Offline

    _Filip

    The nms function getHighestBlockYAt will do this.
     
    justcool393 likes this.
Thread Status:
Not open for further replies.

Share This Page