Checking if there are players close to another player

Discussion in 'Plugin Development' started by Alex5657, Jul 7, 2012.

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

    Alex5657

    Hey, i need help with a plugin i am makeing.
    What i need help with is makeing the plugin to see if there are any players within a 3x3 square around the other player after a certain event and get their names if there are. Thanks in advance =)
     
  2. Offline

    McLuke500

    I think it's player.getNearbyEntitys() but I may be wrong.
     
  3. Offline

    DocRedstone

    Something like this should work

    Code:
    public void areTheyClose(Player primary) {
    Location loc = primary.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    int z = loc.getZ();
    for (Player p: player.getNearbyEntitys()) {
    if (p.getLocation().getX() > x && p.getLocation().getX() + 3) {
    //Player is in x bounds.
    }
    }
     
  4. Offline

    coldandtired

    That will cause an invalid cast error.

    for (Entity e : p.getNearbyEntities(1.5, 0, 1.5)) // change 0 to a number to account for players at different heights. Not sure if it will allow the 1.5's
    {
    String s = e instanceof Player ? ((Player)e).getName(); : null;
    if (s != null)...
    }
     
  5. Offline

    Jogy34

    You would want to just do player.getNearbyEntities(3, 3, 3) which return a list of entities then just loop through it to find the players
     
  6. Offline

    coldandtired

    That would be a box 6x6x6.
     
  7. Offline

    Jogy34

    O ya then it would be (1,1,1) because that method goes that many blocks out from the entity you call it from thus creating a 3x3x3 cube.
     
Thread Status:
Not open for further replies.

Share This Page