mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
attempt some better trait exception handling
This commit is contained in:
parent
2f69deec93
commit
d30d892982
Binary file not shown.
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user