Defining Player area with two points.

Discussion in 'Plugin Development' started by Samkio, Feb 7, 2011.

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

    Samkio

    Hey,
    I need a way to detect when a player places a block in a certain area.
    At the moment players can define 2 points and it writes this to a file.

    NameOfArea = x1,y1,z1,x2,y2,z2

    That all works fine.
    Thing is i just can't figure out how to detect where the block placed is in that area.
    What i mean is that the block is placed.
    A method then gets the location of this block and compares it to every area.
    This is what i cannot figure out. I have tried listing all the areas and then checking each one but it dosn't want to work.

    My head hurts :(
    Can anyone help me :)
     
  2. Offline

    Crash

    I'm not exactly sure what you mean.. do you mean is it inside the box defined by those two points ?
    I'm actually working on something right now where I needed that. I can give you my method if you want.
     
  3. Offline

    Samkio

    Yes to see if the block is inside the box define by those points.
    If you could that will be great :)
     
  4. Offline

    Crash

    Zone is a class that I made that has two bounding Locations just replace z.getBound... with your two bounds.
    The boolean _Dirs are defined :

    Code:
    xDir = bound1.getBlockX() < bound2.getBlockX();
    yDir = bound1.getBlockY() < bound2.getBlockY();
    zDir = bound1.getBlockZ() < bound2.getBlockZ();
    
    Code:
    public boolean isLocationInZone(Zone z, Location loc){
    
            int locX = loc.getBlockX(), locY = loc.getBlockY(), locZ = loc.getBlockZ();
            boolean insideX = (z.xDir ? locX >= z.getBound1().getBlockX() : locX <= z.getBound1().getBlockX());
            boolean insideY = (z.yDir ? locY >= z.getBound1().getBlockY() : locY <= z.getBound1().getBlockY());
            boolean insideZ = (z.zDir ? locZ >= z.getBound1().getBlockZ() : locZ <= z.getBound1().getBlockZ());
    
            if(insideX && insideY && insideZ){
    
                insideX = (z.xDir ? locX <= z.getBound2().getBlockX() : locX >= z.getBound2().getBlockX());
                insideY = (z.yDir ? locY <= z.getBound2().getBlockY() : locY >= z.getBound2().getBlockY());
                insideZ = (z.zDir ? locZ <= z.getBound2().getBlockZ() : locZ >= z.getBound2().getBlockZ());
    
                return insideX && insideY && insideZ;
    
            }
    
            return false;
    
        }
    Probably not the best way to do stuff but it works for me.
     
  5. Offline

    eisental

  6. Offline

    Samkio

    Ooh that could be useful. :)
    Thanks Crash + Eisental.
     
Thread Status:
Not open for further replies.

Share This Page