Restricting Areas

Discussion in 'Plugin Development' started by legostarwarszach, Jul 1, 2013.

Thread Status:
Not open for further replies.
  1. For some reason this code makes a player not able to move and keeps spazing out the no permission message. My code:
    http://pastebin.com/LH3frF8e

    Thanks in advance
     
  2. Offline

    MCForger

    legostarwarszach
    Create a bounding box using this class:
    Code:java
    1. import org.bukkit.Location;
    2. import org.bukkit.World;
    3.  
    4. public class BoundingBox
    5. {
    6. protected Location lower;
    7. protected Location upper;
    8.  
    9. public BoundingBox() {}
    10.  
    11. public BoundingBox(Location l, Location l2)
    12. {
    13. createBoundingBox(l, l2);
    14. }
    15.  
    16. public void createBoundingBox(Location l1, Location l2)
    17. {
    18. // System.out.println("createBoundingBox ");
    19. lower = new Location(l1.getWorld(), Math.min(l1.getBlockX(),
    20. l2.getBlockX()), Math.min(l1.getBlockY(), l2.getBlockY()),
    21. Math.min(l1.getBlockZ(), l2.getBlockZ()));
    22. upper = new Location(l1.getWorld(), Math.max(l1.getBlockX(),
    23. l2.getBlockX()), Math.max(l1.getBlockY(), l2.getBlockY()),
    24. Math.max(l1.getBlockZ(), l2.getBlockZ()));
    25. }
    26.  
    27. public boolean contains(Location l)
    28. {
    29. return (l.getWorld().getName().equals(lower.getWorld().getName())
    30. && (l.getBlockX() >= lower.getBlockX() && l.getBlockX() <= upper
    31. .getBlockX())
    32. && (l.getBlockY() >= lower.getBlockY() && l.getBlockY() <= upper
    33. .getBlockY()) && (l.getBlockZ() >= lower.getBlockZ() && l
    34. .getBlockZ() <= upper.getBlockZ()));
    35. }
    36.  
    37. public Location getCorner1(){return lower;}
    38. public Location getCorner2(){return upper;}
    39.  
    40. public Location getLowerCorner(){return lower;}
    41. public Location getUpperCorner(){return upper;}
    42.  
    43. public World getWorld(){ return lower.getWorld();}
    44. }

    Then do a check like if (box.contains(player.getLocation()) { // THERE FINE} else { //OUTSIDE OF BOX }
     
  3. MCForger
    Thx, I'll try it

    MCForger
    How would I make the box at a certian cords?
    And box isn't found in the class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  4. Offline

    MCForger

    legostarwarszach
    Make a box by doing
    Code:java
    1. BoundingBox box = new BoundingBox(corner1, corner2);
    2.  

    Then make it a global variable so in your listen do:
    Code:java
    1. if (box.contains(player.getLocation())
    2. {
    3. // Their inside the area still.
    4. }
    5. else
    6. {
    7. // Their outside of the area.
    8. }
     
  5. MCForger
    The method contains(Location) is undefined fir the type BoundingBox
     
Thread Status:
Not open for further replies.

Share This Page