/
TaskScriptContainer.java
93 lines (83 loc) · 3.21 KB
/
TaskScriptContainer.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 com.denizenscript.denizencore.scripts.containers.core;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.scripts.queues.ContextSource;
import com.denizenscript.denizencore.scripts.queues.ScriptQueue;
import com.denizenscript.denizencore.utilities.ScriptUtilities;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import java.util.function.Consumer;
public class TaskScriptContainer extends ScriptContainer {
// <--[language]
// @name Task Script Containers
// @group Script Container System
// @description
// Task script containers are generic script containers for commands that can be run at
// any time by command.
//
// Generally tasks will be ran by <@link command run> or <@link command inject>.
//
// The only required key on a task script container is the 'script:' key.
//
// <code>
// Task_Script_Name:
//
// type: task
//
// # When intending to run a task script via the run command with the "def:" argument to pass data through,
// # use this "definitions" key to specify the names of the definitions (in the same order as the "def:" argument will use).
// # You can optionally document a definition with [square brackets]
// definitions: name1|name2[description here]|...
//
// script:
//
// - your commands here
//
// </code>
//
// -->
public TaskScriptContainer(YamlConfiguration configurationSection, String scriptContainerName) {
super(configurationSection, scriptContainerName);
}
@Override
public void postCheck() {
// Trigger load + cache
if (shouldEnable() && contains("script")) {
getBaseEntries(DenizenCore.implementation.getEmptyScriptEntryData());
}
}
/**
* Runs the task script.
* @return the new queue.
*/
public ScriptQueue run() {
return run(null, null, null);
}
/**
* Runs the task script.
* @param data the player/npc/other data to attach.
* @return the new queue.
*/
public ScriptQueue run(ScriptEntryData data) {
return run(data, null, null);
}
/**
* Runs the task script.
* @param data the player/npc/other data to attach.
* @param context the provider for <context> data.
* @return the new queue.
*/
public ScriptQueue run(ScriptEntryData data, ContextSource context) {
return run(data, context, null);
}
/**
* Runs the task script.
* @param data the player/npc/other data to attach.
* @param context the provider for <context> data.
* @param configure a function to configure the queue (eg add definitions) before starting.
* @return the new queue.
*/
public ScriptQueue run(ScriptEntryData data, ContextSource context, Consumer<ScriptQueue> configure) {
return ScriptUtilities.createAndStartQueue(this, null, data, context, configure, null, null, null, null);
}
}