From 7520a903ab9af2457e5cd27aa09ec66327b29d31 Mon Sep 17 00:00:00 2001 From: MorphanOne Date: Wed, 14 Aug 2013 20:55:42 -0400 Subject: [PATCH] Add ]> --- .../aufdemrand/denizen/objects/dLocation.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java index 13176ad463..c13c8e79b3 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java @@ -500,6 +500,30 @@ public int compare(dPlayer pl1, dPlayer pl2) { return new dList(found).getAttribute(attribute); } + + // <-- + // -> dList + // Returns a dList of NPCs within a radius. + // --> + else if (attribute.startsWith("npcs") + && attribute.getAttribute(2).startsWith("within") + && attribute.hasContext(2)) { + ArrayList found = new ArrayList(); + 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() { + @Override + public int compare(dNPC npc1, dNPC npc2) { + return (int) (distanceSquared(npc1.getLocation()) - distanceSquared(npc2.getLocation())); + } + }); + + return new dList(found).getAttribute(attribute); + } // <-- // -> dList