Skip to content

Commit

Permalink
Add <l@location.find.living_entities.within[x]>
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Aug 8, 2013
1 parent 924a3b5 commit f5ca990
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.World;
import org.bukkit.block.Sign;
Expand Down Expand Up @@ -522,8 +523,33 @@ public int compare(dEntity ent1, dEntity ent2) {
});

return new dList(found).getAttribute(attribute);
}

}

// <--
// <l@location.find.living_entities.within[X]> -> dList
// Returns a dList of living entities within a radius.
// -->
else if (attribute.startsWith("living_entities")
&& attribute.getAttribute(2).startsWith("within")
&& attribute.hasContext(2)) {
ArrayList<dEntity> found = new ArrayList<dEntity>();
int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10;
attribute.fulfill(2);
for (Entity entity : getWorld().getEntities())
if (entity instanceof LivingEntity
&& Utilities.checkLocation(this, entity.getLocation(), radius))
found.add(new dEntity(entity));

Collections.sort(found, new Comparator<dEntity>() {
@Override
public int compare(dEntity ent1, dEntity ent2) {
return (int) (distanceSquared(ent1.getBukkitEntity().getLocation()) - distanceSquared(ent2.getBukkitEntity().getLocation()));
}
});

return new dList(found).getAttribute(attribute);
}

else return "null";
}

Expand Down

0 comments on commit f5ca990

Please sign in to comment.