added names

This commit is contained in:
aPunch 2012-01-14 22:41:02 -06:00
parent ffd078a3f8
commit a3dd54757e
3 changed files with 28 additions and 9 deletions

Binary file not shown.

View File

@ -14,17 +14,20 @@ import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
import net.citizensnpcs.resources.lib.CraftNPC;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
public class CitizensNPC implements NPC {
private final int id;
private final Set<Trait> traits = new HashSet<Trait>();
private Character character = null;
private final Set<Trait> traits = new HashSet<Trait>();
private String name;
private CraftNPC mcEntity;
private boolean spawned;
private final CitizensNPCManager manager;
protected CitizensNPC(Character character, Trait... traits) {
protected CitizensNPC(String name, Character character, Trait... traits) {
this.name = name;
this.character = character;
for (Trait trait : traits) {
this.traits.add(trait);
@ -33,6 +36,21 @@ public class CitizensNPC implements NPC {
id = manager.getUniqueID();
}
@Override
public String getFullName() {
return name;
}
@Override
public String getName() {
return ChatColor.stripColor(name);
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public void addTrait(Trait trait) {
if (!hasTrait(trait))

View File

@ -29,18 +29,18 @@ public class CitizensNPCManager implements NPCManager {
private Map<Integer, NPC> byID = new HashMap<Integer, NPC>();
@Override
public NPC createNPC() {
return createNPC(null);
public NPC createNPC(String name) {
return createNPC(name, null);
}
@Override
public NPC createNPC(Character character) {
return createNPC(character);
public NPC createNPC(String name, Character character) {
return createNPC(name, character);
}
@Override
public NPC createNPC(Character character, Trait... traits) {
CitizensNPC npc = new CitizensNPC(character, traits);
public NPC createNPC(String name, Character character, Trait... traits) {
CitizensNPC npc = new CitizensNPC(name, character, traits);
byID.put(npc.getId(), npc);
return npc;
}
@ -100,7 +100,8 @@ public class CitizensNPCManager implements NPCManager {
public CraftNPC spawn(NPC npc) {
Location loc = ((LocationTrait) npc.getTrait("location")).getLocation();
WorldServer ws = getWorldServer(loc.getWorld());
CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, "", new ItemInWorldManager(ws));
CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(),
new ItemInWorldManager(ws));
mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
ws.addEntity(mcEntity);
ws.players.remove(mcEntity);