removed some methods from API

This commit is contained in:
aPunch 2012-03-10 13:41:09 -06:00
parent 95cddba16b
commit 0c70b28803
3 changed files with 35 additions and 26 deletions

View File

@ -28,10 +28,12 @@ public abstract class CitizensNPC extends AbstractNPC {
protected final CitizensAI ai = new CitizensAI(this);
protected final CitizensNPCManager manager;
protected EntityLiving mcEntity;
private final CitizensTraitManager traitManager;
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
super(id, name);
this.manager = manager;
traitManager = (CitizensTraitManager) CitizensAPI.getTraitManager();
}
@Override
@ -83,6 +85,15 @@ public abstract class CitizensNPC extends AbstractNPC {
return inventory;
}
@Override
public <T extends Trait> T getTrait(Class<T> clazz) {
Trait t = traits.get(clazz);
if (t == null)
addTrait(traitManager.getTrait(clazz, this));
return traits.get(clazz) != null ? clazz.cast(traits.get(clazz)) : null;
}
@Override
public boolean isSpawned() {
return getHandle() != null;
@ -139,7 +150,7 @@ public abstract class CitizensNPC extends AbstractNPC {
// Load traits
for (DataKey traitKey : root.getRelative("traits").getSubKeys()) {
Trait trait = CitizensAPI.getTraitManager().getTrait(traitKey.name(), this);
Trait trait = traitManager.getTrait(traitKey.name(), this);
if (trait == null)
throw new NPCLoadException("No trait with the name '" + traitKey.name()
+ "' exists. Was it registered properly?");

View File

@ -35,22 +35,6 @@ public class CitizensTraitManager implements TraitManager {
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints"));
}
@SuppressWarnings("unchecked")
@Override
public <T extends Trait> T getTrait(String name, NPC npc) {
if (!registered.containsKey(name))
return null;
Trait t = getTrait(registered.get(name), npc);
try {
if (t.getName() == null)
t.setName(name);
return (T) t;
} catch (TraitException ex) {
ex.printStackTrace();
}
return null;
}
@Override
public <T extends Trait> T getTrait(Class<T> clazz) {
return getTrait(clazz, null);
@ -58,6 +42,18 @@ public class CitizensTraitManager implements TraitManager {
@SuppressWarnings("unchecked")
@Override
public <T extends Trait> T getTrait(String name) {
if (!registered.containsKey(name))
return null;
return (T) create(registered.get(name), null);
}
@Override
public void registerTrait(TraitFactory factory) {
registered.put(factory.getName(), factory.getTraitClass());
}
@SuppressWarnings("unchecked")
public <T extends Trait> T getTrait(Class<T> clazz, NPC npc) {
for (String name : registered.keySet())
if (registered.get(name).equals(clazz)) {
@ -74,16 +70,18 @@ public class CitizensTraitManager implements TraitManager {
}
@SuppressWarnings("unchecked")
@Override
public <T extends Trait> T getTrait(String name) {
public <T extends Trait> T getTrait(String name, NPC npc) {
if (!registered.containsKey(name))
return null;
return (T) create(registered.get(name), null);
}
@Override
public void registerTrait(TraitFactory factory) {
registered.put(factory.getName(), factory.getTraitClass());
Trait t = getTrait(registered.get(name), npc);
try {
if (t.getName() == null)
t.setName(name);
return (T) t;
} catch (TraitException ex) {
ex.printStackTrace();
}
return null;
}
@SuppressWarnings("unchecked")

View File

@ -23,7 +23,7 @@ public class NavigationStrategy implements PathStrategy {
NavigationStrategy(EntityLiving entity, EntityLiving target) {
if (entity instanceof EntityHumanNPC)
entity = entity;
this.entity = (EntityHumanNPC) entity;
navigation = entity.ak();
navigation.a(target, getSpeed(entity));
}