Solved [HELP] Problems with checking player's location

Discussion in 'Spigot Plugin Development' started by LinhDoraemon, Feb 19, 2020.

  1. Hi guys, I'm making a Clan plugin. I want clans can claim a land, with the center is the chunk's center then widen in given radius. But I cant find any ideas for checking if player is in that land ( Picture )
    Do you have any suggestions for this problem ? Thank you !
    P/s : Sorry, I'm not so good at English !
    [​IMG]
     
  2. To recognise where a player is at and what area they enter you can listen to the PlayerMoveEvent and check their location. This is very resource heavy though.
     
    • Agree Agree x 1
  3. You must write analog for getNearbyEntities via using simple math
     
    • Agree Agree x 1
  4. FrostedSnowman

    Resource Staff

    You haven't specified whether or not the radius is in blocks or chunks, or similar.

    If you plan to base it off an origin point with a set radius, you can just check the distance between the player's location and the center's origin. If the distance is within the radius, they are in the area.

    Some pseudo-code:

    Code (Java):
    private static final double RADIUS = 3.5;
    private final Location origin;

    public boolean inBounds(Location location) {
         return this.origin.distanceSquared(location) <= RADIUS * RADIUS;
    }
     
    • Like Like x 1
  5. Thanks for all of your suggestions ! My problem has been solved !