mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
More IActionManager and IAction QoL !!!
This commit is contained in:
1 parent
8ee35e8088
commit
fa9e5cdfe5
3 files changed
+61
-5
No files matched your search
+1
-1
Submodule src/api updated: 8ad0c21ef4...50f30f3678.
@@ -129,6 +129,10 @@ public class Action implements IAction {
|
||||
return done;
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getData(String key) {
|
||||
return dataStore.get(key);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ScriptedActionManager implements IActionManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAction scheduleAction(String name, Consumer<IAction> task) {
|
||||
public IAction scheduleAction(String name, Consumer<IAction> task) {
|
||||
return scheduleAction(create(name, task));
|
||||
}
|
||||
@Override
|
||||
@@ -175,6 +175,26 @@ public class ScriptedActionManager implements IActionManager {
|
||||
return actionQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAction(String name) {
|
||||
for (IAction act : actionQueue)
|
||||
if (act.getName().equals(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasAny(String name) {
|
||||
if (hasAction(name))
|
||||
return true;
|
||||
else if (hasParallel(name))
|
||||
return true;
|
||||
else if (hasConditional(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
actionQueue.clear();
|
||||
@@ -242,6 +262,15 @@ public class ScriptedActionManager implements IActionManager {
|
||||
return new ArrayList<>(conditionalActions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasConditional(String name) {
|
||||
for (IAction act : conditionalActions)
|
||||
if (act.getName().equals(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAction scheduleParallelAction(IAction action) {
|
||||
parallelActions.add(action);
|
||||
@@ -262,7 +291,10 @@ public class ScriptedActionManager implements IActionManager {
|
||||
if (current instanceof Action) {
|
||||
Action cab = (Action) current;
|
||||
cab.tick(ticksExisted);
|
||||
if (cab.isDone()) actionQueue.pollFirst();
|
||||
if (cab.isDone()) {
|
||||
cab.kill();
|
||||
actionQueue.pollFirst();
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Parallel (all) ───────────────────────────────────────
|
||||
@@ -270,7 +302,10 @@ public class ScriptedActionManager implements IActionManager {
|
||||
while (pit.hasNext()) {
|
||||
Action a = (Action) pit.next();
|
||||
a.tick(ticksExisted);
|
||||
if (a.isDone()) pit.remove();
|
||||
if (a.isDone()) {
|
||||
a.kill();
|
||||
pit.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Conditionals ─────────────────────────────────────────
|
||||
@@ -278,7 +313,10 @@ public class ScriptedActionManager implements IActionManager {
|
||||
while (cit.hasNext()) {
|
||||
ConditionalAction con = (ConditionalAction) cit.next();
|
||||
con.tick(ticksExisted);
|
||||
if (con.isDone()) cit.remove();
|
||||
if (con.isDone()) {
|
||||
con.kill();
|
||||
cit.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,4 +329,18 @@ public class ScriptedActionManager implements IActionManager {
|
||||
public IActionChain parallelChain() {
|
||||
return new ParallelActionChain(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<IAction> getParallelActions() {
|
||||
return parallelActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParallel(String name) {
|
||||
for (IAction act : parallelActions)
|
||||
if (act.getName().equals(name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user