mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 08:27:45 +00:00
Added Custom IActionQueues to ActionManager
This commit is contained in:
1 parent
c10b37f01d
commit
fc6c56e40d
1 file changed
+59
@@ -7,6 +7,8 @@ import noppes.npcs.api.handler.data.IActionQueue;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.controllers.data.action.action.ConditionalAction;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -25,6 +27,8 @@ public class ActionManager implements IActionManager {
|
||||
protected final IActionQueue parallelQueue = new ActionQueue(this, "mainParallel").setParallel(true);
|
||||
protected final IActionQueue conditionalQueue = new ActionQueue(this, "mainConditional").setParallel(true);
|
||||
|
||||
protected final Map<String, IActionQueue> otherQueues = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public IActionManager start() {
|
||||
isWorking = true;
|
||||
@@ -105,6 +109,47 @@ public class ActionManager implements IActionManager {
|
||||
return new ConditionalAction(this, name, condition, task, terminateWhen, onTermination);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
// Queues
|
||||
|
||||
public IActionQueue createQueue(String name) {
|
||||
return createQueue(name, false);
|
||||
}
|
||||
|
||||
public IActionQueue createQueue(String name, boolean isParallel) {
|
||||
IActionQueue queue = new ActionQueue(this, name, isParallel);
|
||||
otherQueues.put(name, queue);
|
||||
return queue;
|
||||
}
|
||||
|
||||
public IActionQueue getOrCreateQueue(String name) {
|
||||
return getOrCreateQueue(name, false);
|
||||
}
|
||||
|
||||
public IActionQueue getOrCreateQueue(String name, boolean isParallel) {
|
||||
IActionQueue queue = getQueue(name);
|
||||
|
||||
if (queue == null)
|
||||
queue = createQueue(name, isParallel);
|
||||
return queue;
|
||||
}
|
||||
|
||||
public IActionQueue getQueue(String name) {
|
||||
return otherQueues.get(name);
|
||||
}
|
||||
|
||||
public boolean removeQueue(String name) {
|
||||
IActionQueue queue = otherQueues.get(name);
|
||||
|
||||
if (queue == null)
|
||||
return false;
|
||||
|
||||
otherQueues.remove(name);
|
||||
queue.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
// Sequential
|
||||
@@ -292,6 +337,12 @@ public class ActionManager implements IActionManager {
|
||||
if (act != null)
|
||||
return act;
|
||||
|
||||
for (IActionQueue q : otherQueues.values()) {
|
||||
act = q.get(name);
|
||||
if (act != null)
|
||||
return act;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -309,6 +360,10 @@ public class ActionManager implements IActionManager {
|
||||
if (canceled)
|
||||
return true;
|
||||
|
||||
for (IActionQueue queue : otherQueues.values())
|
||||
if (queue.cancel(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -328,6 +383,9 @@ public class ActionManager implements IActionManager {
|
||||
|
||||
// ─── Conditionals ─────────────────────────────────────────
|
||||
((ActionQueue) conditionalQueue).tick(ticksExisted);
|
||||
|
||||
// ─── Other Queues ─────────────────────────────────────────
|
||||
otherQueues.forEach((name, queue) -> ((ActionQueue) queue).tick(ticksExisted));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,6 +393,7 @@ public class ActionManager implements IActionManager {
|
||||
sequentialQueue.clear();
|
||||
parallelQueue.clear();
|
||||
conditionalQueue.clear();
|
||||
otherQueues.forEach((name, queue) -> queue.clear());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user