diff --git a/build.gradle b/build.gradle index c844354bc..a375e9c8a 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.10-testingbeta18.2" +version = "1.10-testingbeta18.4" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/noppes/npcs/controllers/data/action/Action.java b/src/main/java/noppes/npcs/controllers/data/action/Action.java index 5151f7a56..fc237d6b1 100644 --- a/src/main/java/noppes/npcs/controllers/data/action/Action.java +++ b/src/main/java/noppes/npcs/controllers/data/action/Action.java @@ -69,8 +69,14 @@ public class Action implements IAction { return; } if (ticksExisted % updateEveryXTick == 0 && task != null) { - task.accept(this); - count++; + try { + task.accept(this); + count++; + } catch (Throwable t) { + System.err.println("Scripted action '" + name + "' threw an exception:"); + t.printStackTrace(); + markDone(); + } } duration++; } diff --git a/src/main/java/noppes/npcs/controllers/data/action/ConditionalAction.java b/src/main/java/noppes/npcs/controllers/data/action/ConditionalAction.java index 161ec560e..9baf1d999 100644 --- a/src/main/java/noppes/npcs/controllers/data/action/ConditionalAction.java +++ b/src/main/java/noppes/npcs/controllers/data/action/ConditionalAction.java @@ -48,23 +48,38 @@ public class ConditionalAction extends Action implements IConditionalAction { @Override public void tick(int ticksExisted) { if (isDone()) return; - if (ticksExisted % updateEveryXTick == 0) { - checkCount++; - boolean terminated = terminateWhen != null && terminateWhen.get(); - if (terminated && onTermination != null) - onTermination.accept(this); - if ((maxChecks >= 0 && checkCount > maxChecks) || terminated) { - markDone(); - return; - } + try { + if (ticksExisted % updateEveryXTick == 0) { + checkCount++; + boolean terminated = terminateWhen != null && terminateWhen.get(); - if (condition != null && condition.get()) { - task.accept(this); - taskExecuted = true; + if (terminated && onTermination != null) { + try { + onTermination.accept(this); + } catch (Throwable t) { + System.err.println("Error in onTermination for conditional '" + getName() + "':"); + t.printStackTrace(); + } + } + + if ((maxChecks >= 0 && checkCount > maxChecks) || terminated) { + markDone(); + return; + } + + if (condition != null && condition.get()) { + task.accept(this); + taskExecuted = true; + } } + } catch (Throwable t) { + System.err.println("Scripted conditional '" + getName() + "' threw an exception:"); + t.printStackTrace(); + markDone(); + } finally { + duration++; } - duration++; } @Override