Solved How to get players nearby from a location?

Discussion in 'Plugin Development' started by TheWolfBadger, Jun 15, 2014.

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

    TheWolfBadger

    Hey Bukkit Community! I was just wondering how I would get players nearby to a certain block using the Bukkit api. Does anyone have any clue how to do this? I'm looking for like a getNearbyEntities method, but for blocks. Thanks. - Jack
     
  2. Offline

    Niknea

    TheWolfBadger get the blocks location. Save it as a variable. Then do something like variablename.getNearbyEntities().
     
  3. Offline

    TheWolfBadger

    Niknea Did you not understand what I asked?
     
  4. Offline

    TheEntropy

    TheWolfBadger likes this.
  5. Offline

    TheWolfBadger

  6. Offline

    Garris0n

    TheEntropy likes this.
  7. Offline

    TheWolfBadger

  8. Offline

    Garris0n

    I mean...exactly what I said. What part wasn't clear?
     
  9. Offline

    TheWolfBadger

    Garris0n I want to make sure they aren't within about 10-15 blocks of the location. Would I use distanceSquared or just the distance?
     
  10. Offline

    Garris0n

    It doesn't matter, the comparison will work.

    If I need to check if 2 is greater than 3:
    2 > 3 returns false.
    OR
    2^2=4
    3^3 = 9
    4 > 9 also returns false.

    However, you should use distanceSquared() because it works a bit backwards. The .distance() method has to use a square root operation to get the final product, while distanceSquared() just does part of the calculation (google the distance formula, you probably learned it in Algebra if you've taken it). In computers, using the square root operation is pretty "expensive" to do, as in it slows the computer down more. So, if you're in a situation where either works (such as comparing two distances), you should always use distanceSquared(), simply because it's a cheaper operation and will technically slow down the server less to accomplish.
     
    TheWolfBadger likes this.
  11. Offline

    NathanWolf

    I've got a PR out for a getEntities using an arbitrary location and radius.

    Until a feature like that is accepted, you need to have an entity to center the query around, use NMS, or get a list of all players and iterate through that, as has been suggested.
     
Thread Status:
Not open for further replies.

Share This Page