update for SpawnLocation trait

This commit is contained in:
aPunch 2012-01-21 10:21:21 -06:00
parent 7e7e4ff37a
commit f583344506
5 changed files with 15 additions and 12 deletions

Binary file not shown.

View File

@ -8,7 +8,7 @@ import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.trait.Trait;
import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.trait.CitizensCharacterManager;
import net.citizensnpcs.npc.trait.CitizensTraitManager;
@ -94,7 +94,7 @@ public class Citizens extends JavaPlugin {
// TODO possibly separate this out some more
private void setupNPCs() throws NPCLoadException {
traitManager.registerTrait(LocationTrait.class);
traitManager.registerTrait(SpawnLocation.class);
int spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
int id = Integer.parseInt(key.name());
@ -129,7 +129,7 @@ public class Citizens extends JavaPlugin {
// Spawn the NPC
if (key.getBoolean("spawned")) {
npc.spawn(npc.getTrait(LocationTrait.class).getLocation());
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
spawned++;
}
}

View File

@ -5,7 +5,7 @@ import java.util.Set;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -57,7 +57,7 @@ public class EventListen implements Listener {
public void onChunkLoad(ChunkLoadEvent event) {
for (int id : toRespawn) {
NPC npc = CitizensAPI.getNPCManager().getNPC(id);
npc.spawn(npc.getTrait(LocationTrait.class).getLocation());
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
toRespawn.remove(id);
}
}
@ -68,10 +68,11 @@ public class EventListen implements Listener {
return;
for (NPC npc : CitizensAPI.getNPCManager().getNPCs()) {
Location loc = npc.getTrait(LocationTrait.class).getLocation();
Location loc = npc.getBukkitEntity().getLocation();
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
&& event.getChunk().getZ() == loc.getChunk().getZ()) {
toRespawn.add(npc.getId());
npc.getTrait(SpawnLocation.class).setLocation(loc);
npc.despawn();
}
}

View File

@ -10,7 +10,7 @@ import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.pathfinding.Navigator;
import net.citizensnpcs.api.npc.trait.Trait;
import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.resources.lib.CraftNPC;
import net.citizensnpcs.util.Messaging;
@ -143,8 +143,8 @@ public class CitizensNPC implements NPC {
manager.spawn(this, loc);
// Set the location
addTrait(LocationTrait.class);
getTrait(LocationTrait.class).setLocation(loc);
addTrait(SpawnLocation.class);
getTrait(SpawnLocation.class).setLocation(loc);
spawned = true;
}

View File

@ -20,7 +20,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCManager;
import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.trait.Trait;
import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.resources.lib.CraftNPC;
import net.minecraft.server.ItemInWorldManager;
@ -92,7 +92,6 @@ public class CitizensNPCManager implements NPCManager {
mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
ws.addEntity(mcEntity);
ws.players.remove(mcEntity);
// mcEntity.removeFromPlayerMap(npc.getFullName());
spawned.put(mcEntity.getPlayer(), npc);
return mcEntity;
@ -103,7 +102,10 @@ public class CitizensNPCManager implements NPCManager {
for (Player player : Bukkit.getOnlinePlayers()) {
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(mcEntity.id));
}
getWorldServer(npc.getTrait(LocationTrait.class).getLocation().getWorld()).removeEntity(mcEntity);
Location loc = npc.getBukkitEntity().getLocation();
getWorldServer(loc.getWorld()).removeEntity(mcEntity);
npc.getTrait(SpawnLocation.class).setLocation(loc);
spawned.remove(mcEntity.getPlayer());
}