Skip to content

Commit

Permalink
Don't fail to spawn if a trait has an exception when onSpawn() is called
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 9, 2013
1 parent 93718a3 commit 6cf744c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,14 @@ public boolean spawn(Location at) {

navigator.onSpawn();
// Modify NPC using traits after the entity has been created
for (Trait trait : traits.values())
trait.onSpawn();
for (Trait trait : traits.values()) {
try {
trait.onSpawn();
} catch (Exception ex) {
Messaging.severeTr(Messages.TRAIT_ONSPAWN_FAILED, trait.getName(), getId());
ex.printStackTrace();
}
}
getBukkitEntity().setRemoveWhenFarAway(false);
getBukkitEntity().setCustomName(getFullName());
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/citizensnpcs/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Messages {
public static final String ERROR_STOPPING_NETWORK_THREADS = "citizens.nms-errors.stopping-network-threads";
public static final String ERROR_UPDATING_NAVIGATION_WORLD = "citizens.nms-errors.updating-navigation-world";
public static final String ERROR_UPDATING_PATHFINDING_RANGE = "citizens.nms-errors.updating-pathfinding-range";
public static final String ERROR_UPDATING_SPEED = "citizens.nms-erorrs.updating-land-modifier";
public static final String ERROR_UPDATING_SPEED = "citizens.nms-errors.updating-land-modifier";
public static final String EXCEPTION_UPDATING_NPC = "citizens.notifications.exception-updating-npc";
public static final String FAILED_LOAD_SAVES = "citizens.saves.load-failed";
public static final String FAILED_TO_MOUNT_NPC = "citizens.commands.npc.mount.failed";
Expand Down Expand Up @@ -190,6 +190,7 @@ public class Messages {
public static final String TRAIT_NOT_CONFIGURABLE = "citizens.commands.traitc.not-configurable";
public static final String TRAIT_NOT_FOUND = "citizens.commands.traitc.missing";
public static final String TRAIT_NOT_FOUND_ON_NPC = "citizens.commands.traitc.not-on-npc";
public static final String TRAIT_ONSPAWN_FAILED = "citizens.notifications.trait-onspawn-failed";
public static final String TRAITS_ADDED = "citizens.commands.trait.added";
public static final String TRAITS_FAILED_TO_ADD = "citizens.commands.trait.failed-to-add";
public static final String TRAITS_FAILED_TO_CHANGE = "citizens.commands.trait.failed-to-change";
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ citizens.notifications.saving=Saving Citizens...
citizens.notifications.skipping-broken-trait=Skipped broken or missing trait {0} while loading ID {1}. Has the name changed?
citizens.notifications.skipping-invalid-pose=Skipping pose {0} - invalid yaw/pitch ({1}).
citizens.notifications.trait-load-failed=The trait {0} failed to load for NPC ID: {1}.
citizens.notifications.trait-onspawn-failed=An exception occurred while the trait {0} was spawning for NPC ID {1}.
citizens.notifications.unknown-npc-type=NPC type {0} was not recognized. Did you spell it correctly?
citizens.saves.load-failed=Unable to load saves, disabling...
citizens.settings.writing-default=Writing default setting: {0}
Expand Down

0 comments on commit 6cf744c

Please sign in to comment.