player can only use a command at a specific area

Discussion in 'Plugin Development' started by blazee15, Oct 24, 2012.

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

    blazee15

    Been a while I was trying to figure this out.

    In some games and languages for example you can detect if a player is near a specific area for example

    Code:
    If(IsPlayerInRangeOfPoint(playerid, then the cords will go here))
    
    So i was wondering of there is anyway of doing this in java bukkit

    Basically i just want to let a player access for example cmd /test near for example coordinates -1, -1 -1 and if he isnt near then he will get a null message and wont be able to access the command
     
  2. Offline

    md_5

    You would have to do if (x < target.xmax && x > target.xmin && y < target.xmax && y > target.xmin etc etc etc)
     
  3. Offline

    blazee15

    Mind giving me a example of it with any cmd and coordinates please? That will help a lot, i learn more by looking then reading/listening, im more of a visual person lol
     
  4. Offline

    md_5

    Code:java
    1.  
    2. /**
    3.   * Checks if a point is within the bounds of 2 other points.
    4.   */
    5. private boolean isIn(Location point, Location corner1, Location corner2) {
    6. Location min = getMin(corner1, corner2);
    7. Location max = getMax(corner1, corner2);
    8. return point.getWorld() == min.getWorld()
    9. && point.getX() > min.getX() && point.getX() < max.getX()
    10. && point.getY() > min.getY() && point.getY() < max.getY()
    11. && point.getZ() > min.getZ() && point.getZ() < max.getZ();
    12. }
    13.  
    14. /**
    15.   * Gets the min points of a location.
    16.   */
    17. private Location getMin(Location l1, Location l2) {
    18. if (l1.getWorld() != l2.getWorld()) {
    19. }
    20. return new Location(l1.getWorld(), Math.min(l1.getX(), l1.getX()), Math.min(l1.getY(), l1.getZ()), Math.min(l1.getZ(), l1.getY()));
    21. }
    22.  
    23. /**
    24.   * Gets the max points of a location.
    25.   */
    26. private Location getMax(Location l1, Location l2) {
    27. if (l1.getWorld() != l2.getWorld()) {
    28. }
    29. return new Location(l1.getWorld(), Math.max(l1.getX(), l1.getX()), Math.max(l1.getY(), l1.getZ()), Math.max(l1.getZ(), l1.getY()));
    30. }


    So in that case you would use isIn() with the players location and the location of the 2 points.
     
    blazee15 likes this.
  5. Offline

    blazee15

    How will I set to the point? For example one point is coordinates 1, 1, 1 and the other point is 3,3,3? This is kinda confusing to be honest lol
     
  6. Offline

    md_5

    new Location(player.getLocation().getWorld),1,1,1);
    For example.
     
  7. Offline

    blazee15

    That ik but where will i place it for example in your code, since I dont see any specific variable to set the two points
     
  8. Offline

    md_5

    The points are those passed to the method. I suggest you come back when you know a little bit more about Java programming, I have given you *all* the code.
     
Thread Status:
Not open for further replies.

Share This Page