-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
ScriptEntry.java
193 lines (148 loc) · 4.29 KB
/
ScriptEntry.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package net.aufdemrand.denizen.scripts;
import net.aufdemrand.denizen.exceptions.ScriptEntryCreationException;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.*;
/**
* ScriptEntry contain information about a single entry from a dScript.
*
* @author Jeremy Schroeder
*
*/
public class ScriptEntry {
// The name of the command that will be executed
private String command;
// The queuetime and allowed-run-time can dictate whether it's okay
// for this command to run in the queue.
private long creationTime;
private long queueTime;
private long runTime;
private long holdTime;
private boolean instant = false;
private boolean waitfor = false;
private boolean done = false;
private dPlayer player = null;
private dNPC npc = null;
private dScript script = null;
private ScriptQueue queue = null;
private List<String> args = null;
private Map<String, Object> objects = new HashMap<String, Object>();
public ScriptEntry(String command, String[] arguments, ScriptContainer script) throws ScriptEntryCreationException {
// Must never be null
if (command == null)
throw new ScriptEntryCreationException("dCommand 'type' cannot be null!");
this.command = command.toUpperCase();
this.script = script.getAsScriptArg();
// Internal, never null. runTime/holdTime can be adjusted mid-execution
this.creationTime = System.currentTimeMillis();
this.queueTime = creationTime;
this.runTime = creationTime;
this.holdTime = creationTime;
// Check if this is an 'instant' or 'waitfor' command.
if (command.startsWith("^")) {
instant = true;
this.command = command.substring(1);
} else if (command.startsWith("~")) {
waitfor = true;
this.command = command.substring(1);
}
this.args = new ArrayList<String>();
if (arguments != null)
this.args = Arrays.asList(arguments);
// Check for replaceable tags.
for (String arg : args) {
if (arg.indexOf("<") >= 0
&& arg.indexOf(">") >= 0) {
has_tags = true;
break;
}
}
}
public boolean has_tags = false;
public ScriptEntry addObject(String key, Object object) {
if (object == null) return this;
objects.put(key.toUpperCase(), object);
return this;
}
public long getRunTime() {
return runTime;
}
public long getHoldTime() {
return holdTime;
}
public List<String> getArguments() {
return args;
}
public String getCommandName() {
return command;
}
public dNPC getNPC() {
return npc;
}
public void setFinished(boolean finished) {
done = finished;
}
public dPlayer getPlayer() {
return player;
}
public Map<String, Object> getObjects() {
return objects;
}
public Object getObject(String key) {
try {
return objects.get(key.toUpperCase());
} catch (Exception e) { return null; }
}
public boolean hasObject(String key) {
return objects.containsKey(key.toUpperCase());
}
public dScript getScript() {
return script;
}
public ScriptQueue getResidingQueue() {
return queue;
}
public Long getQueueTime() {
return queueTime;
}
public boolean isInstant() {
return instant;
}
public boolean shouldWaitFor() {
return waitfor;
}
public boolean isDone() {
return done;
}
public ScriptEntry setRunTime(Long newTime) {
runTime = newTime;
return this;
}
public ScriptEntry setArguments(List<String> arguments) {
args = arguments;
return this;
}
public ScriptEntry setInstant(boolean instant) {
this.instant = instant;
return this;
}
public ScriptEntry setPlayer(dPlayer player) {
this.player = player;
return this;
}
public ScriptEntry setNPC(dNPC dNPC) {
this.npc = dNPC;
return this;
}
public ScriptEntry setScript(String scriptName) {
this.script = dScript.valueOf(scriptName);
return this;
}
public void setSendingQueue(ScriptQueue scriptQueue) {
queue = scriptQueue;
}
}