-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ScriptEngine.java
81 lines (74 loc) · 2.94 KB
/
ScriptEngine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.denizenscript.denizencore.scripts.queues;
import com.denizenscript.denizencore.scripts.commands.CommandExecutor;
import com.denizenscript.denizencore.scripts.queues.core.Delayable;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.scripts.ScriptEntry;
public class ScriptEngine {
public final CommandExecutor commandExecutor;
public ScriptEngine() {
commandExecutor = new CommandExecutor();
}
boolean shouldHold(ScriptQueue scriptQueue) {
if (scriptQueue instanceof Delayable && ((Delayable) scriptQueue).isPaused()) {
return true;
}
if (scriptQueue.getLastEntryExecuted() == null || !scriptQueue.getLastEntryExecuted().shouldWaitFor()) {
return false;
}
if (!(scriptQueue instanceof Delayable)) {
Debug.echoDebug(scriptQueue.getLastEntryExecuted(), "Forcing queue " + scriptQueue.id + " into a timed queue...");
scriptQueue.forceToTimed(null);
}
return true;
}
public void revolveOnceForce(ScriptQueue scriptQueue) {
ScriptEntry scriptEntry = scriptQueue.getNext();
if (scriptEntry == null) {
return;
}
scriptEntry.setSendingQueue(scriptQueue);
scriptQueue.setLastEntryExecuted(scriptEntry);
try {
commandExecutor.execute(scriptEntry);
}
catch (Throwable e) {
Debug.echoError(scriptEntry.getResidingQueue(), "An exception has been called with this command (while revolving the queue forcefully)!");
Debug.echoError(scriptEntry.getResidingQueue(), e);
}
}
public void revolve(ScriptQueue scriptQueue) {
if (shouldHold(scriptQueue)) {
return;
}
ScriptEntry scriptEntry = scriptQueue.getNext();
while (scriptEntry != null) {
scriptEntry.setSendingQueue(scriptQueue);
scriptQueue.setLastEntryExecuted(scriptEntry);
commandExecutor.execute(scriptEntry);
if (scriptQueue instanceof Delayable) {
Delayable delayedQueue = (Delayable) scriptQueue;
if (delayedQueue.isDelayed() || delayedQueue.isPaused()) {
break;
}
if (delayedQueue.isInstantSpeed() || scriptEntry.isInstant()) {
if (shouldHold(scriptQueue)) {
return;
}
scriptEntry = scriptQueue.getNext();
}
else {
break;
}
}
else if (scriptEntry.isInstant()) {
if (shouldHold(scriptQueue)) {
return;
}
scriptEntry = scriptQueue.getNext();
}
else {
break;
}
}
}
}