-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
ScriptEntry.java
229 lines (178 loc) · 5.59 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package net.aufdemrand.denizen.scripts;
import net.aufdemrand.denizen.exceptions.ScriptEntryCreationException;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
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;
private long creationTime;
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();
if (script != null)
this.script = script.getAsScriptArg();
// Internal, never null.
this.creationTime = System.currentTimeMillis();
// 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.contains("<") && arg.contains(">")) {
has_tags = true;
break;
}
}
}
public boolean has_tags = false;
public ScriptEntry addObject(String key, Object object) {
if (object == null) return this;
if (object instanceof dObject)
((dObject) object).setPrefix(key);
objects.put(key.toUpperCase(), object);
return this;
}
/**
* If the scriptEntry lacks the object corresponding to the
* key, set it to the first non-null argument
*
* @param key The key of the object to check
* @return The scriptEntry
*
*/
public ScriptEntry defaultObject(String key, Object... objects) {
if (this.hasObject(key) == false) {
for (Object obj : objects) {
if (obj != null) {
this.addObject(key, obj);
break;
}
}
}
return this;
}
public List<String> getArguments() {
return args;
}
public String getCommandName() {
return command;
}
public dNPC getNPC() {
return npc;
}
public boolean hasNPC() {
if (npc != null) return true;
return false;
}
public void setFinished(boolean finished) {
done = finished;
}
public dPlayer getPlayer() {
return player;
}
public boolean hasPlayer() {
if (player != null) return true;
return false;
}
public Map<String, Object> getObjects() {
return objects;
}
public Object getObject(String key) {
try {
return objects.get(key.toUpperCase());
} catch (Exception e) { return null; }
}
public dObject getdObject(String key) {
try {
return (dObject) objects.get(key.toUpperCase());
} catch (Exception e) { return null; }
}
public Element getElement(String key) {
try {
return (Element) objects.get(key.toUpperCase());
} catch (Exception e) { return null; }
}
public boolean hasObject(String key) {
if (objects.containsKey(key.toUpperCase())
&& objects.get(key.toUpperCase()) != null)
return true;
else return false;
}
public dScript getScript() {
return script;
}
public ScriptQueue getResidingQueue() {
return queue;
}
public boolean isInstant() {
return instant;
}
public boolean shouldWaitFor() {
return waitfor;
}
public boolean isDone() {
return done;
}
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;
}
// Keep track of objects which were added by mass
// so that IF can inject them into new entries.
// This is ugly, but it will keep from breaking
// previous versions of Denizen.
public List<String> tracked_objects = new ArrayList<String>();
public ScriptEntry trackObject(String key) {
tracked_objects.add(key.toUpperCase());
return this;
}
public void setCommandName(String commandName) {
this.command = commandName;
}
}