Skip to content

Commit

Permalink
Allow <l@location.find.entities[creeper|zombie|player].within[x]>
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Dec 9, 2013
1 parent 26a8bad commit 54a4408
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -739,20 +739,40 @@ public int compare(dNPC npc1, dNPC npc2) {
}

// <--[tag]
// @attribute <l@location.find.entities.within[X]>
// @attribute <l@location.find.entities[<entity>|...].within[X]>
// @returns dList
// @description
// Returns a list of entities within a radius.
// Returns a list of entities within a radius, with an optional search parameter
// for the entity type.
// -->
else if (attribute.startsWith("entities")
&& attribute.getAttribute(2).startsWith("within")
&& attribute.hasContext(2)) {
dList ent_list = new dList();
if (attribute.hasContext(1)) {
for (String ent : attribute.getContext(1).split("\\|")) {
if (dEntity.matches(ent))
ent_list.add(ent.toUpperCase());
}
}
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 (Utilities.checkLocation(this, entity.getLocation(), radius))
found.add(new dEntity(entity));
for (Entity entity : getWorld().getEntities()) {
if (Utilities.checkLocation(this, entity.getLocation(), radius)) {
dEntity current = new dEntity(entity);
if (!ent_list.isEmpty()) {
for (String ent : ent_list) {
if (entity.getType().name().equals(ent) || current.identify().equalsIgnoreCase(ent)) {
found.add(current);
break;
}
}
}
else
found.add(current);
}
}

Collections.sort(found, new Comparator<dEntity>() {
@Override
Expand Down

0 comments on commit 54a4408

Please sign in to comment.