getNearbyEntities not getting players

Discussion in 'Plugin Development' started by nuclearmissile, Jan 4, 2014.

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

    nuclearmissile

    I have this code to get entities within 30 meters:

    Code:
    List<Entity> affected = player.getNearbyEntities(30, 30, 30);
                            for (Entity temp:affected){
                                if (temp instanceof LivingEntity){
                                    LivingEntity temp2 = (LivingEntity) temp;
                                    if(temp2.getHealth() > 6){
                                        temp2.setHealth(temp2.getHealth() - 6);
                                    }
                                    else temp2.setHealth(0);
                                }
                            }
    It works fine on animals, but for some reason it won't harm me in survival mode. Any ideas what's wrong? All help is greatly appreciated.
     
  2. Offline

    messageofdeath

    if(temp2.getHealth() > 6){
    temp2.setHealth(temp2.getHealth() - 6);
    }
    else temp2.setHealth(0);

    This is an unnecessary check just use
    temp2.setHealth(temp2.getHealth() - 6);
     
  3. Offline

    dillyg10


    Actually, you're wrong, he has the check so he doesn't get an IllegalArugmentException (with can be fixed with Math.max(0,temp2.getHealth()-6);

    Regardless... do this for me
    if (temp2 instanceof Player){
    Bukkit.broadcastMessage("Found player!");
    }

    See what happens... (getNearbyEntities will return nearby players, but this is just a failsafe).
     
Thread Status:
Not open for further replies.

Share This Page