Nearby Entities

Discussion in 'Plugin Development' started by Ghilliedrone, Jul 29, 2013.

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


    When i use this if statement, it doesn't detect nearby players
    1. if(entity.getNearbyEntities(5, 4, 5).contains(EntityType.PLAYER))

    Anyone know a fix?
  2. Offline


    You can't use the contains() method in that way. Some of the entities in the list may be of type Player, but none of them are actually equal to the type itself.
  3. Offline


    Ghilliedrone I've never used this function before, but from the name of it, I'm guessing it returns a list of entities. If so, you have to iterate over the list and for each data type in the list check whether its an instanceof Player.
  4. Offline


    1. boolean playerInArea = false;
    2. for(Iterator<Entity> iterator = event.getPlayer().getNearbyEntities(5, 4, 5).iterator(); iterator.hasNext();)
    3. {
    4. Entity entity =;
    5. if(entity instanceof Player)
    6. playerInArea = true;
    7. }
  5. Offline


    The above does pretty much the same as this, but here's an alternative:
    2. boolean inRadius = false;
    3. for (Entity e : entity.getNearbyEntities(5, 4, 5)) {
    4. if (e.getType().equals(EntityType.PLAYER) && e instanceof Player) {
    5. // Bingo, we have ourselves a player
    6. inRadius = true;
    7. }
    8. }
    9. return inRadius;
  6. Offline


    Is it possible to add firework as the objects where the radius has to be checked and then if there's a player in that radius deal damage?
    tip: Firework is not a projectile
Thread Status:
Not open for further replies.

Share This Page