Checking if a player is in an area

Discussion in 'Plugin Development' started by CarPet, Oct 21, 2012.

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

    CarPet

    Can someone please help me on how to check if a player is inside and area and if they are not they cannot execute a command, please paste your code :D

    Thanks a lot!
     
  2. Offline

    Deleted user

    onCommand
    if(player.getLocation() == location

    and

    onPlayerMove()
     
  3. Offline

    CarPet

    Wow, honestly, this does not help me at all :p Why would you use onPlayerMove?

    Edit: I was wanting to have a spawn area where they could walk around and if they are not within those coords then they cannot execute that command
     
  4. Offline

    Deathmarine

    Check their location when the command is executed.
     
  5. Offline

    KeybordPiano459

    Just use WorldGuard
     
  6. Offline

    gomeow

    Worldguard does exactly that
     
  7. Offline

    CarPet

    I am not wanting to use an alternate plugin...
     
  8. Offline

    gomeow

    then try hooking into world guard
     
  9. Offline

    Remi1115

    Do you mean something like this?

    Code:java
    1.  
    2. public boolean inArea(Location location1, Location location2, Location playerLocation){
    3. if(playerLocation.getBlockX() >= location1.getBlockX() && playerLocation.getBlockX() <= location2.getBlockX()){
    4. if(playerLocation.getBlockZ() >= location1.getBlockZ() && playerLocation.getBlockZ() <= location2.getBlockZ()){
    5. return true;
    6. }
    7. }
    8. return false;
    9. }
    10.  

    Edit: Found out how to correctly post Java code (using the syntax BBCode tag).
    Edit two, three and all after that probably: Trying out with the different syntaxes.
     
  10. Offline

    the_merciless

    Wont work if you are standing in a negative coordinate
     
  11. Offline

    Remi1115

    Ahh, thanks. I didn't think about that.
    This might work, it did when I tested it.
    Code:java
    1.  
    2. public boolean inArea(Location location1, Location location2, Location playerLocation){
    3. if((playerLocation.getBlockX() >= location1.getBlockX() && playerLocation.getBlockX() <= location2.getBlockX()) || (playerLocation.getBlockX() <= location1.getBlockX() && playerLocation.getBlockX() >= location2.getBlockX())){
    4. if((playerLocation.getBlockZ() >= location1.getBlockZ() && playerLocation.getBlockZ() <= location2.getBlockZ()) || (playerLocation.getBlockZ() <= location1.getBlockZ() && playerLocation.getBlockZ() >= location2.getBlockZ())){
    5. return true;
    6. }
    7. }
    8. return false;
    9. }
    10.  
     
  12. I will make something for you when I get home in a few hours. Adding config files for multiple areas and stuff.

    I am almost done with it

    Here is my way of checking it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page