added spawned trait

This commit is contained in:
aPunch 2012-01-29 12:23:42 -06:00
parent 967eef4836
commit 0e737cc367
4 changed files with 18 additions and 7 deletions

Binary file not shown.

View File

@ -19,6 +19,7 @@ import net.citizensnpcs.api.npc.trait.InstanceFactory;
import net.citizensnpcs.api.npc.trait.Trait;
import net.citizensnpcs.api.npc.trait.trait.Owner;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.api.npc.trait.trait.Spawned;
import net.citizensnpcs.command.CommandManager;
import net.citizensnpcs.command.Injector;
import net.citizensnpcs.command.command.NPCCommands;
@ -175,6 +176,7 @@ public class Citizens extends JavaPlugin {
private void setupNPCs() throws NPCLoadException {
traitManager.register("location", SpawnLocation.class);
traitManager.register("owner", Owner.class);
traitManager.register("spawned", Spawned.class);
int created = 0, spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.trait.DefaultInstanceFactory;
import net.citizensnpcs.api.npc.trait.trait.Owner;
import net.citizensnpcs.api.npc.trait.trait.Spawned;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.annotation.Command;
import net.citizensnpcs.command.annotation.Permission;
@ -85,6 +86,7 @@ public class NPCCommands {
min = 2,
max = 2)
@Permission("npc.spawn")
@Requirements
public void spawnNPC(CommandContext args, Player player, NPC npc) {
CitizensNPC respawn = (CitizensNPC) npcManager.getNPC(args.getInteger(1));
if (respawn == null) {
@ -120,8 +122,8 @@ public class NPCCommands {
@Requirements(ownership = true)
public void selectNPC(CommandContext args, Player player, NPC npc) {
NPC toSelect = npcManager.getNPC(args.getInteger(1));
if (toSelect == null) {
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' exists.");
if (toSelect == null || !toSelect.getTrait(Spawned.class).isSpawned()) {
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
return;
}
if (npc != null && toSelect.getId() == npc.getId()) {

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.ai.Navigator;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.api.npc.trait.trait.Spawned;
import net.citizensnpcs.npc.ai.CitizensNavigator;
import net.citizensnpcs.resource.lib.CraftNPC;
import net.citizensnpcs.util.Messaging;
@ -15,7 +16,6 @@ import org.bukkit.entity.Player;
public class CitizensNPC extends AbstractNPC {
private CraftNPC mcEntity;
private boolean spawned;
private final CitizensNPCManager manager;
public CitizensNPC(CitizensNPCManager manager, int id, String name) {
@ -33,8 +33,8 @@ public class CitizensNPC extends AbstractNPC {
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this));
manager.despawn(this);
getTrait(Spawned.class).setSpawned(false);
spawned = false;
return true;
}
@ -54,7 +54,7 @@ public class CitizensNPC extends AbstractNPC {
@Override
public boolean isSpawned() {
return spawned;
return getHandle() != null;
}
@Override
@ -79,9 +79,16 @@ public class CitizensNPC extends AbstractNPC {
mcEntity = manager.spawn(this, loc);
// Set the location
addTrait(new SpawnLocation(loc));
if (!hasTrait(SpawnLocation.class))
addTrait(new SpawnLocation(loc));
else
getTrait(SpawnLocation.class).setLocation(loc);
if (!hasTrait(Spawned.class))
addTrait(new Spawned(true));
else
getTrait(Spawned.class).setSpawned(true);
spawned = true;
return true;
}
}