diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index e316132e7..b1a624642 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -4,7 +4,6 @@ import java.io.File; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.DataKey; -import net.citizensnpcs.api.Factory; import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.trait.Character; @@ -92,12 +91,7 @@ public class Citizens extends JavaPlugin { // TODO possibly separate this out some more private void setupNPCs() throws NPCLoadException { - traitManager.registerTraitFactory("location", new Factory() { - @Override - public SpawnLocation create() { - return new SpawnLocation(); - } - }); + traitManager.registerTrait("location", SpawnLocation.class); int spawned = 0; for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) { int id = Integer.parseInt(key.name()); diff --git a/src/net/citizensnpcs/npc/CitizensNPC.java b/src/net/citizensnpcs/npc/CitizensNPC.java index 6ef3f31b1..e9e33bf47 100644 --- a/src/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/net/citizensnpcs/npc/CitizensNPC.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.Map; import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.Factory; import net.citizensnpcs.api.event.NPCDespawnEvent; import net.citizensnpcs.api.event.NPCSpawnEvent; import net.citizensnpcs.api.npc.NPC; @@ -177,24 +176,4 @@ public class CitizensNPC implements NPC { public CraftNPC getHandle() { return mcEntity; } - - public static class ReflectionTraitFactory implements Factory { - private final Class clazz; - - public ReflectionTraitFactory(Class clazz) { - this.clazz = clazz; - } - - @Override - public Trait create() { - try { - return clazz.newInstance(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return null; - } - } } \ No newline at end of file diff --git a/src/net/citizensnpcs/npc/trait/CitizensTraitManager.java b/src/net/citizensnpcs/npc/trait/CitizensTraitManager.java index 25b2d9b4f..9abf202ac 100644 --- a/src/net/citizensnpcs/npc/trait/CitizensTraitManager.java +++ b/src/net/citizensnpcs/npc/trait/CitizensTraitManager.java @@ -20,9 +20,31 @@ public class CitizensTraitManager implements TraitManager { } @Override - public void registerTraitFactory(String name, Factory factory) { + public void registerTrait(String name, Class clazz) { + registerTraitWithFactory(name, new ReflectionFactory(clazz)); + } + + @Override + public void registerTraitWithFactory(String name, Factory factory) { if (registered.get(name) != null) throw new IllegalArgumentException("trait factory already registered"); registered.put(name, factory); } + + private static class ReflectionFactory implements Factory { + private final Class clazz; + + private ReflectionFactory(Class clazz) { + this.clazz = clazz; + } + + @Override + public Trait create() { + try { + return clazz.newInstance(); + } catch (Exception ex) { + return null; + } + } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/test/StorageTest.java b/src/net/citizensnpcs/test/StorageTest.java new file mode 100644 index 000000000..119595366 --- /dev/null +++ b/src/net/citizensnpcs/test/StorageTest.java @@ -0,0 +1,11 @@ +package net.citizensnpcs.test; + +import org.junit.Test; + +public class StorageTest { + + @Test + public void testYaml() { + + } +}