Solved Any way to make sure player is not teleported into water?

Discussion in 'Plugin Development' started by KarimAKL, Jun 20, 2018.

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

    KarimAKL

    I have this code:
    Code:Java
    1.  
    2. for (Player op : Bukkit.getOnlinePlayers()) {
    3. if (op.getName().equalsIgnoreCase(args[0])) {
    4. Random r = new Random();
    5. int x = r.nextInt(2500);
    6. int z = r.nextInt(2500);
    7. int y = op.getWorld().getHighestBlockYAt(x,z);
    8. Location oldloc = op.getLocation();
    9. Location loc = new Location(op.getWorld(),x,y+0.5,z);
    10. op.teleport(loc);
    11. sender.sendMessage(plugin.Color("&aYou teleported "+op.getName()+" to a random location."));
    12. op.sendMessage(plugin.Color("&bYou've been teleported to location "+loc.getBlockX()+" "+loc.getBlockY()+" "+loc.getBlockZ()+" from "+oldloc.getBlockX()+" "+oldloc.getBlockY()+" "+oldloc.getBlockZ()+"."));
    13. return true;
    14. } else {
    15. sender.sendMessage(plugin.Color("&cA player with the name "+args[0]+" was not found. :("));
    16. return true;
    17. }
    18. }
    19.  

    And it works but is there any way to check if the player is gonna be teleported into water and if the player is gonna be teleported into water is there any way to search for a new location?
     
  2. Online

    timtower Administrator Administrator Moderator

    @KarimAKL While loop will do the trick.
    And you can check the block which is the highest one.
    Make sure to also check for lava.
     
  3. Offline

    KarimAKL

    @timtower Thanks for the information, i'll try to look it up. :) And thanks for the reminder about lava. :p
    EDIT: Works perfectly! Thanks again. :)
     
    Last edited by a moderator: Jul 25, 2018
Thread Status:
Not open for further replies.

Share This Page