/
ReloadScriptsScriptEvent.java
80 lines (66 loc) · 2.18 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
package com.denizenscript.denizencore.events.core;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.DenizenCore;
public class ReloadScriptsScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// reload scripts
// script reload
//
// @Switch haderror true|false
// @Switch all true|false
//
// @Regex ^on ((reload scripts)|(script reload))$
//
// @Triggers when Denizen scripts are reloaded.
//
// @Context
// <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 ScriptEntryData data = null;
@Override
public void reset() {
hadError = false;
all = false;
data = DenizenCore.getImplementation().getEmptyScriptEntryData();
super.reset();
}
@Override
public ScriptEntryData getScriptEntryData() {
return data;
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("haderror")) {
return new ElementTag(hadError);
}
else if (name.equals("all")) {
return new ElementTag(all);
}
return super.getContext(name);
}
public ReloadScriptsScriptEvent() {
instance = this;
}
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("reload scripts") || path.eventLower.startsWith("script reload");
}
@Override
public boolean matches(ScriptPath path) {
return path.checkSwitch("haderror", hadError ? "true" : "false")
&& path.checkSwitch("all", all ? "true" : "false");
}
@Override
public String getName() {
return "ReloadScripts";
}
}