attempt some better trait exception handling

This commit is contained in:
aPunch 2012-02-03 17:35:24 -06:00
parent 2f69deec93
commit d30d892982
3 changed files with 15 additions and 10 deletions

Binary file not shown.

View File

@ -12,6 +12,7 @@ import java.util.logging.Level;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.DataKey;
import net.citizensnpcs.api.exception.NPCException;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.Character;
@ -205,13 +206,15 @@ public class Citizens extends JavaPlugin {
if (!key.keyExists("name"))
throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'.");
// TODO better trait exception handling
String type = key.getString("traits.type");
NPC npc = npcManager.createNPC(
type.equalsIgnoreCase("DEFAULT") ? CreatureType.MONSTER : CreatureType.valueOf(key.getString(
"traits.type").toUpperCase()), id, key.getString("name"), null);
npc.load(key);
try {
npc.load(key);
} catch (NPCException ex) {
Messaging.log(ex.getMessage());
}
++created;
if (npc.isSpawned())
++spawned;

View File

@ -1,8 +1,11 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.DataKey;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.trait.SaveId;
import net.citizensnpcs.api.npc.trait.Trait;
@SaveId("look-close")
public class LookClose implements Trait {
private boolean shouldLookClose;
@ -14,13 +17,12 @@ public class LookClose implements Trait {
}
@Override
public String getName() {
return "look-close";
}
@Override
public void load(DataKey key) {
shouldLookClose = key.getBoolean("");
public void load(DataKey key) throws NPCLoadException {
try {
shouldLookClose = key.getBoolean("");
} catch (Exception ex) {
throw new NPCLoadException("Invalid value. Valid values: true or false");
}
}
@Override