Testing for a Player in a certain area

Discussion in 'Plugin Development' started by Valdemart, Aug 17, 2014.

Thread Status:
Not open for further replies.
  1. I need help with testing a player in a certain area (coordinates).
    That's pretty much all.
    Thanks!
     
  2. Offline

    St3venAU

    something like this would work. The min and max values are just an example - in this case it would check if the player is inside a 100x100x100 cube centered on 0,64,0.

    Code:java
    1. double minX = -50.0;
    2. double maxX = 50.0;
    3. double minY = 14.0;
    4. double maxY = 114.0;
    5. double minZ = -50.0;
    6. double maxZ = 50.0;
    7.  
    8. double x = player.getLocation().getX();
    9. double y = player.getLocation().getY();
    10. double z = player.getLocation().getZ();
    11.  
    12. if(x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ) {
    13. // player is within the coordinates
    14. }
     
  3. Offline

    EnderTroll68

    St3venAU
    That would only work if the worlds are the same. You need to add a world check
     
  4. Offline

    St3venAU

Thread Status:
Not open for further replies.

Share This Page