[Need Help]LivingEntitys within radius of a targetedblock

Discussion in 'Plugin Development' started by thecrystalflame, May 13, 2013.

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


    hey guys, i have been developing a class plugin recently. all classes have unique ability's of a wide range from Leap to Lightning Storm.
    the Lightning Storm ability gets the block the player has targeted and checks if there are any players within a certain radius. It then strikes them with lightning.

        for (final Player onlineplayer : main.getServer().getOnlinePlayers()) {
            if(block.getLocation().distance(onlineplayer.getLocation()) <= 5) {
    this works very nicely. no problems.

    however I do not know how to replicate this with mobs.
    any help appreciated
  2. Offline


    Loop through all entities in the world and check the distance between them and the location.

    2. World w;
    3. Location hit;
    4. for(LivingEntity e : w.getLivingEntities){
    5. if(e.getLocation().distance(hit) <= 3){
    6. //within 3 blocks
    7. }
    8. }[syntax][/syntax]
  3. Offline


    thanks heaps, works a charm
Thread Status:
Not open for further replies.

Share This Page