mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 04:57:27 +00:00
IAction exceptions now report to CNPC+ script console
This commit is contained in:
1 parent
74198534af
commit
6a04a0ea28
2 files changed
+37
-16
No files matched your search
@@ -2,8 +2,10 @@ package noppes.npcs.controllers.data.action;
|
||||
|
||||
import noppes.npcs.api.handler.data.IAction;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.ScriptedActionManager;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -24,28 +26,20 @@ public class Action implements IAction {
|
||||
protected boolean isThreaded;
|
||||
protected ActionThread actionThread;
|
||||
|
||||
protected ScriptContainer reportTo;
|
||||
|
||||
public Action(ScriptedActionManager manager, String name) {
|
||||
this.manager = manager;
|
||||
this.name = name;
|
||||
|
||||
if (ScriptContainer.Current != null)
|
||||
reportTo = ScriptContainer.Current;
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, Consumer<IAction> task) {
|
||||
this(manager, task.toString(), task);
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, String name, int maxDuration, int startAfterTicks, Consumer<IAction> task) {
|
||||
this.manager = manager;
|
||||
this.name = name;
|
||||
this.maxDuration = maxDuration;
|
||||
this.startAfterTicks = startAfterTicks;
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, String name, int startAfterTicks, Consumer<IAction> task) {
|
||||
this(manager, name, task);
|
||||
this.startAfterTicks = startAfterTicks;
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, String name, Consumer<IAction> task) {
|
||||
this(manager, name);
|
||||
this.task = task;
|
||||
@@ -56,11 +50,22 @@ public class Action implements IAction {
|
||||
this.startAfterTicks = startAfterTicks;
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, String name, int startAfterTicks, Consumer<IAction> task) {
|
||||
this(manager, name, task);
|
||||
this.startAfterTicks = startAfterTicks;
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, int maxDuration, int startAfterTicks, Consumer<IAction> task) {
|
||||
this(manager, startAfterTicks, task);
|
||||
this.maxDuration = maxDuration;
|
||||
}
|
||||
|
||||
public Action(ScriptedActionManager manager, String name, int maxDuration, int startAfterTicks, Consumer<IAction> task) {
|
||||
this(manager, name, startAfterTicks, task);
|
||||
this.maxDuration = maxDuration;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IAction setTask(Consumer<IAction> task) {
|
||||
this.task = task;
|
||||
@@ -91,7 +96,12 @@ public class Action implements IAction {
|
||||
task.accept(this);
|
||||
count++;
|
||||
} catch (Throwable t) {
|
||||
System.err.println("IAction '" + name + "' threw an exception:");
|
||||
String err = "IAction '" + name + "' threw an exception:";
|
||||
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
System.err.println(err);
|
||||
t.printStackTrace();
|
||||
markDone();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data.action;
|
||||
import noppes.npcs.api.handler.data.IAction;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.scripted.ScriptedActionManager;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
@@ -85,7 +86,12 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
count++;
|
||||
taskExecuted = true;
|
||||
} catch (Throwable t) {
|
||||
System.err.println("IConditionalAction '" + getName() + "' threw an exception:");
|
||||
String err = "IConditionalAction '" + getName() + "' threw an exception:";
|
||||
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
System.err.println(err);
|
||||
t.printStackTrace();
|
||||
markDone();
|
||||
}
|
||||
@@ -95,7 +101,12 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
try {
|
||||
onTermination.accept(this);
|
||||
} catch (Throwable t) {
|
||||
System.err.println("IConditionalAction's onTermination '" + getName() + "' threw an exception:");
|
||||
String err = "IConditionalAction's onTermination '" + getName() + "' threw an exception:";
|
||||
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
System.err.println(err);
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user