Making sure player coordinate isn't in ground

Discussion in 'Plugin Development' started by sample_text, Feb 26, 2017.

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

    sample_text

    So, I'm making a command which will teleport you to a random place within 0,0 and 5000, 5000. I've got the X and Z coordinates working, but whenever I run the command, the player is put in the ground or in the air. How can I find the Y coordinate directly above the ground for a certain x/z coordinate?

    Code:
    Player ttp = (Player) sender;
    Random r = new Random();
    Location loc = new Location(((Player) sender).getWorld(), r.nextInt(5000) + 1, ???, r.nextInt(5000)+1);
    ttp.teleport(loc);
    
     
  2. Offline

    mine-care

    This is what you are looking for.
    Also i hope you are checking if sender is a Player, and I also hope you realise that coordinates can also be negative ;)
     
  3. Offline

    Irantwomiles

    When picking the coordinates check if the block at that location is air or not. If not air loop through the Y value at that location and find a place where it is air, but make sure that its not just 1 block of air which could also suffocate you.
     
Thread Status:
Not open for further replies.

Share This Page