/
AssignmentScriptContainer.java
90 lines (82 loc) · 3.94 KB
/
AssignmentScriptContainer.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
package com.denizenscript.denizen.scripts.containers.core;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.utilities.Deprecations;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import java.util.List;
public class AssignmentScriptContainer extends ScriptContainer {
// <--[language]
// @name Assignment Script Containers
// @group Script Container System
// @description
// Assignment script-containers provide functionality to NPCs by 'assignment' of the container. Assignment
// scripts are meant to be used when customizing the normal behavior of NPCs. This can be used on a 'per-NPC' basis,
// but the encouraged approach is to design assignment scripts in a way that they can be used for multiple NPCs,
// perhaps with the use of constants or flags to determine specific information required by the scripts.
//
// Features unique to assignment script-containers include 'actions' and 'interact script' assignment.
// Like any script, the ability to run local utility scripts can be accomplished as well. This allows fully
// interactive NPCs to be built purely with Assignment Scripts, and for advanced situations, world scripts and
// interact scripts can provide more functionality.
// See also <@link language interact script containers>
//
// Basic structure of an assignment script:
// <code>
// Assignment_Script_Name:
//
// type: assignment
//
// # | All assignment scripts MUST have this key!
// actions:
// on <action>:
// - ...
//
// # | Most assignment scripts should exclude this key, but it's available.
// default constants:
// <constant_name>: <value>
// <constant_list>:
// - ...
//
// # | MOST assignment scripts should have this key!
// interact scripts:
// - <interact_script_name>
// </code>
//
// All part of an assignment script are optional. The three features provided can be
// used together, but do not require one another.
//
// Though note that almost always you should include the 'actions:' key, usually with the 'on assignment:' action (if using triggers).
// Refer to <@link action assignment>.
//
// -->
public AssignmentScriptContainer(YamlConfiguration configurationSection, String scriptContainerName) {
super(configurationSection, scriptContainerName);
if (contains("interact scripts", List.class)) {
List<String> names = getStringList("interact scripts");
if (!names.isEmpty()) {
if (names.size() > 1) {
Debug.echoError("Assignment script '" + getName() + "' invalid: assignment scripts should only have ONE interact script in modern Denizen, not multiple!");
}
String name = names.get(0);
int space = name.indexOf(' ');
if (space != -1 && Character.isDigit(name.charAt(0))) {
Deprecations.interactScriptPriority.warn(this);
name = name.substring(space + 1).replace("^", "");
}
interactName = name;
}
}
}
public String interactName;
public InteractScriptContainer interact;
public InteractScriptContainer getInteract() {
if (interact == null && interactName != null) {
interact = ScriptRegistry.getScriptContainerAs(interactName, InteractScriptContainer.class);
if (interact == null) {
Debug.echoError("'" + interactName + "' is not a valid Interact Script. Is there a duplicate script by this name, or is it missing?");
}
}
return interact;
}
}