Skip to content

Commit

Permalink
Add <server.list_notables[<type>]>
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Dec 21, 2014
1 parent ce461ea commit 5c93393
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Expand Up @@ -228,4 +228,8 @@ public static String getClassId(Class notable) {
else
return null;
}

public static Map<String, Class> getReverseClassIdMap() {
return reverse_objects;
}
}
31 changes: 31 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java
Expand Up @@ -3,6 +3,8 @@
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.events.EventManager;
import net.aufdemrand.denizen.objects.notable.Notable;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.tags.ReplaceableTagEvent;
import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.npc.traits.AssignmentTrait;
Expand Down Expand Up @@ -194,6 +196,35 @@ public void serverTag(ReplaceableTagEvent event) {
: searchFlags.getAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.list_notables[<type>]>
// @returns dList(Notable)
// @description
// Lists all saved Notables currently on the server.
// Optionally, specify a type to search for.
// Valid types: locations, cuboids, ellipsoids, items, inventories
// -->
if (attribute.startsWith("list_notables")) {
dList allNotables = new dList();
if (attribute.hasContext(1)) {
String type = CoreUtilities.toLowerCase(attribute.getContext(1));
types: for (Map.Entry<String, Class> typeClass : NotableManager.getReverseClassIdMap().entrySet()) {
if (type.equals(CoreUtilities.toLowerCase(typeClass.getKey()))) {
for (Object notable : NotableManager.getAllType(typeClass.getValue())) {
allNotables.add(((dObject) notable).identify());
}
break types;
}
}
}
else {
for (Notable notable : NotableManager.notableObjects.values()) {
allNotables.add(((dObject) notable).identify());
}
}
event.setReplaced(allNotables.getAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.start_time>
// @returns Duration
Expand Down

0 comments on commit 5c93393

Please sign in to comment.