-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
AsyncCommand.java
47 lines (38 loc) · 1.69 KB
/
AsyncCommand.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
package net.aufdemrand.denizencore.scripts.commands.core;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.BracedCommand;
import net.aufdemrand.denizencore.scripts.commands.Holdable;
import net.aufdemrand.denizencore.scripts.queues.ScriptQueue;
import net.aufdemrand.denizencore.scripts.queues.core.InstantQueue;
import java.util.List;
public class AsyncCommand extends BracedCommand implements Holdable {
@Override
public void onEnable() {
setBraced();
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
scriptEntry.addObject("braces", getBracedCommands(scriptEntry));
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("ASYNC_COMMAND"));
queue.run_async = true;
queue.addEntries(((List<BracedData>) scriptEntry.getObject("braces")).get(0).value);
queue.getAllDefinitions().putAll(scriptEntry.getResidingQueue().getAllDefinitions());
// Setup a callback if the queue is being waited on
if (scriptEntry.shouldWaitFor()) {
// Record the ScriptEntry
final ScriptEntry se = scriptEntry;
queue.callBack(new Runnable() {
@Override
public void run() {
se.setFinished(true);
}
});
}
queue.start();
}
}