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 26ba80a commit 9daf8cc
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

1 comment on commit 9daf8cc

@Morphan1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the random spam of commits x~x I had some problems getting updates from the master branch. But it should all be good now.

Please sign in to comment.