-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
DetermineCommand.java
80 lines (59 loc) · 2.47 KB
/
DetermineCommand.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
package net.aufdemrand.denizen.scripts.commands.core;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
/**
*
* @author aufdemrand
*
*/
public class DetermineCommand extends AbstractCommand {
private static Map<Long, String> outcomes = new ConcurrentHashMap<Long, String>(8, 0.9f, 1);
public static long uniqueId = 0;
public static long getNewId() {
uniqueId++;
return uniqueId;
}
public static boolean hasOutcome(long id) {
return outcomes.containsKey(id);
}
public static String getOutcome(long id) {
String outcome = outcomes.get(id);
outcomes.remove(id);
return outcome;
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matches("passive, passively"))
scriptEntry.addObject("passively", new Element(true));
else if (!scriptEntry.hasObject("outcome"))
scriptEntry.addObject("outcome", arg.asElement());
else arg.reportUnhandled();
}
// Set defaults
scriptEntry.defaultObject("passively", new Element(false));
scriptEntry.defaultObject("outcome", new Element(false));
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Report!
dB.report(scriptEntry, getName(), scriptEntry.getElement("outcome").debug()
+ scriptEntry.getElement("passively").debug());
// Fetch
String outcome = scriptEntry.getElement("outcome").asString();
Boolean passively = scriptEntry.getElement("passively").asBoolean();
Long uniqueId = (Long) scriptEntry.getObject("reqId");
if (uniqueId == null) return;
outcomes.put(uniqueId, outcome);
if (!passively)
// Stop the queue by clearing the remainder of it.
scriptEntry.getResidingQueue().clear();
}
}