Skip to content

Commit

Permalink
Add <location.find.npcs.within[<#>]>
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Aug 15, 2013
1 parent 64eb3ff commit 7520a90
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -500,6 +500,30 @@ public int compare(dPlayer pl1, dPlayer pl2) {

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

// <--
// <l@location.find.npcs.within[X]> -> dList
// Returns a dList of NPCs within a radius.
// -->
else if (attribute.startsWith("npcs")
&& attribute.getAttribute(2).startsWith("within")
&& attribute.hasContext(2)) {
ArrayList<dNPC> found = new ArrayList<dNPC>();
int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10;
attribute.fulfill(2);
for (dNPC npc : DenizenAPI.getSpawnedNPCs())
if (Utilities.checkLocation(this, npc.getLocation(), radius))
found.add(npc);

Collections.sort(found, new Comparator<dNPC>() {
@Override
public int compare(dNPC npc1, dNPC npc2) {
return (int) (distanceSquared(npc1.getLocation()) - distanceSquared(npc2.getLocation()));
}
});

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

// <--
// <l@location.find.entities.within[X]> -> dList
Expand Down

0 comments on commit 7520a90

Please sign in to comment.