This commit is contained in:
fullwall 2012-01-22 22:09:32 +08:00
commit 7cb59f9f8a
5 changed files with 18 additions and 23 deletions

View File

@ -14,6 +14,7 @@ import net.citizensnpcs.npc.trait.CitizensCharacterManager;
import net.citizensnpcs.npc.trait.CitizensTraitManager;
import net.citizensnpcs.storage.Storage;
import net.citizensnpcs.storage.flatfile.YamlStorage;
import net.citizensnpcs.util.ByIdArray;
import net.citizensnpcs.util.Messaging;
import org.bukkit.Bukkit;
@ -92,7 +93,6 @@ public class Citizens extends JavaPlugin {
// TODO possibly separate this out some more
private void setupNPCs() throws NPCLoadException {
traitManager.registerTrait("location", SpawnLocation.class);
int spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
int id = Integer.parseInt(key.name());
if (!key.keyExists("name"))
@ -121,19 +121,18 @@ public class Citizens extends JavaPlugin {
}
// Spawn the NPC
if (key.getBoolean("spawned")) {
if (key.getBoolean("spawned"))
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
spawned++;
}
}
Messaging.log("Loaded " + npcManager.size() + " NPCs (" + spawned + " spawned).");
Messaging.log("Loaded " + ((ByIdArray<NPC>) npcManager.getAllNPCs()).size() + " NPCs ("
+ ((ByIdArray<NPC>) npcManager.getSpawnedNPCs()).size() + " spawned).");
}
private void saveNPCs() {
for (NPC npc : npcManager.getAllNPCs()) {
DataKey root = saves.getKey("npc." + npc.getId());
root.setString("name", npc.getFullName());
root.setBoolean("spawned", npc.isSpawned());
root.setBoolean("spawned", npc.getBukkitEntity().isDead());
// Save the character if it exists
if (npc.getCharacter() != null) {
@ -142,9 +141,8 @@ public class Citizens extends JavaPlugin {
}
// Save all existing traits
for (Trait trait : npc.getTraits()) {
for (Trait trait : npc.getTraits())
trait.save(root.getRelative(trait.getName()));
}
}
saves.save();
}

View File

@ -52,7 +52,8 @@ public class EventListen implements Listener {
return;
NPC npc = manager.getNPC(event.getEntity());
npc.getCharacter().onRightClick(npc, (Player) event.getTarget());
if (npc.getCharacter() != null)
npc.getCharacter().onRightClick(npc, (Player) event.getTarget());
}
/*

View File

@ -27,8 +27,8 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class CitizensNPCManager implements NPCManager {
private final ByIdArray<NPC> spawned = ByIdArray.create();
private final ByIdArray<NPC> byID = ByIdArray.create();
private final ByIdArray<NPC> spawned = new ByIdArray<NPC>();
private final ByIdArray<NPC> byID = new ByIdArray<NPC>();
@Override
public NPC createNPC(String name) {
@ -65,7 +65,7 @@ public class CitizensNPCManager implements NPCManager {
@Override
public Collection<NPC> getNPCs(Class<? extends Trait> trait) {
List<NPC> npcs = new ArrayList<NPC>();
for (NPC npc : byID) {
for (NPC npc : getAllNPCs()) {
if (npc.hasTrait(trait))
npcs.add(npc);
}
@ -129,8 +129,4 @@ public class CitizensNPCManager implements NPCManager {
private MinecraftServer getMinecraftServer(Server server) {
return ((CraftServer) server).getServer();
}
public int size() {
return byID.size();
}
}

View File

@ -1,10 +1,10 @@
package net.citizensnpcs.test;
import org.junit.Test;
//import org.junit.Test;
public class StorageTest {
@Test
// @Test
public void testYaml() {
}

View File

@ -130,7 +130,11 @@ public class ByIdArray<T> implements Iterable<T> {
if (elementData.length > highest)
elementData = Arrays.copyOf(elementData, highest + 1);
}
public boolean contains(int index) {
return elementData.length > index && elementData[index] != null;
}
public static <T> ByIdArray<T> create() {
return new ByIdArray<T>();
}
@ -138,8 +142,4 @@ public class ByIdArray<T> implements Iterable<T> {
public static <T> ByIdArray<T> create(int capacity) {
return new ByIdArray<T>(capacity);
}
public boolean contains(int index) {
return elementData.length > index && elementData[index] != null;
}
}