Skip to content

Commit

Permalink
Add ObjectFetcher method _registerCoreObjects() to avoid unnecessaril…
Browse files Browse the repository at this point in the history
…y reloading objects
  • Loading branch information
Morphan1 committed Oct 26, 2013
1 parent 92b1a18 commit 8435c7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -248,9 +248,9 @@ public void onEnable() {
// Register CommandHandler with Citizens
Depends.citizens.registerCommandClass(CommandHandler.class);

// Initialize ObjectFetcher
// Register Core dObjects with the ObjectFetcher
try {
ObjectFetcher._initialize();
ObjectFetcher._registerCoreObjects();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/net/aufdemrand/denizen/objects/ObjectFetcher.java
Expand Up @@ -24,7 +24,26 @@ public class ObjectFetcher {
static Map<Class, Method> matches = new WeakHashMap<Class, Method>();
static Map<Class, Method> valueof = new WeakHashMap<Class, Method>();

public static void _initialize() throws IOException, ClassNotFoundException, NoSuchMethodException {
public static void _initialize() throws IOException, ClassNotFoundException {

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(Fetchable.class)) {
String[] identifiers = method.getAnnotation(Fetchable.class).value().split(",");
for (String identifer : identifiers)
adding.put(identifer.trim().toLowerCase(), dClass);
}

objects.putAll(adding);
dB.echoApproval("Added objects to the ObjectFetcher " + adding.keySet().toString());
fetchable_objects.clear();
}

public static void _registerCoreObjects() throws NoSuchMethodException, ClassNotFoundException, IOException {

// Initialize the ObjectFetcher
registerWithObjectFetcher(dItem.class); // i@
Expand All @@ -42,22 +61,9 @@ public static void _initialize() throws IOException, ClassNotFoundException, NoS
registerWithObjectFetcher(Element.class); // el@
registerWithObjectFetcher(Duration.class); // d@
registerWithObjectFetcher(dChunk.class); // ch@

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(Fetchable.class)) {
String[] identifiers = method.getAnnotation(Fetchable.class).value().split(",");
for (String identifer : identifiers)
adding.put(identifer.trim().toLowerCase(), dClass);
}

objects.putAll(adding);
dB.echoApproval("Added objects to the ObjectFetcher " + adding.keySet().toString());
fetchable_objects.clear();

_initialize();

}

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

0 comments on commit 8435c7b

Please sign in to comment.