Solved (Location).getNearbyEntities

Discussion in 'Plugin Development' started by Stab, Jun 20, 2014.

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

    Stab

    Hello there.
    I've been trying to figure out how do I can make a Location as a point for getNearbyEntities.
    Code:java
    1. List<Entity> nearbyEntities = player1.getNearbyEntities(15, 5, 15);
    2. for (Entity entity : nearbyEntities) {
    3. entity.remove();
    4. }

    It works if I tell for the code who's the player1, but I would like to use always a same location instead. Is that possible. If so. How to?

    I'm also interested to trigger this function "all the time" so what could be the correct event for this one like that the server doesn't crash/overload due the spam event.

    Thanks for the help already. I'm new with Java and Plugins.
     
  2. Offline

    viper_monster

    Stab smthing like this maybe?
    Code:java
    1. double radius = 15;
    2. for (LivingEntity entity : player.getWorld().getLivingEntities()) {
    3. if (player.getLocation().distanceSquared(entity.getLocation()) <= radius * radius) {
    4. entity.remove();
    5. }
    6. }
     
  3. Offline

    Stab

    I'm not 100% sure, but I mean, can I set some coordinate there? I mean that I want to replace the player with a some coordinate only without requiring any blocks or players that it checks if they're near that coordinate it removes them.
     
  4. Offline

    viper_monster

    Stab
    Code:java
    1. public void removeLivingEntities(World world, Location center, double radius) {
    2. for (LivingEntity entity : world.getLivingEntities()) {
    3. if (center.distanceSquared(entity.getLocation()) <= radius * radius) {
    4. entity.remove();
    5. }
    6. }
    7. }
     
    Stab likes this.
  5. Offline

    Stab

    viper_monster I guess it is this. I will try it later! :)
    Thank you :)
     
Thread Status:
Not open for further replies.

Share This Page