/
ReloadScriptsScriptEvent.java
95 lines (79 loc) · 2.83 KB
/
ReloadScriptsScriptEvent.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
package net.aufdemrand.denizencore.events.core;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import java.util.HashMap;
public class ReloadScriptsScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// reload scripts
// script reload
//
// @Switch haderror true|false
// @Switch sender player|server
// @Switch all true|false
//
// @Regex ^((reload scripts)|(script reload))$
//
// @Triggers when Denizen scripts are reloaded.
//
// @Context
// <context.sender> returns an Element of the name of the sender who triggered the reload.
// <context.all> returns an Element(Boolean) of whether 'reload -a' was used.
// <context.haderror> returns an Element(Boolean) whether there was an error.
//
// -->
public static ReloadScriptsScriptEvent instance;
public boolean hadError = false;
public boolean all = false;
public String sender = null;
public ScriptEntryData data = null;
@Override
public void reset() {
hadError = false;
sender = null;
all = false;
data = DenizenCore.getImplementation().getEmptyScriptEntryData();
super.reset();
}
@Override
public ScriptEntryData getScriptEntryData() {
return data;
}
@Override
public dObject getContext(String name) {
if (name.equals("haderror")) {
return new Element(hadError);
}
else if (name.equals("all")) {
return new Element(all);
}
else if (name.equals("sender")) {
return new Element(sender);
}
return super.getContext(name);
}
public ReloadScriptsScriptEvent() {
instance = this;
}
@Override
public boolean couldMatch(ScriptContainer script, String event) {
String lower = CoreUtilities.toLowerCase(event);
return lower.startsWith("reload scripts") || lower.startsWith("script reload");
}
@Override
public boolean matches(ScriptContainer script, String event) {
return checkSwitch(event, "haderror", hadError ? "true" : "false")
&& checkSwitch(event, "sender", sender.equalsIgnoreCase("console") ? "server" : "player")
&& checkSwitch(event, "all", all ? "true" : "false");
}
@Override
public String getName() {
return "ReloadScripts";
}
}