mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 14:43:54 +01:00
removed some methods from API
This commit is contained in:
parent
95cddba16b
commit
0c70b28803
@ -28,10 +28,12 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
protected final CitizensAI ai = new CitizensAI(this);
|
protected final CitizensAI ai = new CitizensAI(this);
|
||||||
protected final CitizensNPCManager manager;
|
protected final CitizensNPCManager manager;
|
||||||
protected EntityLiving mcEntity;
|
protected EntityLiving mcEntity;
|
||||||
|
private final CitizensTraitManager traitManager;
|
||||||
|
|
||||||
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
traitManager = (CitizensTraitManager) CitizensAPI.getTraitManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,6 +85,15 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
return inventory;
|
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
|
@Override
|
||||||
public boolean isSpawned() {
|
public boolean isSpawned() {
|
||||||
return getHandle() != null;
|
return getHandle() != null;
|
||||||
@ -139,7 +150,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
// Load traits
|
// Load traits
|
||||||
for (DataKey traitKey : root.getRelative("traits").getSubKeys()) {
|
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)
|
if (trait == null)
|
||||||
throw new NPCLoadException("No trait with the name '" + traitKey.name()
|
throw new NPCLoadException("No trait with the name '" + traitKey.name()
|
||||||
+ "' exists. Was it registered properly?");
|
+ "' exists. Was it registered properly?");
|
||||||
|
@ -35,22 +35,6 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints"));
|
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
|
@Override
|
||||||
public <T extends Trait> T getTrait(Class<T> clazz) {
|
public <T extends Trait> T getTrait(Class<T> clazz) {
|
||||||
return getTrait(clazz, null);
|
return getTrait(clazz, null);
|
||||||
@ -58,6 +42,18 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@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) {
|
public <T extends Trait> T getTrait(Class<T> clazz, NPC npc) {
|
||||||
for (String name : registered.keySet())
|
for (String name : registered.keySet())
|
||||||
if (registered.get(name).equals(clazz)) {
|
if (registered.get(name).equals(clazz)) {
|
||||||
@ -74,16 +70,18 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
public <T extends Trait> T getTrait(String name, NPC npc) {
|
||||||
public <T extends Trait> T getTrait(String name) {
|
|
||||||
if (!registered.containsKey(name))
|
if (!registered.containsKey(name))
|
||||||
return null;
|
return null;
|
||||||
return (T) create(registered.get(name), null);
|
Trait t = getTrait(registered.get(name), npc);
|
||||||
}
|
try {
|
||||||
|
if (t.getName() == null)
|
||||||
@Override
|
t.setName(name);
|
||||||
public void registerTrait(TraitFactory factory) {
|
return (T) t;
|
||||||
registered.put(factory.getName(), factory.getTraitClass());
|
} catch (TraitException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -23,7 +23,7 @@ public class NavigationStrategy implements PathStrategy {
|
|||||||
|
|
||||||
NavigationStrategy(EntityLiving entity, EntityLiving target) {
|
NavigationStrategy(EntityLiving entity, EntityLiving target) {
|
||||||
if (entity instanceof EntityHumanNPC)
|
if (entity instanceof EntityHumanNPC)
|
||||||
entity = entity;
|
this.entity = (EntityHumanNPC) entity;
|
||||||
navigation = entity.ak();
|
navigation = entity.ak();
|
||||||
navigation.a(target, getSpeed(entity));
|
navigation.a(target, getSpeed(entity));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user