This commit is contained in:
aPunch 2012-01-20 01:48:55 -06:00
parent 504d4f94d2
commit a240b71573
3 changed files with 13 additions and 7 deletions

View File

@ -70,11 +70,11 @@ public class Citizens extends JavaPlugin {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
if (args[0].equals("test")) {
if (args[0].equals("spawn")) {
NPC npc = npcManager.createNPC("aPunch");
npc.spawn(((Player) sender).getLocation());
} else if (args[0].equals("testremove")) {
for(NPC npc : npcManager.getNPCs()) {
} else if (args[0].equals("despawn")) {
for (NPC npc : npcManager.getNPCs()) {
npc.despawn();
}
}
@ -82,7 +82,6 @@ public class Citizens extends JavaPlugin {
}
private void setupNPCs() throws NPCLoadException {
// TODO needs fixing
traitManager.registerTrait(LocationTrait.class);
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
int id = Integer.parseInt(key.name());

View File

@ -29,14 +29,17 @@ public class EventListen implements Listener {
*/
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled() || !CitizensAPI.getNPCManager().isNPC(event.getEntity()))
if (!CitizensAPI.getNPCManager().isNPC(event.getEntity()))
return;
event.setCancelled(true);
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
if (e.getDamager() instanceof Player) {
NPC npc = CitizensAPI.getNPCManager().getNPC(event.getEntity());
npc.getCharacter().onLeftClick(npc, (Player) e.getDamager());
if (npc.getCharacter() != null) {
npc.getCharacter().onLeftClick(npc, (Player) e.getDamager());
}
}
}
}

View File

@ -143,7 +143,11 @@ public class CitizensNPC implements NPC {
mcEntity = manager.spawn(this, loc);
else
manager.spawn(this, loc);
// Set the location
addTrait(LocationTrait.class);
getTrait(LocationTrait.class).setLocation(loc);
spawned = true;
}
@ -156,8 +160,8 @@ public class CitizensNPC implements NPC {
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this));
mcEntity.die();
manager.despawn(this);
mcEntity.die();
spawned = false;
}