/
ScriptEngine.java
101 lines (80 loc) · 3.34 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package net.aufdemrand.denizen.scripts.queues;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.CommandExecuter;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.scripts.queues.core.Delayable;
import net.aufdemrand.denizen.scripts.requirements.RequirementChecker;
import net.aufdemrand.denizen.utilities.debugging.dB;
public class ScriptEngine {
final private Denizen denizen;
final private RequirementChecker requirementChecker;
final private CommandExecuter commandExecuter;
public ScriptEngine(Denizen denizenPlugin) {
denizen = denizenPlugin;
// Create Denizen CommandExecuter and RequirementChecker
commandExecuter = new CommandExecuter(denizen);
requirementChecker = new RequirementChecker(denizen);
}
public void revolve(ScriptQueue scriptQueue) {
// Check last ScriptEntry to see if it should be waited for
if (scriptQueue.getLastEntryExecuted() != null
&& scriptQueue.getLastEntryExecuted().shouldWaitFor())
if (!scriptQueue.getLastEntryExecuted().isDone()) return;
// Okay to run next scriptEntry
ScriptEntry scriptEntry = scriptQueue.getNext();
while (scriptEntry != null) {
// Mark script entry with Queue that is sending it to the executer
scriptEntry.setSendingQueue(scriptQueue);
// Execute the scriptEntry
try { getScriptExecuter().execute(scriptEntry); }
catch (Throwable e) {
dB.echoError("Woah! An exception has been called with this command!");
if (!dB.showStackTraces)
dB.echoError("Enable '/denizen stacktrace' for the nitty-gritty.");
else e.printStackTrace();
}
// Set as last entry executed
scriptQueue.setLastEntryExecuted(scriptEntry);
//
// Determine what should happen after execution:
//
// Check if the scriptQueue is delayed
if (scriptQueue instanceof Delayable) {
// dB.log("Is delayed? " + ((Delayable) scriptQueue).isDelayed());
if (((Delayable) scriptQueue).isDelayed()) break;
}
// If the entry is instant, and not injected, get the next Entry
if (scriptEntry.isInstant()) { // ---> What does this do? && !scriptQueue.hasInjectedItems) {
// Remove from execution list
scriptEntry = scriptQueue.getNext();
}
// ---> What does this do?
// else if (scriptQueue.hasInjectedItems) {
// scriptQueue.hasInjectedItems = false;
// break;
// }
// If entry isn't instant, end the revolution and wait for another
else
break;
}
}
/**
* Gets the currently loaded instance of the RequirementChecker
*
* @return ScriptHelper
*
*/
public RequirementChecker getRequirementChecker() {
return requirementChecker;
}
/**
* Gets the currently loaded instance of the Command Executer
*
* @return CommandExecuter
*
*/
public CommandExecuter getScriptExecuter() {
return commandExecuter;
}
}