diff --git a/src/api b/src/api index 0bbb00f1e..d053084ee 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 0bbb00f1e1c61dc69e207c9aa22bf9b86a7d3f32 +Subproject commit d053084ee064424da495a84032ac4179cdf365d3 diff --git a/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java b/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java index d01768857..d02c0ad59 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java +++ b/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java @@ -22,6 +22,16 @@ public class ScriptedActionManager implements IActionManager { private final Deque actionQueue = new LinkedList<>(); private final List conditionalActions = new LinkedList<>(); + @Override + public IAction create(String name) { + return new Action(name); + } + + @Override + public IAction create(Consumer t) { + return new Action(t); + } + @Override public IAction create(String name, int maxDuration, int startAfterTicks, Consumer task) { return new Action(name, maxDuration, startAfterTicks, task); @@ -42,11 +52,6 @@ public class ScriptedActionManager implements IActionManager { return new Action(name, t); } - @Override - public IAction create(Consumer t) { - return new Action(t); - } - @Override public IConditionalAction create(Supplier predicate, Consumer task) { return new ConditionalAction(predicate, task); @@ -235,9 +240,17 @@ public class ScriptedActionManager implements IActionManager { protected int duration; protected int maxDuration = -1; protected int updateEveryXTick = 5; - protected final Consumer task; + protected Consumer task; private boolean done = false; + protected ActionBase(String name) { + this.name = name; + } + + protected ActionBase(Consumer task) { + this(task.toString()); + this.task = task; + } protected ActionBase(String name, int maxDuration, int startAfterTicks, Consumer task) { this.name = name; this.maxDuration = maxDuration; @@ -261,10 +274,12 @@ public class ScriptedActionManager implements IActionManager { this.startAfterTicks = startAfterTicks; } - protected ActionBase(Consumer task) { - this.name = task.toString(); + @Override + public IAction setTask(Consumer task) { this.task = task; + return this; } + /** * Called once per global tick; respects delay, interval, duration & done‐flag. */ @@ -306,6 +321,12 @@ public class ScriptedActionManager implements IActionManager { return maxDuration; } + @Override + public IAction setMaxDuration(int x) { + maxDuration = x; + return this; + } + @Override public void markDone() { done = true; @@ -328,6 +349,12 @@ public class ScriptedActionManager implements IActionManager { return this; } + @Override + public IAction removeData(String key) { + dataStore.remove(key); + return this; + } + @Override public int getUpdateEveryXTick() { return updateEveryXTick; @@ -344,6 +371,11 @@ public class ScriptedActionManager implements IActionManager { return startAfterTicks; } + @Override + public IAction pauseFor(int ticks) { + startAfterTicks = ticks; + return this; + } @Override public IAction getNext() { int idx = getIndex(this); @@ -434,6 +466,14 @@ public class ScriptedActionManager implements IActionManager { } private class Action extends ActionBase { + + public Action(String name) { + super(name); + } + + public Action(Consumer task) { + super(task); + } public Action(String name, int maxDuration, int startAfterTicks, Consumer task) { super(name, maxDuration, startAfterTicks, task); } @@ -450,9 +490,6 @@ public class ScriptedActionManager implements IActionManager { super(startAfterTicks, task); } - public Action(Consumer task) { - super(task); - } @Override public int getCheckCount() { return 0; }