-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
BukkitScriptProperties.java
116 lines (96 loc) · 4.47 KB
/
BukkitScriptProperties.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package net.aufdemrand.denizen.objects.properties.bukkit;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.scripts.commands.core.CooldownCommand;
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptHelper;
import net.aufdemrand.denizen.tags.Attribute;
public class BukkitScriptProperties implements Property {
public static boolean describes(dObject script) {
return script instanceof dScript;
}
public static BukkitScriptProperties getFrom(dObject script) {
if (!describes(script)) return null;
else return new BukkitScriptProperties((dScript)script);
}
private BukkitScriptProperties(dScript script) {
this.script = script;
}
dScript script;
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) return "null";
// <--[tag]
// @attribute <s@script.cooled_down[<player>]>
// @returns Element(Boolean)
// @description
// Returns whether the script is currently cooled down for the player. Any global
// cooldown present on the script will also be taken into account. Not specifying a player will result in
// using the attached player available in the script entry. Not having a valid player will result in 'null'.
// -->
if (attribute.startsWith("cooled_down")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
if (player != null && player.isValid())
return new Element(CooldownCommand.checkCooldown(player, script.getContainer().getName()))
.getAttribute(attribute.fulfill(1));
else return "null";
}
// <--[tag]
// @attribute <s@script.requirements[<player>].check[<path>]>
// @returns Element
// @description
// Returns whether the player specified (defaults to current) has the requirement.
// Must be an INTERACT script.
// -->
if (attribute.startsWith("requirements.check")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
if (attribute.hasContext(2))
return new Element(((InteractScriptContainer)script.getContainer()).checkRequirements(player,
((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(),
attribute.getContext(2)))
.getAttribute(attribute.fulfill(2));
}
// <--[tag]
// @attribute <s@script.cooldown[<player>]>
// @returns Duration
// @description
// Returns the time left for the player to cooldown for the script.
// -->
if (attribute.startsWith("cooldown")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
return CooldownCommand.getCooldownDuration(player, script.getName())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <s@script.step[<player>]>
// @returns Element
// @description
// Returns the name of a script step that the player is currently on.
// Must be an INTERACT script.
// -->
if (attribute.startsWith("step")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
if (player != null && player.isValid())
return new Element(InteractScriptHelper.getCurrentStep(player, script.getContainer().getName()))
.getAttribute(attribute.fulfill(1));
}
return null;
}
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "BukkitScriptProperties";
}
@Override
public void adjust(Mechanism mechanism) {
// None
}
}