This commit is contained in:
aPunch 2012-01-20 09:15:32 -06:00
parent 204023728c
commit 0511dd53b8
2 changed files with 19 additions and 44 deletions

View File

@ -83,6 +83,7 @@ public class Citizens extends JavaPlugin {
private void setupNPCs() throws NPCLoadException { private void setupNPCs() throws NPCLoadException {
traitManager.registerTrait(LocationTrait.class); traitManager.registerTrait(LocationTrait.class);
int spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) { for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
int id = Integer.parseInt(key.name()); int id = Integer.parseInt(key.name());
if (!key.keyExists("name")) if (!key.keyExists("name"))
@ -107,9 +108,13 @@ public class Citizens extends JavaPlugin {
for (Trait trait : npc.getTraits()) { for (Trait trait : npc.getTraits()) {
trait.load(key); trait.load(key);
} }
// Spawn the NPC // Spawn the NPC
npc.spawn(npc.getTrait(LocationTrait.class).getLocation()); if (key.getBoolean("spawned")) {
npc.spawn(npc.getTrait(LocationTrait.class).getLocation());
spawned++;
}
} }
Messaging.log("Loaded " + npcManager.getNPCs().size() + " NPCs."); Messaging.log("Loaded " + npcManager.getNPCs().size() + " NPCs (" + spawned + " spawned).");
} }
} }

View File

@ -79,53 +79,32 @@ public class YamlStorage implements Storage {
@Override @Override
public boolean getBoolean(String key) { public boolean getBoolean(String key) {
String path = getKeyExt(key); return config.getBoolean(getKeyExt(key));
if (keyExists(path)) {
if (config.getString(path) == null)
return config.getBoolean(path);
return Boolean.parseBoolean(config.getString(path));
}
return false;
} }
@Override @Override
public boolean getBoolean(String keyExt, boolean def) { public boolean getBoolean(String key, boolean def) {
return config.getBoolean(getKeyExt(keyExt), def); return config.getBoolean(getKeyExt(key), def);
} }
@Override @Override
public double getDouble(String key) { public double getDouble(String key) {
String path = getKeyExt(key); return config.getDouble(getKeyExt(key));
if (keyExists(path)) {
if (config.getString(path) == null) {
if (config.get(path) instanceof Integer)
return config.getInt(path);
return config.getDouble(path);
}
return Double.parseDouble(config.getString(path));
}
return 0;
} }
@Override @Override
public double getDouble(String keyExt, double def) { public double getDouble(String key, double def) {
return config.getDouble(getKeyExt(keyExt), def); return config.getDouble(getKeyExt(key), def);
} }
@Override @Override
public int getInt(String key) { public int getInt(String key) {
String path = getKeyExt(key); return config.getInt(getKeyExt(key));
if (keyExists(path)) {
if (config.getString(path) == null)
return config.getInt(path);
return Integer.parseInt(config.getString(path));
}
return 0;
} }
@Override @Override
public int getInt(String path, int value) { public int getInt(String key, int value) {
return config.getInt(getKeyExt(path), value); return config.getInt(getKeyExt(key), value);
} }
@Override @Override
@ -149,21 +128,12 @@ public class YamlStorage implements Storage {
@Override @Override
public long getLong(String key) { public long getLong(String key) {
String path = getKeyExt(key); return config.getLong(getKeyExt(key));
if (keyExists(path)) {
if (config.getString(path) == null) {
if (config.get(path) instanceof Integer)
return config.getInt(path);
return config.getLong(path);
}
return Long.parseLong(config.getString(path));
}
return 0;
} }
@Override @Override
public long getLong(String keyExt, long def) { public long getLong(String key, long def) {
return config.getLong(getKeyExt(keyExt), def); return config.getLong(getKeyExt(key), def);
} }
@Override @Override