/
InstantQueue.java
93 lines (76 loc) · 2.73 KB
/
InstantQueue.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
package net.aufdemrand.denizencore.scripts.queues.core;
import net.aufdemrand.denizencore.objects.Duration;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.scripts.queues.ScriptQueue;
import net.aufdemrand.denizencore.tags.Attribute;
public class InstantQueue extends ScriptQueue {
/**
* Gets an InstantQueue instance.
* <p/>
* If a queue already exists with the given id, it will return that instance,
* which may be currently running, unless the type of Queue is not an InstantQueue.
* If a queue does not exist, a new stopped queue is created instead.
* <p/>
* IDs are case insensitive. If having an easy-to-recall ID is not necessary, just
* pass along null as the id, and it will use ScriptQueue's static method _getNextId()
* which will return a random UUID.
* <p/>
* The default speed node will be automatically read from the configuration,
* and new ScriptQueues may need further information before they
* can start(), including entries, delays, loops, and possibly context.
*
* @param id unique id of the queue
* @return a ScriptQueue
*/
public static InstantQueue getQueue(String id) {
// Get id if not specified.
if (id == null) {
throw new IllegalArgumentException("ID cannot be null!");
}
InstantQueue scriptQueue;
// Does the queue already exist?
if (_queueExists(id)) {
scriptQueue = (InstantQueue) _queues.get(id);
}
// If not, create a new one.
else {
scriptQueue = new InstantQueue(id);
}
return scriptQueue;
}
/////////////////////
// Private instance fields and constructors
/////////////////////
public InstantQueue(String id) {
super(id);
}
public InstantQueue(String id, boolean async) {
super(id, async);
}
@Override
public void onStart() {
while (is_started) {
revolve();
}
}
public void onStop() {
// Nothing to do here!
}
@Override
protected boolean shouldRevolve() {
// Instant queues aren't picky!
return true;
}
@Override
public String getAttribute(Attribute attribute) {
// Meta defined in TimedQueue
if (attribute.startsWith("speed")) {
return new Duration(0).getAttribute(attribute.fulfill(1));
}
// Meta defined in TimedQueue
if (attribute.startsWith("type")) {
return new Element("Instant").getAttribute(attribute.fulfill(1));
}
return super.getAttribute(attribute);
}
}