Skip to content

Commit

Permalink
Allow adding dObjects to the ObjectFetcher without reloading all obje…
Browse files Browse the repository at this point in the history
…cts, implement new Notable method
  • Loading branch information
Morphan1 committed Sep 3, 2013
1 parent c0d5792 commit 8dcab1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Expand Up @@ -315,15 +315,14 @@ public boolean isUnique() {

@Override
@Note("cuboid")
public String getSaveString() {
public String getSaveObject() {
return loc_1.getBlockX() + "," + loc_1.getBlockY()
+ "," + loc_1.getBlockZ() + "," + loc_1.getWorld().getName()
+ "|"
+ loc_2.getBlockX() + "," + loc_2.getBlockY()
+ "," + loc_2.getBlockZ() + "," + loc_2.getWorld().getName();
}


@Override
public void makeUnique(String id) {
NotableManager.saveAs(this, id);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Expand Up @@ -23,6 +23,7 @@

import net.aufdemrand.denizen.objects.notable.Notable;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.objects.notable.Note;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.core.InventoryScriptContainer;
import net.aufdemrand.denizen.tags.Attribute;
Expand All @@ -36,7 +37,7 @@ public class dInventory implements dObject, Notable {
/////////////////

final static Pattern inventory_by_type = Pattern.compile("(in@)(npc|player|entity|location|equipment)(\\[)(.+?)(\\])", Pattern.CASE_INSENSITIVE);
final static Pattern inventory_by_script = Pattern.compile("(in@)(.+)");
final static Pattern inventory_by_script = Pattern.compile("(in@)(.+)", Pattern.CASE_INSENSITIVE);

/////////////////////
// NOTABLE METHODS
Expand All @@ -46,7 +47,8 @@ public boolean isUnique() {
return holderType.equals("notable");
}

public String getSaveString() {
@Note("inventory")
public String getSaveObject() {
return holderIdentifier;
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/net/aufdemrand/denizen/tags/ObjectFetcher.java
Expand Up @@ -17,17 +17,21 @@ public class ObjectFetcher {
private static Map<String, Class> objects = new HashMap<String, Class>();

public static void _initialize() throws IOException, ClassNotFoundException {
objects.clear();

if (fetchable_objects.isEmpty())
return;

Map<String, Class> adding = new HashMap<String, Class>();
for (Class dClass : fetchable_objects)
for (Method method : dClass.getMethods())
if (method.isAnnotationPresent(net.aufdemrand.denizen.objects.ObjectFetcher.class)) {
String[] identifiers = method.getAnnotation(net.aufdemrand.denizen.objects.ObjectFetcher.class).value().split(",");
for (String identifer : identifiers)
objects.put(identifer.trim().toLowerCase(), dClass);
adding.put(identifer.trim().toLowerCase(), dClass);
}

dB.echoApproval("Loaded the Object Fetcher! Valid object types: " + objects.keySet().toString());
objects.putAll(adding);
dB.echoApproval("Added objects to the ObjectFetcher " + adding.keySet().toString());
fetchable_objects.clear();
}

private static ArrayList<Class> fetchable_objects = new ArrayList<Class>();
Expand Down

0 comments on commit 8dcab1a

Please sign in to comment.