-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ReloadScriptsScriptEvent.java
82 lines (70 loc) · 2.33 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
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;
import com.denizenscript.denizencore.utilities.Deprecations;
public class ReloadScriptsScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// reload scripts
// script reload
//
// @Switch had_error true|false
//
// @Regex ^on ((reload scripts)|(script reload))$
//
// @Triggers when Denizen scripts are reloaded.
//
// @Context
// <context.had_error> returns an Element(Boolean) whether there was an error.
//
// -->
public static ReloadScriptsScriptEvent instance;
public boolean hadError = false;
@Override
public void reset() {
hadError = false;
super.reset();
}
@Override
public ScriptEntryData getScriptEntryData() {
return DenizenCore.getImplementation().getEmptyScriptEntryData();
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("had_error")) {
return new ElementTag(hadError);
}
else if (name.equals("haderror")) {
Deprecations.scriptReloadEventNoUnderscore.warn();
return new ElementTag(hadError);
}
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) {
if (path.switches.containsKey("haderror")) {
Deprecations.scriptReloadEventNoUnderscore.warn();
if (!path.checkSwitch("haderror", hadError ? "true" : "false")) {
return false;
}
}
if (path.checkSwitch("had_error", hadError ? "true" : "false")) {
return false;
}
return true;
}
@Override
public String getName() {
return "ReloadScripts";
}
}