mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 16:37:45 +00:00
Added print debugging dump methods for most IAction framework components
This commit is contained in:
1 parent
253bfd7e17
commit
5e48063311
4 files changed
+92
-11
No files matched your search
@@ -8,9 +8,7 @@ import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@@ -43,7 +41,7 @@ public class Action implements IAction {
|
||||
}
|
||||
|
||||
public Action(ActionManager manager, Consumer<IAction> task) {
|
||||
this(manager, task.toString(), task);
|
||||
this(manager, Integer.toHexString(task.hashCode()), task);
|
||||
}
|
||||
|
||||
public Action(ActionManager manager, String name, Consumer<IAction> task) {
|
||||
@@ -194,6 +192,22 @@ public class Action implements IAction {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String printData() {
|
||||
if (dataStore.isEmpty()) {
|
||||
return String.format("Action[name=%s] dataStore is empty", name);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("Action[name=%s] dataStore contents:\n", name));
|
||||
|
||||
for (Map.Entry<String, Object> entry : dataStore.entrySet()) {
|
||||
sb.append(String.format(" %s = %s\n", entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasData(String key) {
|
||||
return dataStore.containsKey(key);
|
||||
@@ -272,6 +286,9 @@ public class Action implements IAction {
|
||||
done = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("Action '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, threaded=%s]", name != null ? name : "unnamed", queue != null ? queue.getName() : "null", isScheduled, done, isPaused(), updateEveryXTick, duration, maxDuration, count, maxCount, isThreaded);
|
||||
}
|
||||
///////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
// Thread
|
||||
|
||||
@@ -7,9 +7,7 @@ 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.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -329,6 +327,18 @@ public class ActionManager implements IActionManager {
|
||||
///////////////////////////////////////////////////
|
||||
// Handling
|
||||
|
||||
@Override
|
||||
public IActionQueue[] getAllQueues() {
|
||||
ArrayList<IActionQueue> allQueues = new ArrayList<>();
|
||||
|
||||
allQueues.add(sequentialQueue);
|
||||
allQueues.add(parallelQueue);
|
||||
allQueues.add(conditionalQueue);
|
||||
|
||||
allQueues.addAll(otherQueues.values());
|
||||
|
||||
return allQueues.toArray(new IActionQueue[0]);
|
||||
}
|
||||
@Override
|
||||
public boolean hasAny(String name) {
|
||||
return getAny(name) != null;
|
||||
@@ -423,4 +433,20 @@ public class ActionManager implements IActionManager {
|
||||
public IActionChain parallelChain() {
|
||||
return parallelQueue.chain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String printQueues() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("ActionManager [working=%s]\n", isWorking));
|
||||
|
||||
|
||||
int i = 0;
|
||||
for (IActionQueue action : getAllQueues()) {
|
||||
sb.append(String.format(" [%d] %s\n", i++, action.toString()));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,11 +111,6 @@ public class ActionQueue implements IActionQueue {
|
||||
public IAction schedule(IAction action) {
|
||||
Action act = (Action) action;
|
||||
|
||||
if (act.queue != this)
|
||||
act.setQueue(this);
|
||||
|
||||
act.isScheduled = true;
|
||||
|
||||
if (!isParallel && act.unscheduledList != null) {
|
||||
act.unscheduledList.scheduleAll(this).forEach((act1) -> act1.unscheduledList = null).kill();
|
||||
return action;
|
||||
@@ -123,6 +118,8 @@ public class ActionQueue implements IActionQueue {
|
||||
|
||||
queue.addLast(action);
|
||||
|
||||
act.queue = this;
|
||||
act.isScheduled = true;
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -319,4 +316,25 @@ public class ActionQueue implements IActionQueue {
|
||||
return new ActionChain(manager, this, isParallel ? "parallel#" : "sequential#");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String printQueue() {
|
||||
if (queue.isEmpty()) {
|
||||
return String.format("ActionQueue[name=%s] is empty", name);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("%s\n", this));
|
||||
|
||||
int i = 0;
|
||||
for (IAction action : queue) {
|
||||
sb.append(String.format(" [%d] %s\n", i++, action.toString()));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("ActionQueue '%s' [size=%d, parallel=%s, working=%s, dead=%s, killWhenEmpty=%s, killAfter=%d]", name, queue.size(), isParallel, isWorking, isDead, killWhenEmpty, killWhenEmptyAfter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -159,4 +159,24 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"ConditionalAction '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, checks=%d/%d, taskExecuted=%s, threaded=%s]",
|
||||
name != null ? name : "unnamed",
|
||||
queue != null ? queue.getName() : "null",
|
||||
isScheduled,
|
||||
done,
|
||||
isPaused(),
|
||||
updateEveryXTick,
|
||||
duration,
|
||||
maxDuration,
|
||||
count,
|
||||
maxCount,
|
||||
checkCount,
|
||||
maxChecks,
|
||||
taskExecuted,
|
||||
isThreaded
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user