mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 23:04:08 +00:00
Added killWhenEmpty and killAfterTicks to IActionQueue
This commit is contained in:
1 parent
fc6c56e40d
commit
ad4aac1e43
2 files changed
+63
-17
No files matched your search
@@ -23,9 +23,9 @@ import java.util.function.Function;
|
||||
public class ActionManager implements IActionManager {
|
||||
protected boolean isWorking = false;
|
||||
|
||||
protected final IActionQueue sequentialQueue = new ActionQueue(this, "mainSequential");
|
||||
protected final IActionQueue parallelQueue = new ActionQueue(this, "mainParallel").setParallel(true);
|
||||
protected final IActionQueue conditionalQueue = new ActionQueue(this, "mainConditional").setParallel(true);
|
||||
protected final ActionQueue sequentialQueue = new ActionQueue(this, "mainSequential");
|
||||
protected final ActionQueue parallelQueue = new ActionQueue(this, "mainParallel", true);
|
||||
protected final ActionQueue conditionalQueue = new ActionQueue(this, "mainConditional", true);
|
||||
|
||||
protected final Map<String, IActionQueue> otherQueues = new HashMap<>();
|
||||
|
||||
@@ -118,7 +118,7 @@ public class ActionManager implements IActionManager {
|
||||
}
|
||||
|
||||
public IActionQueue createQueue(String name, boolean isParallel) {
|
||||
IActionQueue queue = new ActionQueue(this, name, isParallel);
|
||||
IActionQueue queue = new ActionQueue(this, name, isParallel).killWhenEmpty(true);
|
||||
otherQueues.put(name, queue);
|
||||
return queue;
|
||||
}
|
||||
@@ -376,13 +376,13 @@ public class ActionManager implements IActionManager {
|
||||
if (!isWorking) return;
|
||||
|
||||
// ─── Sequential (head only) ─────────────────────────────────
|
||||
((ActionQueue) sequentialQueue).tick(ticksExisted);
|
||||
sequentialQueue.tick(ticksExisted);
|
||||
|
||||
// ─── Parallel (all) ───────────────────────────────────────
|
||||
((ActionQueue) parallelQueue).tick(ticksExisted);
|
||||
parallelQueue.tick(ticksExisted);
|
||||
|
||||
// ─── Conditionals ─────────────────────────────────────────
|
||||
((ActionQueue) conditionalQueue).tick(ticksExisted);
|
||||
conditionalQueue.tick(ticksExisted);
|
||||
|
||||
// ─── Other Queues ─────────────────────────────────────────
|
||||
otherQueues.forEach((name, queue) -> ((ActionQueue) queue).tick(ticksExisted));
|
||||
|
||||
@@ -14,8 +14,10 @@ public class ActionQueue implements IActionQueue {
|
||||
protected final ActionManager manager;
|
||||
protected final String name;
|
||||
|
||||
protected boolean isParallel;
|
||||
protected boolean isWorking;
|
||||
protected boolean isParallel;
|
||||
protected boolean killWhenEmpty;
|
||||
protected int killAfterTicks = 100;
|
||||
|
||||
public ActionQueue(ActionManager manager, String name) {
|
||||
this.manager = manager;
|
||||
@@ -47,21 +49,48 @@ public class ActionQueue implements IActionQueue {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return isParallel;
|
||||
}
|
||||
|
||||
public IActionQueue setParallel(boolean parallel) {
|
||||
isParallel = parallel;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<IAction> getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return isParallel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionQueue setParallel(boolean parallel) {
|
||||
isParallel = parallel;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public boolean isKilledWhenEmpty() {
|
||||
return killWhenEmpty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKillAfterTicks() {
|
||||
return killAfterTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionQueue killWhenEmpty(boolean killWhenEmpty) {
|
||||
this.killWhenEmpty = killWhenEmpty;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionQueue killAfter(int ticks) {
|
||||
this.killAfterTicks = ticks;
|
||||
return this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
// Schedulers
|
||||
|
||||
@Override
|
||||
public IAction schedule(IAction action) {
|
||||
Action act = (Action) action;
|
||||
@@ -143,6 +172,10 @@ public class ActionQueue implements IActionQueue {
|
||||
return action;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
// Queue Data
|
||||
|
||||
@Override
|
||||
public int getIndex(IAction action) {
|
||||
int i = 0;
|
||||
@@ -202,6 +235,10 @@ public class ActionQueue implements IActionQueue {
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
// Handling
|
||||
|
||||
protected void tick(int ticksExisted) {
|
||||
if (!isWorking)
|
||||
return;
|
||||
@@ -228,6 +265,15 @@ public class ActionQueue implements IActionQueue {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (killWhenEmpty && queue.isEmpty())
|
||||
schedule(killAfterTicks, (act) -> {
|
||||
if (!queue.isEmpty())
|
||||
act.markDone();
|
||||
|
||||
manager.removeQueue(name);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user