Solved Getting if a player is inside a location.

Discussion in 'Plugin Development' started by TopTobster5, May 26, 2014.

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

    TopTobster5

    Hi.

    I have written this method to find our if a player is inside an arena I have created. Here is the method:
    Code:
    public boolean isInside(Location loc) {
           
            Location loch = loc1;
            Location locl = loc2;
           
            if (loc1.getX() >= loc2.getX()) {
                loch.setX(loc1.getX());
                locl.setX(loc2.getX());
            } else {
                loch.setX(loc2.getX());
                locl.setX(loc1.getX());
            }
           
            if (loc1.getY() >= loc2.getY()) {
                loch.setY(loc1.getY());
                locl.setY(loc2.getY());
            } else {
                loch.setY(loc2.getY());
                locl.setY(loc1.getY());
            }
           
            if (loc1.getZ() >= loc2.getZ()) {
                loch.setZ(loc1.getZ());
                locl.setZ(loc2.getZ());
            } else {
                loch.setZ(loc2.getZ());
                locl.setZ(loc1.getZ());
            }
           
            if (loc.getX() > loch.getX()) {
                return false;
            } else if (loc.getY() > loch.getY()) {
                return false;
            } else if (loc.getZ() > loch.getZ()) {
                return false;
            } else if (loc.getX() < locl.getX()) {
                return false;
            } else if (loc.getY() < locl.getY()) {
                return false;
            } else if (loc.getZ() < locl.getZ()) {
                return false;
            } else {
                return true;
            }
           
        }
    loc1 is one of the corners and loc2 is the other. loc is the players location which is given when the method is called. loch is supposed to be the highest location (highest x, y, and z) while locl is supposed to be the lowest. However, it does not work. The only way I can get it to work, is if loc1 is the highest point, while loc2 is the lowest already. Any ideas?
     
  2. This is just simple intersection logic.
    Google "rectangle inside point algorithm".
    I think you can use Javas own Rect.contains() method.
     
  3. Offline

    TopTobster5

Thread Status:
Not open for further replies.

Share This Page